10
10
from packaging import version
11
11
from pathlib import Path
12
12
from urllib .parse import urljoin
13
+ from xml .dom .minidom import parse
13
14
14
15
script_path = Path (__file__ ).parent .resolve ()
15
16
sys .path .append (str (script_path .parent ))
29
30
repo_generic_name = "STM32Cube"
30
31
repo_core_name = "Arduino_Core_STM32"
31
32
repo_local_path = home / "STM32Cube_repo"
33
+ local_cube_path = Path ("" )
32
34
33
35
# From
34
36
# Relative to repo path
@@ -276,6 +278,45 @@ def updateCoreRepo():
276
278
execute_cmd (cmd , None )
277
279
278
280
281
+ def checkSTLocal ():
282
+ global local_cube_path
283
+ global stm32_list
284
+ # Handle local STM32Cube
285
+ local_cube_path = Path (upargs .local )
286
+ if not local_cube_path .exists ():
287
+ print (f"Could not find local copy: { local_cube_path } !" )
288
+ exit (1 )
289
+ cube_release = "Unknown"
290
+ # Define the serie based on package.xml
291
+ package_file = local_cube_path / "package.xml"
292
+ if package_file .is_file ():
293
+ xml_file = parse (str (package_file ))
294
+ PackDescription_item = xml_file .getElementsByTagName ("PackDescription" )
295
+ for item in PackDescription_item :
296
+ cube_release = item .attributes ["Release" ].value
297
+ if item .hasAttribute ("Patch" ):
298
+ cube_release = item .attributes ["Patch" ].value
299
+ else :
300
+ print (f"Could not find: { package_file } !" )
301
+ exit (1 )
302
+ # Process Cube release
303
+ release_regex = r"FW.(.+).(\d+.\d+.\d+)$"
304
+ release_match = re .match (release_regex , cube_release )
305
+ if release_match :
306
+ serie = release_match .group (1 )
307
+ cube_release = release_match .group (2 )
308
+ print (f"Local STM32Cube { serie } release { cube_release } \n " )
309
+ else :
310
+ print (
311
+ f"Unable to define local STM32Cube serie and version of { local_cube_path } !"
312
+ )
313
+ exit (1 )
314
+ cube_versions [serie ] = cube_release
315
+ # Manage only one STM32Cube
316
+ stm32_list = [serie .upper ()]
317
+ checkVersion (serie , local_cube_path )
318
+
319
+
279
320
def updateSTRepo ():
280
321
# Handle STM32Cube repo
281
322
for serie in stm32_list :
@@ -572,8 +613,11 @@ def updateMDFile(md_file, serie, version):
572
613
573
614
def updateCore ():
574
615
for serie in stm32_list :
575
- cube_name = f"{ repo_generic_name } { serie } "
576
- cube_path = repo_local_path / cube_name
616
+ if upargs .local :
617
+ cube_path = local_cube_path
618
+ else :
619
+ cube_name = f"{ repo_generic_name } { serie } "
620
+ cube_path = repo_local_path / cube_name
577
621
core_path = repo_local_path / repo_core_name
578
622
core_HAL_ver = core_HAL_versions [serie ]
579
623
cube_HAL_ver = cube_HAL_versions [serie ]
@@ -678,6 +722,12 @@ def updateCore():
678
722
upparser .add_argument (
679
723
"-c" , "--check" , help = "Check versions. Default all." , action = "store_true"
680
724
)
725
+ upparser .add_argument (
726
+ "-l" ,
727
+ "--local" ,
728
+ metavar = "local" ,
729
+ help = "Use local copy of one STM32cube instead of GitHub" ,
730
+ )
681
731
group = upparser .add_mutually_exclusive_group ()
682
732
group .add_argument (
683
733
"-s" , "--serie" , metavar = "pattern" , help = "Pattern of the STM32 serie(s) to update"
@@ -686,6 +736,7 @@ def updateCore():
686
736
"-a" , "--add" , metavar = "name" , help = "STM32 serie name to add. Ex: 'F1'"
687
737
)
688
738
739
+
689
740
upargs = upparser .parse_args ()
690
741
691
742
@@ -701,7 +752,10 @@ def main():
701
752
else :
702
753
print (f"{ upargs .add } can't be added as it already exists!" )
703
754
exit (1 )
704
- updateSTRepo ()
755
+ if upargs .local :
756
+ checkSTLocal ()
757
+ else :
758
+ updateSTRepo ()
705
759
if upargs .check :
706
760
printVersion ()
707
761
else :
0 commit comments