-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.py
96 lines (72 loc) · 2.78 KB
/
build.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/env python3
'''Create a new project from this template. Requires two arguments:
- project name
- audio unit subtype
'''
import os
import os.path
import shutil
import subprocess
import sys
def substituteName(content, name, subtype):
return content.replace('--NAME--', name).replace('--SUBTYPE--', subtype)
def makeDestPath(sourcePath, destDir, name, subtype):
return substituteName(os.path.join(destDir, sourcePath), name, subtype)
def buildFile(sourcePath, destPath, name, subtype):
justCopy = ['.py', '.png', '.caf', '.wav', '.xcuserstate', '.opacity',
'.ttf']
os.makedirs(os.path.split(destPath)[0], exist_ok=True)
if os.path.splitext(destPath)[1] in justCopy:
shutil.copy2(sourcePath, destPath)
else:
open(destPath, 'w').write(substituteName(open(sourcePath, 'r').read(),
name, subtype))
def runCommand(step, *args):
print('--', step)
process = subprocess.run(args, stdout=subprocess.PIPE, universal_newlines=True)
if process.returncode != 0:
print(process.stdout)
print(process.stderr)
sys.exit(1)
def createRepo(destDir):
os.chdir(destDir)
runCommand('creating repo', 'git', 'init')
runCommand('stagiing files', 'git', 'add', '-A')
runCommand('committing to repo', 'git', 'commit', '-m',
'Yeah! Initial commit')
def build(name, subtype):
destDir = os.path.join('..', name)
if os.path.exists(destDir):
print('** destination', destDir, 'exists')
sys.exit(1)
for dirname, dirnames, filenames in os.walk('.'):
for each in list(filter(lambda a: a[0] == '.' or a == 'xuserdata', dirnames)):
dirnames.remove(each)
for filename in filenames:
if filename == '.DS_Store':
continue
sourcePath = os.path.join(dirname, filename)[2:]
print('--', sourcePath)
buildFile(sourcePath,
makeDestPath(sourcePath, destDir, name, subtype),
name,
subtype)
createRepo(destDir)
runCommand('opening project', 'open',
os.path.join(destDir, name + '.xcodeproj'))
if __name__ == '__main__':
if len(sys.argv) != 3:
print("usage: python build.py NAME SUBTYPE")
print("where: ")
print(" NAME is the name of the new AUv3 component")
print(" SUBTYPE is the unique AUv3 4-character subtype for the new component")
sys.exit(1)
name = sys.argv[1]
if not name:
print("*** invalid/missing name")
sys.exit(1)
subType = sys.argv[2]
if not subType or len(subType) != 4:
print("*** invalid/missing subType -- must be exactly 4 characters")
sys.exit(1)
build(name, subType)