From 8de7bc714859cd3c2d66c7e724a2b13cb753fa4a Mon Sep 17 00:00:00 2001 From: cawand <39776867+cawand@users.noreply.github.com> Date: Wed, 1 Aug 2018 14:50:53 -0700 Subject: [PATCH] Show line implementation (#285) --- consutil/lib.py | 16 ++++++++-------- consutil/main.py | 23 ++++++++++++++++++++--- show/main.py | 5 ++--- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/consutil/lib.py b/consutil/lib.py index 0617acf5eb..da438c5f92 100644 --- a/consutil/lib.py +++ b/consutil/lib.py @@ -29,14 +29,6 @@ def run_command(cmd): sys.exit(ERR_CMD) return output -# exits if inputted line number does not correspond to a device -# input: linenum -def checkDevice(linenum): - devices = getAllDevices() - if DEVICE_PREFIX + str(linenum) not in devices: - click.echo("Line number {} does not exist".format(linenum)) - sys.exit(ERR_DEV) - # returns a sorted list of all devices (whose name matches DEVICE_PREFIX) def getAllDevices(): cmd = "ls " + DEVICE_PREFIX + "*" @@ -48,6 +40,14 @@ def getAllDevices(): return devices +# exits if inputted line number does not correspond to a device +# input: linenum +def checkDevice(linenum): + devices = getAllDevices() + if DEVICE_PREFIX + str(linenum) not in devices: + click.echo("Line number {} does not exist".format(linenum)) + sys.exit(ERR_DEV) + # returns a dictionary of busy devices and their info # maps line number to (pid, process start time) def getBusyDevices(): diff --git a/consutil/main.py b/consutil/main.py index 8fc1970aad..036cf329ad 100644 --- a/consutil/main.py +++ b/consutil/main.py @@ -9,6 +9,7 @@ import click import re import subprocess + from tabulate import tabulate except ImportError as e: raise ImportError("%s - required module not found" % str(e)) @@ -22,9 +23,25 @@ def consutil(): # 'show' subcommand @consutil.command() -def line(): - """Show all /dev/ttyUSB lines""" - click.echo("show line") +def show(): + """Show all /dev/ttyUSB lines and their info""" + devices = getAllDevices() + busyDevices = getBusyDevices() + + header = ["Line", "Baud", "PID", "Start Time"] + body = [] + for device in devices: + lineNum = device[11:] + busy = " " + pid = "" + date = "" + if lineNum in busyDevices: + pid, date = busyDevices[lineNum] + busy = "*" + baud = getBaud(lineNum) + body.append([busy+lineNum, baud, pid, date]) + + click.echo(tabulate(body, header, stralign="right")) # 'clear' subcommand @consutil.command() diff --git a/show/main.py b/show/main.py index 14d2a17f00..1899c83d7b 100755 --- a/show/main.py +++ b/show/main.py @@ -1135,9 +1135,8 @@ def reboot_cause(): @cli.command('line') def line(): """Show all /dev/ttyUSB lines and their info""" - # TODO: Stub - return - + cmd = "consutil show" + run_command(cmd, display_cmd=verbose) if __name__ == '__main__': cli()