11
11
import swsssdk
12
12
import subprocess
13
13
import sys
14
- except ImportError as e :
14
+ except ImportError as e :
15
15
raise ImportError ("%s - required module not found" % str (e ))
16
16
17
17
DEVICE_PREFIX = "/dev/ttyUSB"
@@ -50,11 +50,11 @@ def run_command(cmd):
50
50
def getAllDevices ():
51
51
cmd = "ls " + DEVICE_PREFIX + "*"
52
52
output = run_command (cmd )
53
-
53
+
54
54
devices = output .split ('\n ' )
55
55
devices = list (filter (lambda dev : re .match (DEVICE_PREFIX + r"\d+" , dev ) != None , devices ))
56
56
devices .sort (key = lambda dev : int (dev [len (DEVICE_PREFIX ):]))
57
-
57
+
58
58
return devices
59
59
60
60
# exits if inputted line number does not correspond to a device
@@ -71,17 +71,17 @@ def getBusyDevices():
71
71
cmd = 'ps -eo pid,lstart,cmd | grep -E "(mini|pico)com"'
72
72
output = run_command (cmd )
73
73
processes = output .split ('\n ' )
74
-
74
+
75
75
# matches any number of spaces then any number of digits
76
76
regexPid = r" *(\d+)"
77
77
# matches anything of form: Xxx Xxx ( 0)or(00) 00:00:00 0000
78
78
regexDate = r"([A-Z][a-z]{2} [A-Z][a-z]{2} [\d ]\d \d{2}:\d{2}:\d{2} \d{4})"
79
- # matches any non-whitespace characters ending in minicom or picocom,
80
- # then a space and any chars followed by /dev/ttyUSB<any digits>,
79
+ # matches any non-whitespace characters ending in minicom or picocom,
80
+ # then a space and any chars followed by /dev/ttyUSB<any digits>,
81
81
# then a space and any chars
82
82
regexCmd = r"\S*(?:(?:mini)|(?:pico))com .*" + DEVICE_PREFIX + r"(\d+)(?: .*)?"
83
83
regexProcess = re .compile (r"^" + regexPid + r" " + regexDate + r" " + regexCmd + r"$" )
84
-
84
+
85
85
busyDevices = {}
86
86
for process in processes :
87
87
match = regexProcess .match (process )
@@ -98,8 +98,8 @@ def getBusyDevices():
98
98
def getConnectionInfo (linenum ):
99
99
config_db = ConfigDBConnector ()
100
100
config_db .connect ()
101
- entry = config_db .get_entry (CONSOLE_PORT_TABLE , str (linenum ))
102
-
101
+ entry = config_db .get_entry (CONSOLE_PORT_TABLE , str (linenum ))
102
+
103
103
conf_baud = "-" if BAUD_KEY not in entry else entry [BAUD_KEY ]
104
104
act_baud = DEFAULT_BAUD if conf_baud == "-" else conf_baud
105
105
flow_control = False
@@ -118,7 +118,7 @@ def getLineNumber(target, deviceBool):
118
118
119
119
config_db = ConfigDBConnector ()
120
120
config_db .connect ()
121
-
121
+
122
122
devices = getAllDevices ()
123
123
linenums = list (map (lambda dev : dev [len (DEVICE_PREFIX ):], devices ))
124
124
0 commit comments