@@ -98,19 +98,19 @@ def find_candidates(self):
98
98
99
99
@deprecated ("Functionality has been moved into 'list_mbeds'. "
100
100
"Please use list_mbeds with 'unique_names=True' and "
101
- "'read_details_txt =True'" )
101
+ "'include_extra_info =True'" )
102
102
def list_mbeds_ext (self ):
103
103
"""! Function adds extra information for each mbed device
104
104
@return Returns list of mbed devices plus extended data like 'platform_name_unique'
105
105
@details Get information about mbeds with extended parameters/info included
106
106
"""
107
107
108
- return self .list_mbeds (unique_names = True , read_details_txt = True )
108
+ return self .list_mbeds (unique_names = True , include_extra_info = True )
109
109
110
110
def list_mbeds (
111
111
self , fs_interaction = FSInteraction .BeforeFilter ,
112
112
filter_function = None , unique_names = False ,
113
- read_details_txt = False ):
113
+ include_extra_info = False ):
114
114
""" List details of connected devices
115
115
@return Returns list of structures with detailed info about each mbed
116
116
@param fs_interaction A member of the FSInteraction class that picks the
@@ -120,8 +120,8 @@ def list_mbeds(
120
120
Ex. mbeds = list_mbeds(filter_function=lambda m: m['platform_name'] == 'K64F')
121
121
@param unique_names A boolean controlling the presence of the
122
122
'platform_unique_name' member of the output dict
123
- @param read_details_text A boolean controlling the presense of the
124
- output dict attributes read from "DETAILS.TXT"
123
+ @param include_extra_info A boolean controlling the presense of the
124
+ output dict attributes read from other files present on the 'mount_point'
125
125
@details Function returns list of dictionaries with mbed attributes 'mount_point', TargetID name etc.
126
126
Function returns mbed list with platform names if possible
127
127
"""
@@ -143,14 +143,15 @@ def list_mbeds(
143
143
FSInteraction .BeforeFilter : self ._fs_before_id_check ,
144
144
FSInteraction .AfterFilter : self ._fs_after_id_check ,
145
145
FSInteraction .Never : self ._fs_never
146
- }[fs_interaction ](device , filter_function , read_details_txt )
146
+ }[fs_interaction ](device , filter_function , include_extra_info )
147
147
if maybe_device :
148
148
if unique_names :
149
149
name = device ['platform_name' ]
150
150
platform_count .setdefault (name , - 1 )
151
151
platform_count [name ] += 1
152
152
device ['platform_name_unique' ] = (
153
153
"%s[%d]" % (name , platform_count [name ]))
154
+
154
155
try :
155
156
device .update (self .retarget_data [device ['target_id' ]])
156
157
logger .debug ("retargeting %s with %r" ,
@@ -162,7 +163,7 @@ def list_mbeds(
162
163
163
164
return result
164
165
165
- def _fs_never (self , device , filter_function , read_details_txt ):
166
+ def _fs_never (self , device , filter_function , include_extra_info ):
166
167
"""Filter device without touching the file system of the device"""
167
168
device ['target_id' ] = device ['target_id_usb_id' ]
168
169
device ['target_id_mbed_htm' ] = None
@@ -172,41 +173,71 @@ def _fs_never(self, device, filter_function, read_details_txt):
172
173
else :
173
174
return None
174
175
175
- def _fs_before_id_check (self , device , filter_function , read_details_txt ):
176
+ def _fs_before_id_check (self , device , filter_function , include_extra_info ):
176
177
"""Filter device after touching the file system of the device.
177
178
Said another way: Touch the file system before filtering
178
179
"""
179
- self ._update_device_from_htm (device )
180
-
181
- if read_details_txt :
182
- details_txt = self ._details_txt (device ['mount_point' ]) or {}
183
- device .update ({"daplink_%s" % f .lower ().replace (' ' , '_' ): v
184
- for f , v in details_txt .items ()})
185
-
180
+ self ._update_device_from_fs (device , include_extra_info )
186
181
if not filter_function or filter_function (device ):
187
182
return device
188
183
else :
189
184
return None
190
185
191
- def _fs_after_id_check (self , device , filter_function , read_details_txt ):
186
+ def _fs_after_id_check (self , device , filter_function , include_extra_info ):
187
+
192
188
"""Filter device before touching the file system of the device.
193
189
Said another way: Touch the file system after filtering
194
190
"""
195
191
device ['target_id' ] = device ['target_id_usb_id' ]
196
192
device ['target_id_mbed_htm' ] = None
197
193
device ['platform_name' ] = self .plat_db .get (device ['target_id' ][0 :4 ])
198
194
if not filter_function or filter_function (device ):
199
- self ._update_device_from_htm (device )
200
-
201
- if read_details_txt :
202
- details_txt = self ._details_txt (device ['mount_point' ]) or {}
203
- device .update ({"daplink_%s" % f .lower ().replace (' ' , '_' ): v
204
- for f , v in details_txt .items ()})
205
-
195
+ self ._update_device_from_fs (device , include_extra_info )
206
196
return device
207
197
else :
208
198
return None
209
199
200
+ def _update_device_from_fs (self , device , include_extra_info ):
201
+ if not device .get ('mount_point' , None ):
202
+ device ['device_type' ] = 'unknown'
203
+ return
204
+
205
+ device ['device_type' ] = self ._detect_device_type (device ['mount_point' ])
206
+
207
+ # details.txt check happens in here now
208
+ self ._update_device_details (device , include_extra_info )
209
+
210
+ device ['platform_name' ] = self .plat_db .get (device ['target_id' ][0 :4 ],
211
+ device_type = device ['device_type' ])
212
+
213
+ def _detect_device_type (self , device ):
214
+ """ Returns a string of the device type
215
+ @return 'daplink' or 'jlink'
216
+ """
217
+ raise NotImplementedError
218
+
219
+ def _update_device_details (self , device , include_extra_info ):
220
+ """ Updates device dict with information from the filesystem
221
+ @param device Device dictionary to update. Should contain a valid
222
+ 'mount_point' value
223
+ @param include_extra_info Controls how much information (and by extension,
224
+ the performance) is returned from the filesystem
225
+ """
226
+ {
227
+ 'daplink' : self ._update_device_details_daplink ,
228
+ 'jlink' : self ._update_device_details_jlink
229
+ }[device ['device_type' ]](device , include_extra_info )
230
+
231
+ def _update_device_details_daplink (self , device , include_extra_info ):
232
+ self ._update_device_from_htm (device )
233
+ if include_extra_info :
234
+ details_txt = self ._details_txt (device ['mount_point' ]) or {}
235
+ device .update ({"daplink_%s" % f .lower ().replace (' ' , '_' ): v
236
+ for f , v in details_txt .items ()})
237
+
238
+ def _update_device_details_jlink (self , device , include_extra_info ):
239
+ raise NotImplementedError
240
+
210
241
def _update_device_from_htm (self , device ):
211
242
"""Set the 'target_id', 'target_id_mbed_htm', 'platform_name' and
212
243
'daplink_*' attributes by reading from mbed.htm on the device
@@ -372,7 +403,7 @@ def get_string(self, border=False, header=True, padding_width=1, sortby='platfor
372
403
"""
373
404
from prettytable import PrettyTable
374
405
result = ''
375
- mbeds = self .list_mbeds (unique_names = True , read_details_txt = True )
406
+ mbeds = self .list_mbeds (unique_names = True , include_extra_info = True )
376
407
if mbeds :
377
408
""" ['platform_name', 'mount_point', 'serial_port', 'target_id'] - columns generated from USB auto-detection
378
409
['platform_name_unique', ...] - columns generated outside detection subsystem (OS dependent detection)
0 commit comments