-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.py
executable file
·55 lines (44 loc) · 1.35 KB
/
install.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
#!/usr/bin/python
# -*- coding: utf -*-
import random, os
# config settings to save
cfg = {
'FLASK_PORT' : 5000,
'DEBUG' : False,
'SECRET_KEY' : '',
'ALLOWED_IP' : ['127.0', '192.168', '131.111.60'],
'MAIL_SERVER' : '',
'MAIL_PORT' : 25,
'MAIL_USE_TLS' : False,
'MAIL_RECIPIENTS' : ['[email protected]']
}
# flask app port
while True:
input_port = raw_input('Flask app port (default 5000) ')
if not input_port:
cfg['FLASK_PORT'] = 5000
break
if input_port:
cfg['FLASK_PORT'] = int(input_port.strip()) # Better to use Regex to contraint this
break
cfg['SECRET_KEY'] = ''.join([random.choice('./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') for i in range(30)])
# write config.py
python_code = []
for key, value in cfg.items():
if isinstance(value, str):
value = "'" + value.replace("'", r"\'") + "'"
python_code.append("%s = %s" % (key, value))
with open(os.getcwd() + '/config.py', 'w') as f:
f.write('\n'.join(python_code))
# write cherrypy.conf
conf =\
'''
[global]
server.socket_host = '0.0.0.0'
server.socket_port = %i
server.environment = "production"
tree.mount = {'/' : create_flask_app.application}
''' % cfg['FLASK_PORT']
with open(os.getcwd() + '/cherrypy.conf', 'w') as f:
f.write(conf)
print('\nConfiguration files written successfully.\n')