-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrate.py
71 lines (58 loc) · 1.92 KB
/
migrate.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
import shutil
# Migrate all folders except Core and DRIVERS
directories = [d for d in os.listdir('.') if os.path.isdir(d) and not d.startswith('.')]
if "Core" in directories:
directories.remove("Core")
if "Drivers" in directories:
directories.remove("Drivers")
print("Directories to merge:", ", ".join(directories))
# Copy all directories to both Core/Inc and Core/Src
for d in directories:
Inc = os.path.join("Core", "Inc", d)
Src = os.path.join("Core", "Src", d)
shutil.rmtree(Inc, ignore_errors=True)
shutil.rmtree(Src, ignore_errors=True)
shutil.copytree(d, Inc)
shutil.copytree(d, Src)
# Remove all not .h files from Core/Inc
for _dir, _subdirs, _files in os.walk("./Core/Inc"):
for file in _files:
if not file.endswith(".h"):
os.remove(os.path.join(_dir, file))
# Remove all not .c files from Core/Src ss
for _dir, _subdirs, _files in os.walk("./Core/Src"):
for file in _files:
if not file.endswith(".c"):
os.remove(os.path.join(_dir, file))
# Remove all empty directories
for _dir, _subdirs, _files in os.walk("./Core"):
if len(_subdirs) + len(_files) == 0:
os.rmdir(_dir)
# Find all directories with header files
includes_dirs = []
for _dir, _subdirs, _files in os.walk("./Core/Inc"):
if 0 < len(_files):
includes_dirs.append(_dir)
### Generate platformio file
with open("platformio.ini", "w") as file:
file.write("""\
[platformio]
include_dir = Core/Inc
src_dir = Core/Src
[env:nucleo_f767zi]
platform = ststm32
board = nucleo_f767zi
framework = stm32cube
build_flags =
""")
for d in includes_dirs:
file.write("\t-I %s\n" % d)
# Git checkout all USB files
print("Warning : resetting all changes made to USB files in ./Core/(Inc|Src)/USB_DEVICE/")
os.popen('git checkout ./Core/Inc/USB_DEVICE/')
os.popen('git checkout ./Core/Src/USB_DEVICE/')
# files = []
# for _dir, _subdirs, _files in os.walk("./Core/Src"):
# files += [os.path.join(_dir, f) for f in _files if not f.endswith(".c")]
# print(files)