@@ -117,25 +117,37 @@ def list_mbeds(self):
117
117
118
118
# Private methods
119
119
120
- def get_dev_by_id (self , subdir ):
121
- """! Lists disk devices by id
122
- @return List of strings from 'ls' command executed in shell
120
+ def get_dev_by_id_cmd (self , subdir ):
121
+ """! Calls command line 'ls' to get devices by their ids
123
122
@details Uses Linux shell command: 'ls -oA /dev/disk/by-id/'
123
+ @return tuple(stdout lines, retcode)
124
124
"""
125
- result = []
126
125
cmd = 'ls -oA /dev/' + subdir + '/by-id/'
127
126
if self .DEBUG_FLAG :
128
- self .debug (self .get_dev_by_id .__name__ , cmd )
129
-
127
+ self .debug (self .get_dev_by_id_cmd .__name__ , cmd )
130
128
p = subprocess .Popen (cmd , shell = True , stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
131
- for line in p .stdout .readlines ():
132
- line = line .rstrip ()
133
- result .append (line )
134
- if self .DEBUG_FLAG :
135
- self .debug (self .get_dev_by_id .__name__ , line )
136
- retval = p .wait ()
129
+ return (p .stdout .readlines (), p .wait ())
130
+
131
+ def get_dev_by_id_process (self , lines , retval ):
132
+ """! Remove unnecessary lines from command line output
133
+ """
134
+ result = []
135
+ if not retval :
136
+ for line in lines :
137
+ line = line .rstrip ()
138
+ if not line .lower ().startswith ('total ' ): # total 0
139
+ result .append (line )
140
+ if self .DEBUG_FLAG :
141
+ self .debug (self .get_dev_by_id_process .__name__ , line )
137
142
return result
138
143
144
+ def get_dev_by_id (self , subdir ):
145
+ """! Lists disk devices by id
146
+ @return List of strings from 'ls' command executed in shell
147
+ """
148
+ lines , retval = self .get_dev_by_id_cmd (subdir )
149
+ return self .get_dev_by_id_process (lines , retval )
150
+
139
151
def get_mounts (self ):
140
152
"""! Lists mounted devices with vfat file system (potential mbeds)
141
153
@result Returns list of all mounted vfat devices
@@ -147,12 +159,13 @@ def get_mounts(self):
147
159
self .debug (self .get_mounts .__name__ , cmd )
148
160
149
161
p = subprocess .Popen (cmd , shell = True , stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
150
- for line in p .stdout .readlines ():
151
- line = line .rstrip ()
152
- result .append (line )
153
- if self .DEBUG_FLAG :
154
- self .debug (self .get_mounts .__name__ , line )
155
162
retval = p .wait ()
163
+ if not retval :
164
+ for line in p .stdout .readlines ():
165
+ line = line .rstrip ()
166
+ result .append (line )
167
+ if self .DEBUG_FLAG :
168
+ self .debug (self .get_mounts .__name__ , line )
156
169
return result
157
170
158
171
def get_disk_hex_ids (self , disk_list ):
0 commit comments