Skip to content

Commit f0b387a

Browse files
committed
ci: move common functions to common_ext library
Signed-off-by: Frederic Pillon <[email protected]>
1 parent bf6f3d7 commit f0b387a

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

CI/update/stm32cube.py

+1-26
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
script_path = Path(__file__).parent.resolve()
1616
sys.path.append(str(script_path.parent))
1717
from utils import copyFile, copyFolder, createFolder, deleteFolder, genSTM32List
18+
from utils import execute_cmd, getRepoBranchName
1819

1920
if sys.platform.startswith("win32"):
2021
from colorama import init
@@ -74,16 +75,6 @@
7475
out_separator = "-" * 70
7576

7677

77-
def execute_cmd(cmd, stderror):
78-
try:
79-
output = subprocess.check_output(cmd, stderr=stderror).decode("utf-8").strip()
80-
except subprocess.CalledProcessError as e:
81-
print("Failed command: ")
82-
print(e.cmd)
83-
exit(e.returncode)
84-
return output
85-
86-
8778
def create_config(config_file_path):
8879
global repo_local_path
8980

@@ -238,22 +229,6 @@ def createSystemFiles(serie):
238229
copyFile(hal_conf_file, hal_conf_default)
239230

240231

241-
def getRepoBranchName(repo_path):
242-
bname = ""
243-
rname = ""
244-
cmd = ["git", "-C", repo_path, "branch", "-r"]
245-
bnames = execute_cmd(cmd, None).split("\n")
246-
for b in bnames:
247-
name_match = re.match(r"\S+/\S+ -> (\S+)/(\S+)", b.strip())
248-
if name_match:
249-
rname = name_match.group(1)
250-
bname = name_match.group(2)
251-
if not bname:
252-
print(f"Could not find branch name for {repo_path}!")
253-
exit(1)
254-
return (rname, bname)
255-
256-
257232
def updateCoreRepo():
258233
# Handle core repo
259234
repo_path = repo_local_path / repo_core_name

CI/utils/common_ext.py

+26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
import subprocess
23
import shutil
34
import sys
45

@@ -52,6 +53,31 @@ def genSTM32List(path, pattern):
5253
return stm32_list
5354

5455

56+
def execute_cmd(cmd, stderror):
57+
try:
58+
output = subprocess.check_output(cmd, stderr=stderror).decode("utf-8").strip()
59+
except subprocess.CalledProcessError as e:
60+
print(f"Command {e.cmd} failed with error code {e.returncode}")
61+
exit(e.returncode)
62+
return output
63+
64+
65+
def getRepoBranchName(repo_path):
66+
bname = ""
67+
rname = ""
68+
cmd = ["git", "-C", repo_path, "branch", "-r"]
69+
bnames = execute_cmd(cmd, None).split("\n")
70+
for b in bnames:
71+
name_match = re.match(r"\S+/\S+ -> (\S+)/(\S+)", b.strip())
72+
if name_match:
73+
rname = name_match.group(1)
74+
bname = name_match.group(2)
75+
if not bname:
76+
print(f"Could not find branch name for {repo_path}!")
77+
exit(1)
78+
return (rname, bname)
79+
80+
5581
if __name__ == "__main__":
5682
print("This script is not intend to be called directly")
5783
sys.exit()

0 commit comments

Comments
 (0)