Skip to content

Commit

Permalink
Show line implementation (sonic-net#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
cawand authored and jleveque committed Aug 1, 2018
1 parent 08358a1 commit 8de7bc7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
16 changes: 8 additions & 8 deletions consutil/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "*"
Expand All @@ -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():
Expand Down
23 changes: 20 additions & 3 deletions consutil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 8de7bc7

Please sign in to comment.