src/eric7/MicroPython/Devices/CircuitPythonUpdater/CircupFunctions.py

branch
eric7
changeset 11011
f1f1c8d0255d
parent 10908
ef1b3cd9a6ca
child 11090
f5f5f5803935
equal deleted inserted replaced
11010:798440273c11 11011:f1f1c8d0255d
15 15
16 import os 16 import os
17 import shutil 17 import shutil
18 18
19 import circup 19 import circup
20 import circup.command_utils
21 import circup.module
22 import circup.shared
20 import requests 23 import requests
21 24
22 from PyQt6.QtCore import QCoreApplication 25 from PyQt6.QtCore import QCoreApplication
23 26
24 from eric7.EricWidgets import EricMessageBox 27 from eric7.EricWidgets import EricMessageBox
33 @type str or circup.DiskBackend 36 @type str or circup.DiskBackend
34 @param bundles_list list of supported bundles 37 @param bundles_list list of supported bundles
35 @type list of circup.Bundle 38 @type list of circup.Bundle
36 @return list of Module instances describing the current state of the 39 @return list of Module instances describing the current state of the
37 modules on the connected device 40 modules on the connected device
38 @rtype list of circup.Module 41 @rtype list of circup.module.Module
39 """ 42 """
40 backend = ( 43 backend = (
41 circup.DiskBackend(device_path, circup.logger) 44 circup.DiskBackend(device_path, circup.logger)
42 if isinstance(device_path, str) 45 if isinstance(device_path, str)
43 else device_path 46 else device_path
44 ) 47 )
45 result = [] 48 result = []
46 try: 49 try:
47 device_modules = backend.get_device_versions() 50 device_modules = backend.get_device_versions()
48 bundle_modules = circup.get_bundle_versions(bundles_list) 51 bundle_modules = circup.get_bundle_versions(bundles_list)
49 for name, device_metadata in device_modules.items(): 52 for key, device_metadata in device_modules.items():
50 if name in bundle_modules: 53 if key in bundle_modules:
51 path = device_metadata["path"] 54 path = device_metadata["path"]
52 bundle_metadata = bundle_modules[name] 55 bundle_metadata = bundle_modules[key]
53 repo = bundle_metadata.get("__repo__") 56 repo = bundle_metadata.get("__repo__")
54 bundle = bundle_metadata.get("bundle") 57 bundle = bundle_metadata.get("bundle")
55 device_version = device_metadata.get("__version__") 58 device_version = device_metadata.get("__version__")
56 bundle_version = bundle_metadata.get("__version__") 59 bundle_version = bundle_metadata.get("__version__")
57 mpy = device_metadata["mpy"] 60 mpy = device_metadata["mpy"]
58 compatibility = device_metadata.get("compatibility", (None, None)) 61 compatibility = device_metadata.get("compatibility", (None, None))
62 module_name = (
63 path.split(os.sep)[-1]
64 if not path.endswith(os.sep)
65 else path[:-1].split(os.sep)[-1] + os.sep
66 )
59 result.append( 67 result.append(
60 circup.Module( 68 circup.module.Module(
61 path, 69 module_name,
70 backend,
62 repo, 71 repo,
63 device_version, 72 device_version,
64 bundle_version, 73 bundle_version,
65 mpy, 74 mpy,
66 bundle, 75 bundle,
90 @type circup.Bundle 99 @type circup.Bundle
91 """ 100 """
92 tag = bundle.latest_tag 101 tag = bundle.latest_tag
93 do_update = False 102 do_update = False
94 if tag == bundle.current_tag: 103 if tag == bundle.current_tag:
95 for platform in circup.PLATFORMS: 104 for platform in circup.shared.PLATFORMS:
96 # missing directories (new platform added on an existing install 105 # missing directories (new platform added on an existing install
97 # or side effect of pytest or network errors) 106 # or side effect of pytest or network errors)
98 do_update = do_update or not os.path.isdir(bundle.lib_dir(platform)) 107 do_update = do_update or not os.path.isdir(bundle.lib_dir(platform))
99 else: 108 else:
100 do_update = True 109 do_update = True
101 110
102 if do_update: 111 if do_update:
103 try: 112 try:
104 circup.get_bundle(bundle, tag) 113 circup.get_bundle(bundle, tag)
105 circup.tags_data_save_tag(bundle.key, tag) 114 circup.command_utils.tags_data_save_tag(bundle.key, tag)
106 except requests.exceptions.HTTPError as ex: 115 except requests.exceptions.HTTPError as ex:
107 EricMessageBox.critical( 116 EricMessageBox.critical(
108 None, 117 None,
109 QCoreApplication.translate("CircupFunctions", "Download Bundle"), 118 QCoreApplication.translate("CircupFunctions", "Download Bundle"),
110 QCoreApplication.translate( 119 QCoreApplication.translate(

eric ide

mercurial