forked from analogdevicesinc/ai8x-synthesis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassets.py
63 lines (58 loc) · 1.98 KB
/
assets.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
###################################################################################################
# Copyright (C) Maxim Integrated Products, Inc. All Rights Reserved.
#
# Maxim Integrated Products, Inc. Default Copyright Notice:
# https://www.maximintegrated.com/en/aboutus/legal/copyrights.html
#
###################################################################################################
"""
Copy assets
"""
import os
import shutil
import tornadocnn as tc
def copy(
base,
source,
target,
test_name,
):
"""
Copy all files from `base`/`source` to `target`/`test_name`.
"""
dst = os.path.join(target, test_name)
for _, _, files in sorted(os.walk(os.path.join(base, source))):
for name in sorted(files):
shutil.copy(os.path.join(base, source, name), dst)
def eclipse_template(
base,
source,
target,
test_name,
riscv=False,
):
"""
Copy all files `base`/`source` to `target`/`test_name`, with file name and
content substitution.
"""
template = 'template'
if riscv:
elf_file = f'{tc.dev.part_no.lower()}-combined.elf'
else:
elf_file = f'{tc.dev.part_no.lower()}.elf'
for _, _, files in sorted(os.walk(os.path.join(base, source))):
for name in sorted(files):
if name.startswith(template):
dst = os.path.join(
target,
test_name,
name[len(template):].replace('##__PROJ_NAME__##', test_name),
)
with open(os.path.join(base, source, name)) as infile, open(dst, 'w+') as outfile:
for line in infile:
outfile.write(
line.replace('##__PROJ_NAME__##', test_name).
replace('##__ELF_FILE__##', elf_file)
)
else:
shutil.copy(os.path.join(base, source, name), os.path.join(target, test_name))