forked from CIRCL/AIL-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_new_web_module.py
executable file
·44 lines (31 loc) · 1.41 KB
/
create_new_web_module.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
#!/usr/bin/env python3
# -*-coding:UTF-8 -*
"Hepler to create a new webpage associated with a module."
import os
def createModuleFolder(modulename):
path_module = os.path.join('modules', modulename)
os.mkdir(path_module)
# create html template
with open('templates/base_template.html', 'r') as templateFile:
template = templateFile.read()
template = template.replace('MODULENAME', modulename)
os.mkdir(os.path.join(path_module, 'templates'))
with open(os.path.join(os.path.join(path_module, 'templates'), modulename+'.html'), 'w') as toWriteTemplate:
toWriteTemplate.write(template)
# create html header template
with open('templates/header_base_template.html', 'r') as header_templateFile:
header = header_templateFile.read()
header = header.replace('MODULENAME', modulename)
with open(os.path.join(os.path.join(path_module, 'templates'), 'header_{}.html'.format(modulename) ), 'w') as toWriteHeader:
toWriteHeader.write(header)
#create flask template
with open('Flask_base_template.py', 'r') as flaskFile:
flask = flaskFile.read()
flask = flask.replace('MODULENAME', modulename)
with open(os.path.join(path_module, 'Flask_{}.py'.format(modulename)), 'w') as toWriteFlask:
toWriteFlask.write(flask)
def main():
rep1 = input('New module name: ')
createModuleFolder(rep1)
if __name__ == '__main__':
main()