|
1 | | -import os |
2 | 1 | import re |
3 | 2 | import shutil |
4 | 3 |
|
5 | 4 |
|
6 | 5 | # Create a folder if not exists |
7 | 6 | def createFolder(path): |
8 | 7 | try: |
9 | | - if not os.path.exists(path): |
10 | | - os.makedirs(path) |
| 8 | + if not path.exists(): |
| 9 | + path.mkdir() |
11 | 10 | except OSError: |
12 | 11 | print("Error: Creating directory. " + path) |
13 | 12 |
|
14 | 13 |
|
15 | 14 | # Delete targeted folder recursively |
16 | 15 | def deleteFolder(path): |
17 | | - if os.path.isdir(path): |
| 16 | + if path.is_dir(): |
18 | 17 | shutil.rmtree(path, ignore_errors=True) |
19 | 18 |
|
20 | 19 |
|
21 | 20 | # copy src folder recursively to dest |
22 | 21 | def copyFolder(src, dest, ign_patt=set()): |
23 | 22 | try: |
24 | | - if os.path.isdir(src): |
| 23 | + if src.is_dir(): |
25 | 24 | shutil.copytree(src, dest, ignore=shutil.ignore_patterns(*ign_patt)) |
26 | 25 | except OSError as e: |
27 | 26 | print("Error: Folder %s not copied. %s" % src, e) |
28 | 27 |
|
29 | 28 |
|
30 | 29 | def genSTM32List(path, pattern): |
31 | 30 | 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) |
33 | 32 |
|
34 | 33 | if pattern is not None: |
35 | 34 | serie_pattern = re.compile(pattern, re.IGNORECASE) |
36 | 35 | else: |
37 | 36 | serie_pattern = re.compile(".*", re.IGNORECASE) |
38 | 37 |
|
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) |
41 | 40 | if res and serie_pattern.search(res.group(1)): |
42 | 41 | stm32_list.append(res.group(1)) |
43 | 42 | stm32_list.sort() |
|
0 commit comments