forked from matteoferla/MichelaNGLo-app
/
app.py
51 lines (42 loc) · 1.99 KB
/
app.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
from waitress import serve
from pyramid.paster import get_app, setup_logging
import os, argparse
# ======================================================================================================================
# check and fill missing environment variables.
# ones with None are optional.
environmental = dict(PROTEIN_DATA='../protein-data',
SECRETCODE='ERROR',
SQL_URL='sqlite:///demo.db',
MICHELANGLO_URL='localhost:8088',
VENUS_URL='localhost:8088/venus',
SENTRY_DNS_MICHELANGLO=None,
PUPPETEER_CHROME=None, # will crash puppetter
SLACK_WEBHOOK=None,
ADMIN_EMAIL=None,
SERVER_EMAIL=None,
)
for ev in environmental:
if ev in os.environ:
print(f'Environment variable {ev}: present')
elif environmental[ev] is None:
print(f'Environment variable {ev}: skipping')
else:
print(f'Environment variable {ev}: defaulting to {environmental[ev]}')
os.environ[ev] = environmental[ev]
# ======================================================================================================================
# custom `app.py` due to os.environs...
parser = argparse.ArgumentParser()
parser.add_argument('--d', action='store_true', help='run in dev mode')
if parser.parse_args().d:
print('*'*10)
print('RUNNING IN DEV MODE')
print('*' * 10)
configfile = 'development.ini'
else:
configfile = 'production.ini'
# ======================================================================================================================
setup_logging(configfile)
app = get_app(configfile, 'main', options={'SQL_URL': os.environ['SQL_URL']}) #pyramid.router.Router
# ======================================================================================================================
if __name__ == '__main__':
serve(app, host='0.0.0.0', port=8088, threads=50)