-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.py
74 lines (58 loc) · 2.03 KB
/
generator.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
import os
import shutil
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates'))
BASE_DIR = os.getcwd()
FILES_TO_CREATE = [
{'name': 'plugin_settings.py', 'template': 'plugin_settings.tpl'},
{'name': 'views.py', 'template': 'views.tpl'},
{'name': 'urls.py', 'template': 'urls.tpl'},
{'name': 'models.py', 'template': 'empty.tpl'},
{'name': 'forms.py', 'template': 'forms.tpl'},
{'name': '__init__.py', 'template': 'empty.tpl'},
{'name': 'manager.html', 'template': 'manager.tpl', 'path': 'templates'},
]
def save_file(contents, path_parts, file_name):
path = os.path.join(
BASE_DIR,
*path_parts,
)
file_path = os.path.join(path, file_name)
if not os.path.exists(path):
os.makedirs(path)
with open(file_path, 'w') as f:
f.write(contents)
f.close()
def generate_files(settings):
for file in FILES_TO_CREATE:
template = env.get_template(file.get('template'))
contents = template.render(settings)
path_parts = [settings.get('short_name')]
if file.get('path', '') == 'templates':
path_parts.append('templates')
path_parts.append(settings.get('short_name'))
save_file(
contents,
path_parts,
file.get('name')
)
def nuke_folders():
try:
shutil.rmtree(os.path.join(BASE_DIR, 'test'))
except FileNotFoundError:
pass
author = input('What is your name? ')
description = input('Give me a short description of this plugin: ')
display_name = input('Plugin display name eg. Typesetting. ')
short_name = input('Short name of the plugin eg. typesetting. ')
workflow_plugin = input('Is this plugin a Workflow Element? y/n: ')
is_workflow_plugin = True if workflow_plugin == 'y' else False
settings = {
'author': author,
'description': description,
'short_name': short_name,
'display_name': display_name,
'is_workflow_plugin': is_workflow_plugin
}
nuke_folders()
generate_files(settings)