Skip to content

Commit e032631

Browse files
committed
scripts: move to Pathlib
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 70bd40f commit e032631

File tree

3 files changed

+186
-230
lines changed

3 files changed

+186
-230
lines changed

CI/utils/stm32common.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,42 @@
1-
import os
21
import re
32
import shutil
43

54

65
# Create a folder if not exists
76
def createFolder(path):
87
try:
9-
if not os.path.exists(path):
10-
os.makedirs(path)
8+
if not path.exists():
9+
path.mkdir()
1110
except OSError:
1211
print("Error: Creating directory. " + path)
1312

1413

1514
# Delete targeted folder recursively
1615
def deleteFolder(path):
17-
if os.path.isdir(path):
16+
if path.is_dir():
1817
shutil.rmtree(path, ignore_errors=True)
1918

2019

2120
# copy src folder recursively to dest
2221
def copyFolder(src, dest, ign_patt=set()):
2322
try:
24-
if os.path.isdir(src):
23+
if src.is_dir():
2524
shutil.copytree(src, dest, ignore=shutil.ignore_patterns(*ign_patt))
2625
except OSError as e:
2726
print("Error: Folder %s not copied. %s" % src, e)
2827

2928

3029
def genSTM32List(path, pattern):
3130
stm32_list = [] # Serie
32-
dir_pattern = re.compile("^STM32(.*)xx_HAL_Driver$", re.IGNORECASE)
31+
dir_pattern = re.compile(r"^STM32(.*)xx_HAL_Driver$", re.IGNORECASE)
3332

3433
if pattern is not None:
3534
serie_pattern = re.compile(pattern, re.IGNORECASE)
3635
else:
3736
serie_pattern = re.compile(".*", re.IGNORECASE)
3837

39-
for file in os.listdir(path):
40-
res = dir_pattern.match(file)
38+
for file in path.iterdir():
39+
res = dir_pattern.match(file.name)
4140
if res and serie_pattern.search(res.group(1)):
4241
stm32_list.append(res.group(1))
4342
stm32_list.sort()

0 commit comments

Comments
 (0)