Skip to content

Commit 510d0ad

Browse files
authored
[consutil] Add brief option to show line command (#1176)
Signed-off-by: Jing Kan [email protected]
1 parent c395e14 commit 510d0ad

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

consutil/lib.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def run_command(cmd, abort=True):
6161
return output if abort else (output, error)
6262

6363
# returns a list of all lines
64-
def getAllLines():
64+
def getAllLines(brief=False):
6565
config_db = ConfigDBConnector()
6666
config_db.connect()
6767

@@ -73,16 +73,17 @@ def getAllLines():
7373
line[LINE_KEY] = k
7474
lines.append(line)
7575

76-
# Querying device directory to get all available console ports
77-
cmd = "ls " + DEVICE_PREFIX + "*"
78-
output, _ = run_command(cmd, abort=False)
79-
availableTtys = output.split('\n')
80-
availableTtys = list(filter(lambda dev: re.match(DEVICE_PREFIX + r"\d+", dev) != None, availableTtys))
81-
for tty in availableTtys:
82-
k = tty[len(DEVICE_PREFIX):]
83-
if k not in keys:
84-
line = { LINE_KEY: k }
85-
lines.append(line)
76+
# Querying device directory to get all available console ports
77+
if not brief:
78+
cmd = "ls " + DEVICE_PREFIX + "*"
79+
output, _ = run_command(cmd, abort=False)
80+
availableTtys = output.split('\n')
81+
availableTtys = list(filter(lambda dev: re.match(DEVICE_PREFIX + r"\d+", dev) != None, availableTtys))
82+
for tty in availableTtys:
83+
k = tty[len(DEVICE_PREFIX):]
84+
if k not in keys:
85+
line = { LINE_KEY: k }
86+
lines.append(line)
8687
return lines
8788

8889
# returns a dictionary of busy lines and their info

consutil/main.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ def consutil():
2525

2626
# 'show' subcommand
2727
@consutil.command()
28-
def show():
29-
"""Show all lines and their info"""
30-
lines = getAllLines()
28+
@click.option('--brief', '-b', metavar='<brief_mode>', required=False, is_flag=True)
29+
def show(brief):
30+
"""Show all lines and their info include available ttyUSB devices unless specified brief mode"""
31+
lines = getAllLines(brief)
3132
busyLines = getBusyLines()
3233

3334
# sort lines for table rendering
@@ -59,7 +60,7 @@ def clear(target):
5960
"""Clear preexisting connection to line"""
6061
targetLine = getLine(target)
6162
if not targetLine:
62-
click.echo("Target [{}] does not exist".format(linenum))
63+
click.echo("Target [{}] does not exist".format(target))
6364
sys.exit(ERR_DEV)
6465
lineNumber = targetLine[LINE_KEY]
6566

show/main.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1827,10 +1827,11 @@ def reboot_cause():
18271827
# 'line' command ("show line")
18281828
#
18291829
@cli.command('line')
1830+
@click.option('--brief', '-b', metavar='<brief_mode>', required=False, is_flag=True)
18301831
@click.option('--verbose', is_flag=True, help="Enable verbose output")
1831-
def line(verbose):
1832-
"""Show all /dev/ttyUSB lines and their info"""
1833-
cmd = "consutil show"
1832+
def line(brief, verbose):
1833+
"""Show all console lines and their info include available ttyUSB devices unless specified brief mode"""
1834+
cmd = "consutil show" + (" -b" if brief else "")
18341835
run_command(cmd, display_cmd=verbose)
18351836
return
18361837

0 commit comments

Comments
 (0)