-
Notifications
You must be signed in to change notification settings - Fork 7
/
prepare_work.py
66 lines (51 loc) · 1.88 KB
/
prepare_work.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
# coding=utf-8
'''
@ Summary: prepare
1. create two dirs:
<cwd>/Middlewares
<cwd>/X-CUBE-AI
2. load 'SConscript' files
@ Update:
@ file: prepare_work.py
@ version: 1.0.0
@ Author: [email protected]
@ Date: 2020/12/2 17:06
@ Update: remove stm_out dir first
@ Date: 2021/02/22 17:06
'''
import shutil
import logging
from pathlib import Path
def pre_sconscript(stm_out, sconscripts, stm32_dirs):
""" prepared works:
1. create two folders: Middlewares
2. load Sconscripts to 'Middlewares' & 'X-CUBE-AI'
Args:
stm_out: x-cube-ai:stm32ai output file, str
sconscripts: sconscripts files saved, str, default is "platforms/stm32/Sconscripts"
stm32_dirs: ["Middlewares", "X-CUBE-AI"], list
Raises:
{"Middlewares", "X-CUBE-AI"}/SConscript not exists
"""
stm_out, sconscripts = Path(stm_out), Path(sconscripts)
# delete the dir first
if stm_out.exists(): shutil.rmtree(stm_out)
for i, dir in enumerate(stm32_dirs):
# step 1: create two dirs ("Middlewares", "X-CUBE-AI")
new_dir = stm_out / dir / ("ST/AI/Lib" if i == 0 else "App")
new_dir.mkdir(parents=True, exist_ok=True)
# step 2: load sconscript file to <stm_out>
source_scons = sconscripts / dir
target_scons = stm_out / dir / "SConscript"
if not source_scons.exists():
raise FileNotFoundError(f"Not {source_scons} file found!!!")
shutil.copy(source_scons, target_scons)
logging.info(f"Create two dirs: {' '.join(stm32_dirs)} successfully...")
if __name__ == "__main__":
logging.getLogger().setLevel(logging.INFO)
stm_out = 'tmp_cwd'
scons_path = "./Sconscripts"
stm32_dirs = ["Middlewares", "X-CUBE-AI"]
# 2. prepare tmp output
_ = pre_sconscript(stm_out, scons_path, stm32_dirs)
print("u a right...")