File tree 3 files changed +30
-14
lines changed
3 files changed +30
-14
lines changed Original file line number Diff line number Diff line change @@ -29,14 +29,6 @@ def run_command(cmd):
29
29
sys .exit (ERR_CMD )
30
30
return output
31
31
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
-
40
32
# returns a sorted list of all devices (whose name matches DEVICE_PREFIX)
41
33
def getAllDevices ():
42
34
cmd = "ls " + DEVICE_PREFIX + "*"
@@ -48,6 +40,14 @@ def getAllDevices():
48
40
49
41
return devices
50
42
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
+
51
51
# returns a dictionary of busy devices and their info
52
52
# maps line number to (pid, process start time)
53
53
def getBusyDevices ():
Original file line number Diff line number Diff line change 9
9
import click
10
10
import re
11
11
import subprocess
12
+ from tabulate import tabulate
12
13
except ImportError as e :
13
14
raise ImportError ("%s - required module not found" % str (e ))
14
15
@@ -22,9 +23,25 @@ def consutil():
22
23
23
24
# 'show' subcommand
24
25
@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" ))
28
45
29
46
# 'clear' subcommand
30
47
@consutil .command ()
Original file line number Diff line number Diff line change @@ -1135,9 +1135,8 @@ def reboot_cause():
1135
1135
@cli .command ('line' )
1136
1136
def line ():
1137
1137
"""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 )
1141
1140
1142
1141
if __name__ == '__main__' :
1143
1142
cli ()
You can’t perform that action at this time.
0 commit comments