forked from stm32duino/Arduino_Core_STM32
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstm32common.py
More file actions
43 lines (33 loc) · 1.12 KB
/
stm32common.py
File metadata and controls
43 lines (33 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import re
import shutil
# Create a folder if not exists
def createFolder(path):
try:
if not path.exists():
path.mkdir()
except OSError:
print("Error: Creating directory. " + path)
# Delete targeted folder recursively
def deleteFolder(path):
if path.is_dir():
shutil.rmtree(path, ignore_errors=True)
# copy src folder recursively to dest
def copyFolder(src, dest, ign_patt=set()):
try:
if src.is_dir():
shutil.copytree(src, dest, ignore=shutil.ignore_patterns(*ign_patt))
except OSError as e:
print("Error: Folder %s not copied. %s" % src, e)
def genSTM32List(path, pattern):
stm32_list = [] # Serie
dir_pattern = re.compile(r"^STM32(.*)xx_HAL_Driver$", re.IGNORECASE)
if pattern is not None:
serie_pattern = re.compile(pattern, re.IGNORECASE)
else:
serie_pattern = re.compile(".*", re.IGNORECASE)
for file in path.iterdir():
res = dir_pattern.match(file.name)
if res and serie_pattern.search(res.group(1)):
stm32_list.append(res.group(1))
stm32_list.sort()
return stm32_list