@@ -109,14 +109,14 @@ def list_mbeds_ext(self):
109
109
110
110
def list_mbeds (
111
111
self , fs_interaction = FSInteraction .BeforeFilter ,
112
- platform_name_filters = [] , unique_names = False ,
112
+ filter_function = None , unique_names = False ,
113
113
read_details_txt = 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
117
117
trade of between quality of service and speed
118
- @param platform_name_filters A series of regular expressions to filter
119
- filter targets by
118
+ @param filter_function Function that is passed each mbed candidate,
119
+ should return True if it should be included in the result
120
120
@param unique_names A boolean controlling the presence of the
121
121
'platform_unique_name' member of the output dict
122
122
@param read_details_text A boolean controlling the presense of the
@@ -128,8 +128,6 @@ def list_mbeds(
128
128
candidates = list (self .find_candidates ())
129
129
logger .debug ("Candidates for display %r" , candidates )
130
130
result = []
131
- platform_name_matcher = re .compile ("|" .join ("({})" .format (pf ) for pf
132
- in platform_name_filters ))
133
131
for device in candidates :
134
132
if ((not device ['mount_point' ] or
135
133
not self .mount_point_ready (device ['mount_point' ])) and
@@ -144,7 +142,7 @@ def list_mbeds(
144
142
FSInteraction .BeforeFilter : self ._fs_before_id_check ,
145
143
FSInteraction .AfterFilter : self ._fs_after_id_check ,
146
144
FSInteraction .Never : self ._fs_never
147
- }[fs_interaction ](device , platform_name_matcher )
145
+ }[fs_interaction ](device , filter_function )
148
146
if maybe_device :
149
147
if unique_names :
150
148
name = device ['platform_name' ]
@@ -167,36 +165,38 @@ def list_mbeds(
167
165
168
166
return result
169
167
170
- def _fs_never (self , device , pn ):
168
+ def _fs_never (self , device , filter_function ):
171
169
"""Filter device without touching the file system of the device"""
172
170
device ['target_id' ] = device ['target_id_usb_id' ]
173
171
device ['target_id_mbed_htm' ] = None
174
172
device ['platform_name' ] = self .plat_db .get (device ['target_id' ][0 :4 ])
175
- if device ['platform_name' ] and not pn .match (device ['platform_name' ]):
176
- return None
177
- else :
173
+ if not filter_function or filter_function (device ):
178
174
return device
175
+ else :
176
+ return None
179
177
180
- def _fs_before_id_check (self , device , pn ):
178
+ def _fs_before_id_check (self , device , filter_function ):
181
179
"""Filter device after touching the file system of the device.
182
180
Said another way: Touch the file system before filtering
183
181
"""
184
182
self ._update_device_from_htm (device )
185
- if device ['platform_name' ] and not pn .match (device ['platform_name' ]):
186
- return None
187
- else :
183
+ if not filter_function or filter_function (device ):
188
184
return device
185
+ else :
186
+ return None
189
187
190
- def _fs_after_id_check (self , device , pn ):
188
+ def _fs_after_id_check (self , device , filter_function ):
191
189
"""Filter device before touching the file system of the device.
192
190
Said another way: Touch the file system after filtering
193
191
"""
194
- plat_name = self . plat_db . get ( device ['target_id_usb_id' ][ 0 : 4 ])
195
- if plat_name and not pn . match ( plat_name ):
196
- return None
197
- else :
192
+ device [ 'target_id' ] = device ['target_id_usb_id' ]
193
+ device [ 'target_id_mbed_htm' ] = None
194
+ device [ 'platform_name' ] = self . plat_db . get ( device [ 'target_id' ][ 0 : 4 ])
195
+ if not filter_function or filter_function ( device ) :
198
196
self ._update_device_from_htm (device )
199
197
return device
198
+ else :
199
+ return None
200
200
201
201
def _update_device_from_htm (self , device ):
202
202
"""Set the 'target_id', 'target_id_mbed_htm', 'platform_name' and
0 commit comments