• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ARMmbed / mbed-os-tools / #457

24 Aug 2024 09:15PM CUT coverage: 0.0% (-59.9%) from 59.947%
#457

push

coveralls-python

web-flow
Merge 7c6dbce13 into c467d6f14

0 of 4902 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/mbed_os_tools/detect/platform_database.py
1
# Copyright (c) 2018, Arm Limited and affiliates.
2
# SPDX-License-Identifier: Apache-2.0
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15

16
"""Functions that manage a platform database"""
×
17

18
import datetime
×
19
import json
×
20
import re
×
21
from collections import OrderedDict, defaultdict
×
22
from copy import copy
×
23
from io import open
×
24
from os import makedirs
×
25
from os.path import join, dirname, getmtime
×
26
from appdirs import user_data_dir
×
27
from fasteners import InterProcessLock
×
28

29
import logging
×
30

31
logger = logging.getLogger("mbedls.platform_database")
×
32
logger.addHandler(logging.NullHandler())
×
33
del logging
×
34

35
try:
×
36
    unicode
×
37
except NameError:
×
38
    unicode = str
×
39

40
LOCAL_PLATFORM_DATABASE = join(user_data_dir("mbedls"), "platforms.json")
×
41
LOCAL_MOCKS_DATABASE = join(user_data_dir("mbedls"), "mock.json")
×
42

43
DEFAULT_PLATFORM_DB = {
×
44
    u"daplink": {
45
        u"0200": u"KL25Z",
46
        u"0201": u"KW41Z",
47
        u"0210": u"KL05Z",
48
        u"0214": u"HEXIWEAR",
49
        u"0217": u"K82F",
50
        u"0218": u"KL82Z",
51
        u"0220": u"KL46Z",
52
        u"0227": u"MIMXRT1050_EVK",
53
        u"0228": u"RAPIDIOT_K64F",
54
        u"0230": u"K20D50M",
55
        u"0231": u"K22F",
56
        u"0234": u"RAPIDIOT_KW41Z",
57
        u"0236": u"LPC55S69",
58
        u"0240": u"K64F",
59
        u"0245": u"K64F",
60
        u"0250": u"KW24D",
61
        u"0261": u"KL27Z",
62
        u"0262": u"KL43Z",
63
        u"0300": u"MTS_GAMBIT",
64
        u"0305": u"MTS_MDOT_F405RG",
65
        u"0310": u"MTS_DRAGONFLY_F411RE",
66
        u"0311": u"K66F",
67
        u"0312": u"MTS_DRAGONFLY_L471QG",
68
        u"0313": u"MTS_DRAGONFLY_L496VG",
69
        u"0315": u"MTS_MDOT_F411RE",
70
        u"0316": u"MTS_DRAGONFLY_F413RH",
71
        u"0350": u"XDOT_L151CC",
72
        u"0360": u"HANI_IOT",
73
        u"0400": u"MAXWSNENV",
74
        u"0405": u"MAX32600MBED",
75
        u"0407": u"MAX32620HSP",
76
        u"0408": u"MAX32625NEXPAQ",
77
        u"0409": u"MAX32630FTHR",
78
        u"0410": u"ETTEPLAN_LORA",
79
        u"0415": u"MAX32625MBED",
80
        u"0416": u"MAX32625PICO",
81
        u"0418": u"MAX32620FTHR",
82
        u"0419": u"MAX35103EVKIT2",
83
        u"0421": u"MAX32660EVSYS",
84
        u"0424": u"MAX32670EVKIT",
85
        u"0450": u"MTB_UBLOX_ODIN_W2",
86
        u"0451": u"MTB_MXCHIP_EMW3166",
87
        u"0452": u"MTB_LAIRD_BL600",
88
        u"0453": u"MTB_MTS_XDOT",
89
        u"0454": u"MTB_MTS_DRAGONFLY",
90
        u"0455": u"MTB_UBLOX_NINA_B1",
91
        u"0456": u"MTB_MURATA_ABZ",
92
        u"0457": u"MTB_RAK811",
93
        u"0458": u"ADV_WISE_1510",
94
        u"0459": u"ADV_WISE_1530",
95
        u"0460": u"ADV_WISE_1570",
96
        u"0461": u"MTB_LAIRD_BL652",
97
        u"0462": u"MTB_USI_WM_BN_BM_22",
98
        u"0465": u"MTB_LAIRD_BL654",
99
        u"0466": u"MTB_MURATA_WSM_BL241",
100
        u"0467": u"MTB_STM_S2LP",
101
        u"0468": u"MTB_STM_L475",
102
        u"0469": u"MTB_STM32_F439",
103
        u"0472": u"MTB_ACONNO_ACN52832",
104
        u"0602": u"EV_COG_AD3029LZ",
105
        u"0603": u"EV_COG_AD4050LZ",
106
        u"0604": u"SDP_K1",
107
        u"0700": u"NUCLEO_F103RB",
108
        u"0705": u"NUCLEO_F302R8",
109
        u"0710": u"NUCLEO_L152RE",
110
        u"0715": u"NUCLEO_L053R8",
111
        u"0720": u"NUCLEO_F401RE",
112
        u"0725": u"NUCLEO_F030R8",
113
        u"0729": u"NUCLEO_G071RB",
114
        u"0730": u"NUCLEO_F072RB",
115
        u"0735": u"NUCLEO_F334R8",
116
        u"0740": u"NUCLEO_F411RE",
117
        u"0742": u"NUCLEO_F413ZH",
118
        u"0743": u"DISCO_F413ZH",
119
        u"0744": u"NUCLEO_F410RB",
120
        u"0745": u"NUCLEO_F303RE",
121
        u"0746": u"DISCO_F303VC",
122
        u"0747": u"NUCLEO_F303ZE",
123
        u"0750": u"NUCLEO_F091RC",
124
        u"0755": u"NUCLEO_F070RB",
125
        u"0760": u"NUCLEO_L073RZ",
126
        u"0764": u"DISCO_L475VG_IOT01A",
127
        u"0765": u"NUCLEO_L476RG",
128
        u"0766": u"SILICA_SENSOR_NODE",
129
        u"0770": u"NUCLEO_L432KC",
130
        u"0774": u"DISCO_L4R9I",
131
        u"0775": u"NUCLEO_F303K8",
132
        u"0776": u"NUCLEO_L4R5ZI",
133
        u"0777": u"NUCLEO_F446RE",
134
        u"0778": u"NUCLEO_F446ZE",
135
        u"0779": u"NUCLEO_L433RC_P",
136
        u"0780": u"NUCLEO_L011K4",
137
        u"0781": u"NUCLEO_L4R5ZI_P",
138
        u"0783": u"NUCLEO_L010RB",
139
        u"0785": u"NUCLEO_F042K6",
140
        u"0788": u"DISCO_F469NI",
141
        u"0790": u"NUCLEO_L031K6",
142
        u"0791": u"NUCLEO_F031K6",
143
        u"0795": u"DISCO_F429ZI",
144
        u"0796": u"NUCLEO_F429ZI",
145
        u"0797": u"NUCLEO_F439ZI",
146
        u"0805": u"DISCO_L053C8",
147
        u"0810": u"DISCO_F334C8",
148
        u"0812": u"NUCLEO_F722ZE",
149
        u"0813": u"NUCLEO_H743ZI",
150
        u"0814": u"DISCO_H747I",
151
        u"0815": u"DISCO_F746NG",
152
        u"0816": u"NUCLEO_F746ZG",
153
        u"0817": u"DISCO_F769NI",
154
        u"0818": u"NUCLEO_F767ZI",
155
        u"0820": u"DISCO_L476VG",
156
        u"0821": u"NUCLEO_L452RE",
157
        u"0822": u"DISCO_L496AG",
158
        u"0823": u"NUCLEO_L496ZG",
159
        u"0824": u"LPC824",
160
        u"0825": u"DISCO_F412ZG",
161
        u"0826": u"NUCLEO_F412ZG",
162
        u"0827": u"NUCLEO_L486RG",
163
        u"0828": u"NUCLEO_L496ZG_P",
164
        u"0829": u"NUCLEO_L452RE_P",
165
        u"0830": u"DISCO_F407VG",
166
        u"0833": u"DISCO_L072CZ_LRWAN1",
167
        u"0835": u"NUCLEO_F207ZG",
168
        u"0836": u"NUCLEO_H743ZI2",
169
        u"0839": u"NUCLEO_WB55RG",
170
        u"0840": u"B96B_F446VE",
171
        u"0841": u"NUCLEO_G474RE",
172
        u"0842": u"NUCLEO_H753ZI",
173
        u"0843": u"NUCLEO_H745ZI_Q",
174
        u"0844": u"NUCLEO_H755ZI_Q",
175
        u"0847": u"DISCO_H745I",
176
        u"0849": u"NUCLEO_G070RB",
177
        u"0850": u"NUCLEO_G431RB",
178
        u"0851": u"NUCLEO_G431KB",
179
        u"0852": u"NUCLEO_G031K8",
180
        u"0853": u"NUCLEO_F301K8",
181
        u"0854": u"NUCLEO_L552ZE_Q",
182
        u"0855": u"DISCO_L562QE",
183
        u"0858": u"DISCO_H750B",
184
        u"0859": u"DISCO_H7B3I",
185
        u"0860": u"NUCLEO_H7A3ZI_Q",
186
        u"0863": u"DISCO_L4P5G",
187
        u"0865": u"NUCLEO_L4P5ZG",
188
        u"0866": u"NUCLEO_WL55JC",
189
        u"0871": u"NUCLEO_H723ZG",
190
        u"0872": u"NUCLEO_G0B1RE",
191
        u"0875": u"DISCO_H735G",
192
        u"0879": u"NUCLEO_F756ZG",
193
        u"0882": u"NUCLEO_G491RE",
194
        u"0883": u"NUCLEO_WB15CC",
195
        u"0884": u"DISCO_WB5MMG",
196
        u"0885": u"B_L4S5I_IOT01A",
197
        u"0886": u"NUCLEO_U575ZI_Q",
198
        u"0887": u"B_U585I_IOT02A",
199
        u"0900": u"SAMR21G18A",
200
        u"0905": u"SAMD21G18A",
201
        u"0910": u"SAML21J18A",
202
        u"0915": u"SAMD21J18A",
203
        u"1000": u"LPC2368",
204
        u"1010": u"LPC1768",
205
        u"1017": u"HRM1017",
206
        u"1018": u"SSCI824",
207
        u"1019": u"TY51822R3",
208
        u"1022": u"RO359B",
209
        u"1034": u"LPC11U34",
210
        u"1040": u"LPC11U24",
211
        u"1045": u"LPC11U24",
212
        u"1050": u"LPC812",
213
        u"1054": u"LPC54114",
214
        u"1056": u"LPC546XX",
215
        u"1060": u"LPC4088",
216
        u"1061": u"LPC11U35_401",
217
        u"1062": u"LPC4088_DM",
218
        u"1070": u"NRF51822",
219
        u"1075": u"NRF51822_OTA",
220
        u"1080": u"OC_MBUINO",
221
        u"1090": u"RBLAB_NRF51822",
222
        u"1093": u"RBLAB_BLENANO2",
223
        u"1095": u"RBLAB_BLENANO",
224
        u"1100": u"NRF51_DK",
225
        u"1101": u"NRF52_DK",
226
        u"1102": u"NRF52840_DK",
227
        u"1105": u"NRF51_DK_OTA",
228
        u"1114": u"LPC1114",
229
        u"1120": u"NRF51_DONGLE",
230
        u"1130": u"NRF51822_SBK",
231
        u"1140": u"WALLBOT_BLE",
232
        u"1168": u"LPC11U68",
233
        u"1200": u"NCS36510",
234
        u"1234": u"UBLOX_C027",
235
        u"1236": u"UBLOX_EVK_ODIN_W2",
236
        u"1237": u"UBLOX_EVK_NINA_B1",
237
        u"1280": u"OKDO_ODIN_W2",
238
        u"1300": u"NUC472-NUTINY",
239
        u"1301": u"NUMBED",
240
        u"1302": u"NUMAKER_PFM_NUC472",
241
        u"1303": u"NUMAKER_PFM_M453",
242
        u"1304": u"NUMAKER_PFM_M487",
243
        u"1305": u"NU_PFM_M2351",
244
        u"1306": u"NUMAKER_PFM_NANO130",
245
        u"1307": u"NUMAKER_PFM_NUC240",
246
        u"1308": u"NUMAKER_IOT_M487",
247
        u"1309": u"NUMAKER_IOT_M252",
248
        u"1310": u"NUMAKER_IOT_M263A",
249
        u"1312": u"NU_M2354",
250
        u"1313": u"NUMAKER_IOT_M467",
251
        u"1500": u"RHOMBIO_L476DMW1K",
252
        u"1549": u"LPC1549",
253
        u"1600": u"LPC4330_M4",
254
        u"1605": u"LPC4330_M4",
255
        u"1701": u"GD32_F307VG",
256
        u"1702": u"GD32_F450ZI",
257
        u"1703": u"GD32_E103VB",
258
        u'1900': u'CY8CKIT_062_WIFI_BT',
259
        u'1901': u'CY8CPROTO_062_4343W',
260
        u'1902': u'CY8CKIT_062_BLE',
261
        u'1903': u'CYW9P62S1_43012EVB_01',
262
        u'1904': u'CY8CPROTO_063_BLE',
263
        u'1905': u'CY8CKIT_062S2_4343W',
264
        u'1906': u'CYW943012P6EVB_01',
265
        u'1907': u'CY8CPROTO_064_SB',
266
        u'1908': u'CYW9P62S1_43438EVB_01',
267
        u'1909': u'CY8CPROTO_062S2_43012',
268
        u'190A': u'CY8CKIT_064S2_4343W',
269
        u'190B': u'CY8CKIT_062S2_43012',
270
        u'190C': u'CY8CPROTO_064B0S3',
271
        u'190E': u'CY8CPROTO_062S3_4343W',
272
        u'190F': u'CY8CPROTO_064B0S1_BLE',
273
        u'1910': u'CY8CKIT064B0S2_4343W',
274
        u'1911': u'CY8CKIT064S0S2_4343W',
275
        u'1912': u'CYSBSYSKIT_01',
276
        u"2000": u"EFM32_G8XX_STK",
277
        u"2005": u"EFM32HG_STK3400",
278
        u"2010": u"EFM32WG_STK3800",
279
        u"2015": u"EFM32GG_STK3700",
280
        u"2020": u"EFM32LG_STK3600",
281
        u"2025": u"EFM32TG_STK3300",
282
        u"2030": u"EFM32ZG_STK3200",
283
        u"2035": u"EFM32PG_STK3401",
284
        u"2040": u"EFM32PG12_STK3402",
285
        u"2041": u"TB_SENSE_12",
286
        u"2042": u"EFM32GG11_STK3701",
287
        u"2043": u"EFM32TG11_STK3301",
288
        u"2045": u"TB_SENSE_1",
289
        u"2100": u"XBED_LPC1768",
290
        u"2201": u"WIZWIKI_W7500",
291
        u"2202": u"WIZWIKI_W7500ECO",
292
        u"2203": u"WIZWIKI_W7500P",
293
        u"2600": u"EP_AGORA",
294
        u"3001": u"LPC11U24",
295
        u"3101": u"SDT32620B",
296
        u"3102": u"SDT32625B",
297
        u"3103": u"SDT51822B",
298
        u"3104": u"SDT52832B",
299
        u"3105": u"SDT64B",
300
        u"3701": u"S5JS100",
301
        u"3702": u"S3JT100",
302
        u"3703": u"S1SBP6A",
303
        u"4000": u"LPC11U35_Y5_MBUG",
304
        u"4005": u"NRF51822_Y5_MBUG",
305
        u"4100": u"MOTE_L152RC",
306
        u"4337": u"LPC4337",
307
        u"4500": u"DELTA_DFCM_NNN40",
308
        u"4501": u"DELTA_DFBM_NQ620",
309
        u"4502": u"DELTA_DFCM_NNN50",
310
        u"4600": u"REALTEK_RTL8195AM",
311
        u"5000": u"ARM_MPS2",
312
        u"5001": u"ARM_IOTSS_BEID",
313
        u"5002": u"ARM_BEETLE_SOC",
314
        u"5003": u"ARM_MPS2_M0P",
315
        u"5004": u"ARM_CM3DS_MPS2",
316
        u"5005": u"ARM_MPS2_M0DS",
317
        u"5006": u"ARM_MUSCA_A1",
318
        u"5007": u"ARM_MUSCA_B1",
319
        u"5009": u"ARM_MUSCA_S1",
320
        u"5020": u"HOME_GATEWAY_6LOWPAN",
321
        u"5500": u"RZ_A1H",
322
        u"5501": u"GR_LYCHEE",
323
        u"5502": u"GR_MANGO",
324
        u"6000": u"FUTURE_SEQUANA",
325
        u"6660": u"NZ32_SC151",
326
        u"7011": u"TMPM066",
327
        u"7012": u"TMPM3H6",
328
        u"7013": u"TMPM46B",
329
        u"7014": u"TMPM3HQ",
330
        u"7015": u"TMPM4G9",
331
        u"7020": u"TMPM4KN",
332
        u"7402": u"MBED_BR_HAT",
333
        u"7778": u"TEENSY3_1",
334
        u"8001": u"UNO_91H",
335
        u"8012": u"TT_M3HQ",
336
        u"8013": u"TT_M4G9",
337
        u"8080": u"FF1705_L151CC",
338
        u"8081": u"FF_LPC546XX",
339
        u"9001": u"LPC1347",
340
        u"9002": u"LPC11U24",
341
        u"9003": u"LPC1347",
342
        u"9004": u"ARCH_PRO",
343
        u"9006": u"LPC11U24",
344
        u"9007": u"LPC11U35_501",
345
        u"9008": u"XADOW_M0",
346
        u"9009": u"ARCH_BLE",
347
        u"9010": u"ARCH_GPRS",
348
        u"9011": u"ARCH_MAX",
349
        u"9012": u"SEEED_TINY_BLE",
350
        u"9014": u"WIO_3G",
351
        u"9015": u"WIO_BG96",
352
        u"9017": u"WIO_EMW3166",
353
        u"9020": u"UHURU_RAVEN",
354
        u"9900": u"NRF51_MICROBIT",
355
        u"C002": u"VK_RZ_A1H",
356
        u"C005": u"MTM_MTCONNECT04S",
357
        u"C006": u"VBLUNO51",
358
        u"C008": u"SAKURAIO_EVB_01",
359
        u"C030": u"UBLOX_C030_U201",
360
        u"C031": u"UBLOX_C030_N211",
361
        u"C032": u"UBLOX_C030_R404M",
362
        u"C033": u"UBLOX_C030_R410M",
363
        u"C034": u"UBLOX_C030_S200",
364
        u"C035": u"UBLOX_C030_R3121",
365
        u"C036": u"UBLOX_C030_R412M",
366
        u"RIOT": u"RIOT",
367
    },
368
    u"jlink": {
369
        u"X729475D28G": {
370
            u"platform_name": u"NRF51_DK",
371
            u"jlink_device_name": u"nRF51422_xxAC",
372
        },
373
        u"X349858SLYN": {
374
            u"platform_name": u"NRF52_DK",
375
            u"jlink_device_name": u"nRF52832_xxaa",
376
        },
377
        u"FRDM-KL25Z": {
378
            u"platform_name": u"KL25Z",
379
            u"jlink_device_name": u"MKL25Z128xxx4",
380
        },
381
        u"FRDM-KL27Z": {
382
            u"platform_name": u"KL27Z",
383
            u"jlink_device_name": u"MKL27Z64xxx4",
384
        },
385
        u"FRDM-KL43Z": {
386
            u"platform_name": u"KL43Z",
387
            u"jlink_device_name": u"MKL43Z256xxx4",
388
        },
389
    },
390
    u"atmel": {u"2241": "SAML21J18A"},
391
}
392

393

394
def _get_modified_time(path):
×
395
    try:
×
396
        mtime = getmtime(path)
×
397
    except OSError:
×
398
        mtime = 0
×
399
    return datetime.datetime.fromtimestamp(mtime)
×
400

401

402
def _older_than_me(path):
×
403
    return _get_modified_time(path) < _get_modified_time(__file__)
×
404

405

406
def _modify_data_format(data, verbose_data, simple_data_key="platform_name"):
×
407
    if isinstance(data, dict):
×
408
        if verbose_data:
×
409
            return data
×
410

411
        return data[simple_data_key]
×
412
    else:
413
        if verbose_data:
×
414
            return {simple_data_key: data}
×
415

416
        return data
×
417

418

419
def _overwrite_or_open(db):
×
420
    try:
×
421
        if db is LOCAL_PLATFORM_DATABASE and _older_than_me(db):
×
422
            raise ValueError("Platform Database is out of date")
×
423
        with open(db, encoding="utf-8") as db_in:
×
424
            return json.load(db_in)
×
425
    except (IOError, ValueError) as exc:
×
426
        if db is LOCAL_PLATFORM_DATABASE:
×
427
            logger.warning("Error loading database %s: %s; Recreating", db, str(exc))
×
428
            try:
×
429
                makedirs(dirname(db))
×
430
            except OSError:
×
431
                pass
×
432
            try:
×
433
                with open(db, "w", encoding="utf-8") as out:
×
434
                    out.write(unicode(json.dumps(DEFAULT_PLATFORM_DB)))
×
435
            except IOError:
×
436
                pass
×
437
            return copy(DEFAULT_PLATFORM_DB)
×
438
        else:
439
            return {}
×
440

441

442
class PlatformDatabase(object):
×
443
    """Represents a union of multiple platform database files.
444
    Handles inter-process synchronization of database files.
445
    """
446

447
    target_id_pattern = re.compile(r"^[a-fA-F0-9]{4}$")
×
448

449
    def __init__(self, database_files, primary_database=None):
×
450
        """Construct a PlatformDatabase object from a series of platform database
451
        files
452
        """
453
        self._prim_db = primary_database
×
454
        if not self._prim_db and len(database_files) == 1:
×
455
            self._prim_db = database_files[0]
×
456
        self._dbs = OrderedDict()
×
457
        self._keys = defaultdict(set)
×
458
        for db in database_files:
×
459
            new_db = _overwrite_or_open(db)
×
460
            first_value = None
×
461
            if new_db.values():
×
462
                first_value = next(iter(new_db.values()))
×
463
                if not isinstance(first_value, dict):
×
464
                    new_db = {"daplink": new_db}
×
465

466
            if new_db:
×
467
                for device_type in new_db:
×
468
                    duplicates = self._keys[device_type].intersection(
×
469
                        set(new_db[device_type].keys())
470
                    )
471
                    duplicates = set(["%s.%s" % (device_type, k) for k in duplicates])
×
472
                    if duplicates:
×
473
                        logger.warning(
×
474
                            "Duplicate platform ids found: %s,"
475
                            " ignoring the definitions from %s",
476
                            " ".join(duplicates),
477
                            db,
478
                        )
479
                    self._dbs[db] = new_db
×
480
                    self._keys[device_type] = self._keys[device_type].union(
×
481
                        new_db[device_type].keys()
482
                    )
483
            else:
484
                self._dbs[db] = new_db
×
485

486
    def items(self, device_type="daplink"):
×
487
        for db in self._dbs.values():
×
488
            for entry in db.get(device_type, {}).items():
×
489
                yield entry
×
490

491
    def all_ids(self, device_type="daplink"):
×
492
        return iter(self._keys[device_type])
×
493

494
    def get(self, index, default=None, device_type="daplink", verbose_data=False):
×
495
        """Standard lookup function. Works exactly like a dict. If 'verbose_data'
496
        is True, all data for the platform is returned as a dict."""
497
        for db in self._dbs.values():
×
498
            if device_type in db:
×
499
                maybe_answer = db[device_type].get(index, None)
×
500
                if maybe_answer:
×
501
                    return _modify_data_format(maybe_answer, verbose_data)
×
502

503
        return default
×
504

505
    def _update_db(self):
×
506
        if self._prim_db:
×
507
            lock = InterProcessLock("%s.lock" % self._prim_db)
×
508
            acquired = lock.acquire(blocking=False)
×
509
            if not acquired:
×
510
                logger.debug("Waiting 60 seconds for file lock")
×
511
                acquired = lock.acquire(blocking=True, timeout=60)
×
512
            if acquired:
×
513
                try:
×
514
                    with open(self._prim_db, "w", encoding="utf-8") as out:
×
515
                        out.write(unicode(json.dumps(self._dbs[self._prim_db])))
×
516
                    return True
×
517
                finally:
518
                    lock.release()
×
519
            else:
520
                logger.error(
×
521
                    "Could not update platform database: "
522
                    "Lock acquire failed after 60 seconds"
523
                )
524
                return False
×
525
        else:
526
            logger.error(
×
527
                "Can't update platform database: destination database is ambiguous"
528
            )
529
            return False
×
530

531
    def add(self, id, platform_name, permanent=False, device_type="daplink"):
×
532
        """Add a platform to this database, optionally updating an origin
533
        database
534
        """
535
        if self.target_id_pattern.match(id):
×
536
            if self._prim_db:
×
537
                if device_type not in self._dbs[self._prim_db]:
×
538
                    self._dbs[self._prim_db][device_type] = {}
×
539
                self._dbs[self._prim_db][device_type][id] = platform_name
×
540
            else:
541
                cur_db = next(iter(self._dbs.values()))
×
542
                if device_type not in cur_db:
×
543
                    cur_db[device_type] = {}
×
544
                cur_db[device_type][id] = platform_name
×
545
            self._keys[device_type].add(id)
×
546
            if permanent:
×
547
                self._update_db()
×
548
        else:
549
            raise ValueError("Invald target id: %s" % id)
×
550

551
    def remove(self, id, permanent=False, device_type="daplink", verbose_data=False):
×
552
        """Remove a platform from this database, optionally updating an origin
553
        database. If 'verbose_data' is True, all data for the platform is returned
554
        as a dict.
555
        """
556
        logger.debug("Trying remove of %s", id)
×
557
        if id == "*" and device_type in self._dbs[self._prim_db]:
×
558
            self._dbs[self._prim_db][device_type] = {}
×
559
            if permanent:
×
560
                self._update_db()
×
561
        else:
562
            for db in self._dbs.values():
×
563
                if device_type in db and id in db[device_type]:
×
564
                    logger.debug("Removing id...")
×
565
                    removed = db[device_type][id]
×
566
                    del db[device_type][id]
×
567
                    self._keys[device_type].remove(id)
×
568
                    if permanent:
×
569
                        self._update_db()
×
570

571
                    return _modify_data_format(removed, verbose_data)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc