-
Notifications
You must be signed in to change notification settings - Fork 11
/
manage.py
49 lines (42 loc) · 1.41 KB
/
manage.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
import os
from urllib.parse import urlparse
import initdatabase
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
try:
import config
except ImportError:
print('It seems like this is the first time running the server.')
print('First let us generate a proper configuration file.')
try:
from generateconfig import generate_config
generate_config()
import config
print('Initializing database "%s".' % config.SQLALCHEMY_DATABASE_URI)
initdatabase.init_database()
except Exception as e:
print(e)
print('An error ocurred. Please fix the errors and try again.')
print('Deleting "config.py" file.')
try:
os.remove('config.py')
os.remove('config.pyc')
finally:
raise SystemExit('Exiting now.')
from mhn import mhn, db
if __name__ == '__main__':
migrate = Migrate(mhn, db)
manager = Manager(mhn)
manager.add_command('db', MigrateCommand)
@manager.command
def run():
# Takes run parameters from configuration.
serverurl = urlparse(config.SERVER_BASE_URL)
mhn.run(debug=config.DEBUG, host='0.0.0.0',
port=serverurl.port)
@manager.command
def runlocal():
serverurl = urlparse(config.SERVER_BASE_URL)
mhn.run(debug=config.DEBUG, host='0.0.0.0',
port=serverurl.port)
manager.run()