Skip to content

Commit 8de7bc7

Browse files
cawandjleveque
authored andcommitted
Show line implementation (sonic-net#285)
1 parent 08358a1 commit 8de7bc7

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

consutil/lib.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ def run_command(cmd):
2929
sys.exit(ERR_CMD)
3030
return output
3131

32-
# exits if inputted line number does not correspond to a device
33-
# input: linenum
34-
def checkDevice(linenum):
35-
devices = getAllDevices()
36-
if DEVICE_PREFIX + str(linenum) not in devices:
37-
click.echo("Line number {} does not exist".format(linenum))
38-
sys.exit(ERR_DEV)
39-
4032
# returns a sorted list of all devices (whose name matches DEVICE_PREFIX)
4133
def getAllDevices():
4234
cmd = "ls " + DEVICE_PREFIX + "*"
@@ -48,6 +40,14 @@ def getAllDevices():
4840

4941
return devices
5042

43+
# exits if inputted line number does not correspond to a device
44+
# input: linenum
45+
def checkDevice(linenum):
46+
devices = getAllDevices()
47+
if DEVICE_PREFIX + str(linenum) not in devices:
48+
click.echo("Line number {} does not exist".format(linenum))
49+
sys.exit(ERR_DEV)
50+
5151
# returns a dictionary of busy devices and their info
5252
# maps line number to (pid, process start time)
5353
def getBusyDevices():

consutil/main.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import click
1010
import re
1111
import subprocess
12+
from tabulate import tabulate
1213
except ImportError as e:
1314
raise ImportError("%s - required module not found" % str(e))
1415

@@ -22,9 +23,25 @@ def consutil():
2223

2324
# 'show' subcommand
2425
@consutil.command()
25-
def line():
26-
"""Show all /dev/ttyUSB lines"""
27-
click.echo("show line")
26+
def show():
27+
"""Show all /dev/ttyUSB lines and their info"""
28+
devices = getAllDevices()
29+
busyDevices = getBusyDevices()
30+
31+
header = ["Line", "Baud", "PID", "Start Time"]
32+
body = []
33+
for device in devices:
34+
lineNum = device[11:]
35+
busy = " "
36+
pid = ""
37+
date = ""
38+
if lineNum in busyDevices:
39+
pid, date = busyDevices[lineNum]
40+
busy = "*"
41+
baud = getBaud(lineNum)
42+
body.append([busy+lineNum, baud, pid, date])
43+
44+
click.echo(tabulate(body, header, stralign="right"))
2845

2946
# 'clear' subcommand
3047
@consutil.command()

show/main.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1135,9 +1135,8 @@ def reboot_cause():
11351135
@cli.command('line')
11361136
def line():
11371137
"""Show all /dev/ttyUSB lines and their info"""
1138-
# TODO: Stub
1139-
return
1140-
1138+
cmd = "consutil show"
1139+
run_command(cmd, display_cmd=verbose)
11411140

11421141
if __name__ == '__main__':
11431142
cli()

0 commit comments

Comments
 (0)