263
263
u'FFFF' : u'K20 BOOTLOADER' ,
264
264
u'RIOT' : u'RIOT' ,
265
265
},
266
- 'jlink' : {
267
- u'X349858SLYN' : u'NRF52_DK' ,
268
- u'FRDM-KL25Z' : u'KL25Z' ,
269
- u'FRDM-KL27Z' : u'KL27Z' ,
270
- u'FRDM-KL43Z' : u'KL43Z'
266
+ u'jlink' : {
267
+ u'X349858SLYN' : {
268
+ u'platform_name' : u'NRF52_DK' ,
269
+ u'jlink_device_name' : u'nRF52832_xxaa'
270
+ },
271
+ u'FRDM-KL25Z' : {
272
+ u'platform_name' : u'KL25Z' ,
273
+ u'jlink_device_name' : u'MKL25Z128xxx4'
274
+ },
275
+ u'FRDM-KL27Z' : {
276
+ u'platform_name' : u'KL27Z' ,
277
+ u'jlink_device_name' : u'MKL27Z64xxx4'
278
+ },
279
+ u'FRDM-KL43Z' : {
280
+ u'platform_name' : u'KL43Z' ,
281
+ u'jlink_device_name' : u'MKL43Z256xxx4'
282
+ }
271
283
}
272
284
}
273
285
@@ -284,6 +296,21 @@ def _older_than_me(path):
284
296
return _get_modified_time (path ) < _get_modified_time (__file__ )
285
297
286
298
299
+ def _modify_data_format (data , verbose_data , simple_data_key = 'platform_name' ):
300
+ if isinstance (data , dict ):
301
+ if verbose_data :
302
+ return data
303
+
304
+ return data [simple_data_key ]
305
+ else :
306
+ if verbose_data :
307
+ return {
308
+ simple_data_key : data
309
+ }
310
+
311
+ return data
312
+
313
+
287
314
def _overwrite_or_open (db ):
288
315
try :
289
316
if db is LOCAL_PLATFORM_DATABASE and _older_than_me (db ):
@@ -355,13 +382,14 @@ def items(self, device_type='daplink'):
355
382
def all_ids (self , device_type = 'daplink' ):
356
383
return iter (self ._keys [device_type ])
357
384
358
- def get (self , index , default = None , device_type = 'daplink' ):
359
- """Standard lookup function. Works exactly like a dict"""
385
+ def get (self , index , default = None , device_type = 'daplink' , verbose_data = False ):
386
+ """Standard lookup function. Works exactly like a dict. If 'verbose_data'
387
+ is True, all data for the platform is returned as a dict."""
360
388
for db in self ._dbs .values ():
361
389
if device_type in db :
362
390
maybe_answer = db [device_type ].get (index , None )
363
391
if maybe_answer :
364
- return maybe_answer
392
+ return _modify_data_format ( maybe_answer , verbose_data )
365
393
366
394
return default
367
395
@@ -409,9 +437,10 @@ def add(self, id, platform_name, permanent=False, device_type='daplink'):
409
437
else :
410
438
raise ValueError ("Invald target id: %s" % id )
411
439
412
- def remove (self , id , permanent = False , device_type = 'daplink' ):
440
+ def remove (self , id , permanent = False , device_type = 'daplink' , verbose_data = False ):
413
441
"""Remove a platform from this database, optionally updating an origin
414
- database
442
+ database. If 'verbose_data' is True, all data for the platform is returned
443
+ as a dict.
415
444
"""
416
445
logger .debug ("Trying remove of %s" , id )
417
446
if id is '*' and device_type in self ._dbs [self ._prim_db ]:
@@ -424,4 +453,5 @@ def remove(self, id, permanent=False, device_type='daplink'):
424
453
self ._keys [device_type ].remove (id )
425
454
if permanent :
426
455
self ._update_db ()
427
- return removed
456
+
457
+ return _modify_data_format (removed , verbose_data )
0 commit comments