Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[consutil] Add brief option to show line command #1176

Merged
merged 1 commit into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions consutil/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def run_command(cmd, abort=True):
return output if abort else (output, error)

# returns a list of all lines
def getAllLines():
def getAllLines(brief=False):
config_db = ConfigDBConnector()
config_db.connect()

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

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

# returns a dictionary of busy lines and their info
Expand Down
9 changes: 5 additions & 4 deletions consutil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ def consutil():

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

# sort lines for table rendering
Expand Down Expand Up @@ -59,7 +60,7 @@ def clear(target):
"""Clear preexisting connection to line"""
targetLine = getLine(target)
if not targetLine:
click.echo("Target [{}] does not exist".format(linenum))
click.echo("Target [{}] does not exist".format(target))
sys.exit(ERR_DEV)
lineNumber = targetLine[LINE_KEY]

Expand Down
7 changes: 4 additions & 3 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1827,10 +1827,11 @@ def reboot_cause():
# 'line' command ("show line")
#
@cli.command('line')
@click.option('--brief', '-b', metavar='<brief_mode>', required=False, is_flag=True)
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def line(verbose):
"""Show all /dev/ttyUSB lines and their info"""
cmd = "consutil show"
def line(brief, verbose):
"""Show all console lines and their info include available ttyUSB devices unless specified brief mode"""
cmd = "consutil show" + (" -b" if brief else "")
run_command(cmd, display_cmd=verbose)
return

Expand Down