Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit55e4695

Browse files
committed
ci: harden python scripts
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent06547a2 commit55e4695

File tree

5 files changed

+122
-132
lines changed

5 files changed

+122
-132
lines changed

‎CI/update/fqbn.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def get_fqbn_list():
6666
forfqbninfqbn_list_tmp:
6767
try:
6868
output=subprocess.check_output(
69-
[arduino_cli,"board","details","--format","json",fqbn],
69+
[arduino_cli,"board","details","--format","json","-b",fqbn],
7070
stderr=subprocess.DEVNULL,
7171
).decode("utf-8")
7272
board_detail=json.loads(output)
@@ -106,8 +106,7 @@ def main():
106106
arg_board_pattern=re.compile(args.board,re.IGNORECASE)
107107

108108
forfqbninfqbn_list:
109-
ifargs.board:
110-
ifarg_board_pattern.search(fqbn)isNone:
109+
ifargs.boardandarg_board_pattern.search(fqbn)isNone:
111110
continue
112111
print(fqbn)
113112

‎CI/update/stm32cube.py‎

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,8 @@ def checkConfig():
9696
config_file_path=script_path/"update_config.json"
9797
ifconfig_file_path.is_file():
9898
try:
99-
config_file=open(config_file_path,"r")
100-
path_config=json.load(config_file)
101-
config_file.close()
99+
withopen(config_file_path,"r")asconfig_file:
100+
path_config=json.load(config_file)
102101
# Common path
103102
if"REPO_LOCAL_PATH"notinpath_config:
104103
path_config["REPO_LOCAL_PATH"]=str(repo_local_path)
@@ -201,9 +200,8 @@ def createSystemFiles(serie):
201200
stm32_hal_conf_file=system_serie/stm32yyxx_hal_conf_file.replace(
202201
"yy",serie.lower()
203202
)
204-
out_file=open(stm32_hal_conf_file,"w",newline="\n")
205-
out_file.write(stm32yyxx_hal_conf_file_template.render(serie=serie))
206-
out_file.close()
203+
withopen(stm32_hal_conf_file,"w",newline="\n")asout_file:
204+
out_file.write(stm32yyxx_hal_conf_file_template.render(serie=serie))
207205
# Copy system_stm32*.c file from CMSIS device template
208206
system_stm32_path=cmsis_dest_path/f"STM32{serie}xx"/"Source"/"Templates"
209207
filelist=sorted(system_stm32_path.glob("system_stm32*.c"))
@@ -365,36 +363,36 @@ def parseVersion(path, patterns):
365363
sub1_found=False
366364
sub2_found=False
367365
rc_found=False
368-
369-
fori,lineinenumerate(open(path,encoding="utf8",errors="ignore")):
370-
formatchinre.finditer(patterns[0],line):
371-
VERSION_MAIN=int(match.group(1),16)
372-
main_found=True
373-
formatchinre.finditer(patterns[1],line):
374-
VERSION_SUB1=int(match.group(1),16)
375-
sub1_found=True
376-
formatchinre.finditer(patterns[2],line):
377-
VERSION_SUB2=int(match.group(1),16)
378-
sub2_found=True
379-
formatchinre.finditer(patterns[3],line):
380-
VERSION_RC=int(match.group(1),16)
381-
rc_found=True
382-
ifmain_foundandsub1_foundandsub2_foundandrc_found:
383-
break
384-
else:
385-
print(f"Could not find the full version in{path}")
386-
ifmain_found:
387-
print(f"main version found:{VERSION_MAIN}")
388-
VERSION_MAIN="FF"
389-
ifsub1_found:
390-
print(f"sub1 version found:{VERSION_SUB1}")
391-
VERSION_SUB1="FF"
392-
ifsub2_found:
393-
print(f"sub2 version found:{VERSION_SUB2}")
394-
VERSION_SUB2="FF"
395-
ifrc_found:
396-
print(f"rc version found:{VERSION_RC}")
397-
VERSION_RC="FF"
366+
withopen(path,encoding="utf8",errors="ignore")asfp:
367+
for_i,lineinenumerate(fp):
368+
formatchinre.finditer(patterns[0],line):
369+
VERSION_MAIN=int(match.group(1),16)
370+
main_found=True
371+
formatchinre.finditer(patterns[1],line):
372+
VERSION_SUB1=int(match.group(1),16)
373+
sub1_found=True
374+
formatchinre.finditer(patterns[2],line):
375+
VERSION_SUB2=int(match.group(1),16)
376+
sub2_found=True
377+
formatchinre.finditer(patterns[3],line):
378+
VERSION_RC=int(match.group(1),16)
379+
rc_found=True
380+
ifmain_foundandsub1_foundandsub2_foundandrc_found:
381+
break
382+
else:
383+
print(f"Could not find the full version in{path}")
384+
ifmain_found:
385+
print(f"main version found:{VERSION_MAIN}")
386+
VERSION_MAIN="FF"
387+
ifsub1_found:
388+
print(f"sub1 version found:{VERSION_SUB1}")
389+
VERSION_SUB1="FF"
390+
ifsub2_found:
391+
print(f"sub2 version found:{VERSION_SUB2}")
392+
VERSION_SUB2="FF"
393+
ifrc_found:
394+
print(f"rc version found:{VERSION_RC}")
395+
VERSION_RC="FF"
398396

399397
ret=f"{VERSION_MAIN}.{VERSION_SUB1}.{VERSION_SUB2}"
400398

‎CI/update/stm32svd.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ def checkConfig():
2828
config_file_path=script_path/"update_config.json"
2929
ifconfig_file_path.is_file():
3030
try:
31-
config_file=open(config_file_path,"r")
32-
path_config=json.load(config_file)
33-
config_file.close()
31+
withopen(config_file_path,"r")asconfig_file:
32+
path_config=json.load(config_file)
3433

3534
if"STM32CUBECLT_PATH"notinpath_config:
3635
path_config["STM32CUBECLT_PATH"]=str(
@@ -159,8 +158,9 @@ def main():
159158
forserieinstm32_list:
160159
serie_dir=stm32_svd_dir/f"STM32{serie}xx"
161160
ifnotany(serie_dir.glob("*")):
162-
print(f"Folder{serie_dir} is empty.")
161+
print(f"Folder{serie_dir} is empty.")
163162
serie_dir.rmdir()
164163

164+
165165
if__name__=="__main__":
166166
main()

‎CI/update/stm32variant.py‎

Lines changed: 54 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,8 @@ def get_gpio_af_numF1_default(pintofind, iptofind):
382382
# return "AFIO_" + iptofind .split("_")[0] + "_DISABLE"
383383
ip=iptofind.split("_")[0]
384384
afio_default="AFIO_NONE"
385-
ifpintofindindefault_afio_f1:
386-
ifipindefault_afio_f1[pintofind]:
387-
afio_default=default_afio_f1[pintofind][ip]
385+
ifpintofindindefault_afio_f1andipindefault_afio_f1[pintofind]:
386+
afio_default=default_afio_f1[pintofind][ip]
388387
returnafio_default
389388

390389

@@ -559,10 +558,9 @@ def store_xspi(pin, name, signal):
559558

560559
# Store SYS pins
561560
defstore_sys(pin,name,signal):
562-
if"_WKUP"insignal:
563-
ifnotany(pin.replace("_C","")iniforiinsyswkup_list):
564-
signal=signal.replace("PWR","SYS")
565-
syswkup_list.append([pin,name,signal])
561+
if"_WKUP"insignalandnotany(pin.replace("_C","")iniforiinsyswkup_list):
562+
signal=signal.replace("PWR","SYS")
563+
syswkup_list.append([pin,name,signal])
566564

567565

568566
# Store USB pins
@@ -1341,7 +1339,7 @@ def print_pinamevar():
13411339
alt_syswkup_list= []
13421340
foridx,syswkup_listinenumerate(syswkup_pins_list,start=1):
13431341
iflen(syswkup_list)>1:
1344-
foridx2,lstinenumerate(syswkup_list[1:],start=1):
1342+
foridx2,_lstinenumerate(syswkup_list[1:],start=1):
13451343
alt_syswkup_list.append(f"{idx}_{idx2}")
13461344
returnalt_syswkup_list
13471345

@@ -1375,13 +1373,13 @@ def spi_pins_variant():
13751373
forssinspissel_list:
13761374
ss_inst=ss[2].split("_",1)[0]
13771375
ifmosi_inst==ss_inst:
1378-
if"PNUM_NOT_DEFINED"==ss_pin:
1376+
ifss_pin=="PNUM_NOT_DEFINED":
13791377
ss_pin=ss[0].replace("_","",1)
1380-
elif"PNUM_NOT_DEFINED"==ss1_pin:
1378+
elifss1_pin=="PNUM_NOT_DEFINED":
13811379
ss1_pin=ss[0].replace("_","",1)
1382-
elif"PNUM_NOT_DEFINED"==ss2_pin:
1380+
elifss2_pin=="PNUM_NOT_DEFINED":
13831381
ss2_pin=ss[0].replace("_","",1)
1384-
elif"PNUM_NOT_DEFINED"==ss3_pin:
1382+
elifss3_pin=="PNUM_NOT_DEFINED":
13851383
ss3_pin=ss[0].replace("_","",1)
13861384
break
13871385
break
@@ -1449,7 +1447,7 @@ def serial_pins_variant():
14491447
print("No serial instance number found!")
14501448
serialnum="-1"
14511449
else:
1452-
serialtx_pin=serialtx_pin="PNUM_NOT_DEFINED"
1450+
serialtx_pin="PNUM_NOT_DEFINED"
14531451
serialnum="-1"
14541452
print("No serial found!")
14551453
returndict(instance=serialnum,rx=serialrx_pin,tx=serialtx_pin)
@@ -1653,10 +1651,13 @@ def search_product_line(valueline: str, extra: str) -> str:
16531651
else:
16541652
break
16551653
ifpline>=vline:
1656-
ifextraandlen(product_line_list)>idx_pline+1:
1657-
ifproduct_line_list[idx_pline+1]== (product_line+extra):
1658-
# Look for the next product line if contains the extra
1659-
product_line=product_line_list[idx_pline+1]
1654+
if (
1655+
extra
1656+
andlen(product_line_list)>idx_pline+1
1657+
andproduct_line_list[idx_pline+1]== (product_line+extra)
1658+
):
1659+
# Look for the next product line if contains the extra
1660+
product_line=product_line_list[idx_pline+1]
16601661
break
16611662
else:
16621663
# In case of CMSIS device does not exist
@@ -1700,9 +1701,7 @@ def parse_stm32targets():
17001701

17011702

17021703
defsearch_svdfile(mcu_name):
1703-
svd_file=""
1704-
ifmcu_nameinsvd_dict:
1705-
svd_file=svd_dict[mcu_name]
1704+
svd_file=svd_dict.get(mcu_name,"")
17061705
returnsvd_file
17071706

17081707

@@ -2275,7 +2274,7 @@ def merge_dir(out_temp_path, group_mcu_dir, mcu_family, periph_xml, variant_exp)
22752274
# Save board entry
22762275
skip=False
22772276
withopen(dir_name/boards_entry_filename)asfp:
2278-
forindex,lineinenumerate(fp):
2277+
for_index,lineinenumerate(fp):
22792278
# Skip until next empty line (included)
22802279
ifskip:
22812280
ifline=="\n":
@@ -2391,24 +2390,23 @@ def aggregate_dir():
23912390
periph_xml_tmp= []
23922391
variant_exp_tmp= []
23932392
forindex2,fnameinenumerate(mcu_dir1_files_list):
2394-
withopen(fname,"r")asf1:
2395-
withopen(mcu_dir2_files_list[index2],"r")asf2:
2396-
diff=set(f1).symmetric_difference(f2)
2397-
diff.discard("\n")
2398-
ifnotdifforlen(diff)==2:
2399-
ifindex2==0:
2400-
forlineindiff:
2401-
periph_xml_tmp+=periperalpins_regex.findall(
2402-
line
2403-
)
2404-
elifindex2==2:
2405-
forlineindiff:
2406-
variant_exp_tmp+=variant_regex.findall(line)
2407-
continue
2408-
else:
2409-
# Not the same directory compare with the next one
2410-
index+=1
2411-
break
2393+
withopen(fname,"r")asf1,open(
2394+
mcu_dir2_files_list[index2],"r"
2395+
)asf2:
2396+
diff=set(f1).symmetric_difference(f2)
2397+
diff.discard("\n")
2398+
ifnotdifforlen(diff)==2:
2399+
ifindex2==0:
2400+
forlineindiff:
2401+
periph_xml_tmp+=periperalpins_regex.findall(line)
2402+
elifindex2==2:
2403+
forlineindiff:
2404+
variant_exp_tmp+=variant_regex.findall(line)
2405+
continue
2406+
else:
2407+
# Not the same directory compare with the next one
2408+
index+=1
2409+
break
24122410
# All files compared and matched
24132411
else:
24142412
# Concatenate lists without duplicate
@@ -2505,10 +2503,11 @@ def checkConfig():
25052503
default_cubemxdir()
25062504
ifconfig_filename.is_file():
25072505
try:
2508-
config_file=open(config_filename,"r")
2509-
path_config=json.load(config_file)
2510-
config_file.close()
2511-
2506+
# config_file = open(config_filename, "r")
2507+
# path_config = json.load(config_file)
2508+
# config_file.close()
2509+
withopen(config_filename,"r")asconfig_file:
2510+
path_config=json.load(config_file)
25122511
if"REPO_LOCAL_PATH"notinpath_config:
25132512
path_config["REPO_LOCAL_PATH"]=str(repo_local_path)
25142513
defaultConfig(config_filename,path_config)
@@ -2779,21 +2778,21 @@ def manage_repo():
27792778
generic_clock_filepath=out_temp_path/generic_clock_filename
27802779
out_temp_path.mkdir(parents=True,exist_ok=True)
27812780

2782-
# open output file
2783-
periph_c_file=open(periph_c_filepath,"w",newline="\n")
2784-
pinvar_h_file=open(pinvar_h_filepath,"w",newline="\n")
2785-
variant_cpp_file=open(variant_cpp_filepath,"w",newline="\n")
2786-
variant_h_file=open(variant_h_filepath,"w",newline="\n")
2787-
boards_entry_file=open(boards_entry_filepath,"w",newline="\n")
2788-
generic_clock_file=open(generic_clock_filepath,"w",newline="\n")
27892781
parse_pins()
27902782
manage_af_and_alternate()
27912783

2792-
generic_list=print_boards_entry()
2793-
print_general_clock(generic_list)
2794-
print_peripheral()
2795-
alt_syswkup_list=print_pinamevar()
2796-
print_variant(generic_list,alt_syswkup_list)
2784+
withopen(boards_entry_filepath,"w",newline="\n")asboards_entry_file:
2785+
generic_list=print_boards_entry()
2786+
withopen(generic_clock_filepath,"w",newline="\n")asgeneric_clock_file:
2787+
print_general_clock(generic_list)
2788+
withopen(periph_c_filepath,"w",newline="\n")asperiph_c_file:
2789+
print_peripheral()
2790+
withopen(pinvar_h_filepath,"w",newline="\n")aspinvar_h_file:
2791+
alt_syswkup_list=print_pinamevar()
2792+
withopen(variant_cpp_filepath,"w",newline="\n")asvariant_cpp_file,open(
2793+
variant_h_filepath,"w",newline="\n"
2794+
)asvariant_h_file:
2795+
print_variant(generic_list,alt_syswkup_list)
27972796
delalt_syswkup_list[:]
27982797
delgeneric_list[:]
27992798
sum_io=len(io_list)+len(alt_list)+len(dualpad_list)+len(remap_list)
@@ -2810,12 +2809,6 @@ def manage_repo():
28102809

28112810
clean_all_lists()
28122811

2813-
periph_c_file.close()
2814-
pinvar_h_file.close()
2815-
variant_h_file.close()
2816-
variant_cpp_file.close()
2817-
boards_entry_file.close()
2818-
generic_clock_file.close()
28192812
xml_mcu.unlink()
28202813
xml_gpio.unlink()
28212814

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp