Skip to content

Commit d80a672

Browse files
committed
ci(common): harden functions
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 91b29fb commit d80a672

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

CI/utils/common_ext.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
import subprocess
44
import shutil
55
import sys
6+
from pathlib import Path
67

78

89
# Add default key/value pair to config file
9-
def defaultConfig(config_file_path, data):
10+
def defaultConfig(config_file_path: Path, data: dict):
1011
print(f"Please check the default configuration '{config_file_path}'.")
1112
config_file = open(config_file_path, "w")
1213
config_file.write(json.dumps(data, indent=2))
@@ -15,15 +16,15 @@ def defaultConfig(config_file_path, data):
1516

1617

1718
# Create a folder if not exists
18-
def createFolder(path):
19+
def createFolder(path: Path):
1920
try:
2021
path.mkdir(parents=True, exist_ok=True)
2122
except OSError:
2223
print(f"Error: Creating directory {path}")
2324

2425

2526
# Delete targeted folder recursively
26-
def deleteFolder(path):
27+
def deleteFolder(path: Path):
2728
if path.is_dir():
2829
shutil.rmtree(path, ignore_errors=True)
2930

@@ -38,15 +39,16 @@ def copyFolder(src, dest, ign_patt=set()):
3839

3940

4041
# copy one file to dest
41-
def copyFile(src, dest):
42+
def copyFile(src: Path, dest: Path):
4243
try:
4344
if src.is_file():
4445
shutil.copy(str(src), str(dest))
4546
except OSError as e:
4647
print(f"Error: File {src} not copied. {e}")
4748

4849

49-
def genSTM32List(path, pattern):
50+
# get list of STM32 series from HAL driver directory
51+
def genSTM32List(path: Path, pattern: str = None):
5052
stm32_list = [] # series
5153
dir_pattern = re.compile(r"^STM32(.*)xx_HAL_Driver$", re.IGNORECASE)
5254

@@ -63,7 +65,7 @@ def genSTM32List(path, pattern):
6365
return stm32_list
6466

6567

66-
def execute_cmd(cmd, stderror):
68+
def execute_cmd(cmd: list, stderror: int):
6769
try:
6870
output = subprocess.check_output(cmd, stderr=stderror).decode("utf-8").strip()
6971
except subprocess.CalledProcessError as e:
@@ -72,7 +74,7 @@ def execute_cmd(cmd, stderror):
7274
return output
7375

7476

75-
def getRepoBranchName(repo_path):
77+
def getRepoBranchName(repo_path: Path):
7678
bname = ""
7779
rname = ""
7880
cmd = ["git", "-C", repo_path, "branch", "-r"]

0 commit comments

Comments
 (0)