-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.py
65 lines (55 loc) · 2.39 KB
/
generate.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
#!/usr/bin/env python
import os, sys, argparse, subprocess
from distutils.dir_util import copy_tree
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description="Creates a new TRextern project")
parser.add_argument(
"name",
help = "Name of the TRextern project. Projects with '~' in the name will be created as DSP objects")
parser.add_argument(
"-o", "--out",
default=os.getcwd(),
help = "Output folder")
# parser.add_argument(
# "-c", "--copyfiles",
# type=int,
# default=0,
# help = "Optional copy of dependencies to project directory")
try:
options = parser.parse_args()
scriptDir = os.path.realpath(__file__ + "/..")
print scriptDir
# Check if dependencies are downloaded and fetch if missing
dependencyDir = os.path.join(scriptDir, "dependencies")
if not os.path.exists(os.path.join(dependencyDir, "m_pd.h")) \
or not os.path.exists(os.path.join(dependencyDir, "max-sdk-7.3.3")):
print "Downloading dependencies"
setupPath = os.path.join(scriptDir, "setup.sh")
subprocess.call("sh " + setupPath, shell=True)
if os.path.exists(options.out):
shutil.rmtree(options.out)
print "Creating Project " + options.name + " at path: " + options.out
copy_tree(os.path.join(scriptDir,"templates"), options.out)
# Replace __template__ with 'name' in file contents
filesToRename = []
for dname, dirs, files in os.walk(options.out):
for fname in files:
fpath = os.path.join(dname, fname)
with open(fpath) as f:
s = f.read()
s = s.replace("__template__", options.name)
s = s.replace("{TREXTERN_PATH}", scriptDir)
with open(fpath, "w") as f:
f.write(s)
# Add files we need to rename
if '__template__' in fname:
filesToRename.append(fpath)
if '__template__' in dname:
filesToRename.append(dname)
# Rename files with '__template__' in name
for filepath in filesToRename:
newpath = filepath.replace("__template__", options.name)
os.rename(filepath, newpath)
except:
sys.exit(0)