-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcreate.py
More file actions
79 lines (61 loc) · 2.85 KB
/
create.py
File metadata and controls
79 lines (61 loc) · 2.85 KB
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
from argparse import ArgumentParser
import shutil
import sys
import os
arg_parser = ArgumentParser(
prog='mostly harmless project creator',
description='Create a new mostly harmless plugin project from a boilerplate project',
)
arg_parser.add_argument('name', help='Name of your plugin')
arg_parser.add_argument('path', help='Destination directory for your plugin')
arg_parser.add_argument('type', choices=['fx', 'instrument'], help='Type of plugin')
arg_parser.add_argument('--gui', help='GUI backend ("web", "raw", or "none")', default='none')
def main():
args = arg_parser.parse_args()
if args.gui not in ['web', 'raw', 'none']:
print('Error: --gui must be "web", "raw", or "none"')
sys.exit(1)
has_gui = 'false' if args.gui == 'none' else 'true'
gui = args.gui if args.gui != 'none' else 'no'
dest_path = args.path
dest_src_path = os.path.join(dest_path, 'source')
if os.path.isdir(dest_path):
print(f'Error: {dest_path} already exists')
sys.exit(1)
try:
os.mkdir(dest_path)
os.mkdir(dest_src_path)
prepro_name = args.name.replace('-', '_').upper()
au_subtype, clap_features = ('aufx', 'audio_effect') if args.type == 'fx' else ('aumu', 'instrument')
boilerplate_source = os.path.join(os.path.dirname(__file__), 'boilerplate')
gui_source = os.path.join(boilerplate_source, f'{gui}_gui')
files = [
os.path.join(boilerplate_source, f) for f in os.listdir(boilerplate_source)
if os.path.isfile(os.path.join(boilerplate_source, f))
]
files.extend([
os.path.join(gui_source, f) for f in os.listdir(gui_source)
if os.path.isfile(os.path.join(gui_source, f))
])
for file in files:
with open(file, 'r') as f:
contents = f.read().replace('$PREPRO_NAME$', prepro_name) \
.replace("$LOWER_PROJECT_NAME$", args.name.lower()) \
.replace("$PROJECT_NAME$", args.name) \
.replace("$HAS_GUI$", has_gui) \
.replace("$AU_SUBTYPE$", au_subtype) \
.replace("$CLAP_FEATURES$", clap_features)
stripped_name = os.path.basename(file)
if stripped_name == 'CMakeLists.txt':
dest_file = os.path.join(dest_path, stripped_name)
else:
stripped_name = f'{args.name.lower()}_{stripped_name}'
dest_file = os.path.join(dest_src_path, stripped_name)
with open(dest_file, 'w+') as f:
f.write(contents)
except Exception as e:
print(e)
if os.path.isdir(dest_path):
shutil.rmtree(dest_path)
if __name__ == '__main__':
main()