3
3
import subprocess
4
4
import shutil
5
5
import sys
6
+ from pathlib import Path
6
7
7
8
8
9
# Add default key/value pair to config file
9
- def defaultConfig (config_file_path , data ):
10
+ def defaultConfig (config_file_path : Path , data : dict ):
10
11
print (f"Please check the default configuration '{ config_file_path } '." )
11
12
config_file = open (config_file_path , "w" )
12
13
config_file .write (json .dumps (data , indent = 2 ))
@@ -15,15 +16,15 @@ def defaultConfig(config_file_path, data):
15
16
16
17
17
18
# Create a folder if not exists
18
- def createFolder (path ):
19
+ def createFolder (path : Path ):
19
20
try :
20
21
path .mkdir (parents = True , exist_ok = True )
21
22
except OSError :
22
23
print (f"Error: Creating directory { path } " )
23
24
24
25
25
26
# Delete targeted folder recursively
26
- def deleteFolder (path ):
27
+ def deleteFolder (path : Path ):
27
28
if path .is_dir ():
28
29
shutil .rmtree (path , ignore_errors = True )
29
30
@@ -38,15 +39,16 @@ def copyFolder(src, dest, ign_patt=set()):
38
39
39
40
40
41
# copy one file to dest
41
- def copyFile (src , dest ):
42
+ def copyFile (src : Path , dest : Path ):
42
43
try :
43
44
if src .is_file ():
44
45
shutil .copy (str (src ), str (dest ))
45
46
except OSError as e :
46
47
print (f"Error: File { src } not copied. { e } " )
47
48
48
49
49
- def genSTM32List (path , pattern ):
50
+ # get list of STM32 series from HAL driver directory
51
+ def genSTM32List (path : Path , pattern : str = None ):
50
52
stm32_list = [] # series
51
53
dir_pattern = re .compile (r"^STM32(.*)xx_HAL_Driver$" , re .IGNORECASE )
52
54
@@ -63,7 +65,7 @@ def genSTM32List(path, pattern):
63
65
return stm32_list
64
66
65
67
66
- def execute_cmd (cmd , stderror ):
68
+ def execute_cmd (cmd : list , stderror : int ):
67
69
try :
68
70
output = subprocess .check_output (cmd , stderr = stderror ).decode ("utf-8" ).strip ()
69
71
except subprocess .CalledProcessError as e :
@@ -72,7 +74,7 @@ def execute_cmd(cmd, stderror):
72
74
return output
73
75
74
76
75
- def getRepoBranchName (repo_path ):
77
+ def getRepoBranchName (repo_path : Path ):
76
78
bname = ""
77
79
rname = ""
78
80
cmd = ["git" , "-C" , repo_path , "branch" , "-r" ]
0 commit comments