forked from entrepreneur-interet-general/CIS-front
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun_apiviz.py
79 lines (55 loc) · 2.11 KB
/
run_apiviz.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
75
76
77
78
79
# -*- encoding: utf-8 -*-
import os
import click
### set environment variable
# os.environ['FLASK_CONFIGURATION'] = "default" # "testing" / "production"
### change environment var to "production" for debugging
# os.environ['FLASK_CONFIGURATION'] = "production"
# from app import app
debug = True
@click.command()
@click.option('--mode', default="default", nargs=1, help="The <mode> you need to run the app : default, testing, preprod, production" )
@click.option('--host', default="localhost", nargs=1, help="The <host> name you want the app to run on : <IP_NUMBER> " )
@click.option('--port', default="8100", nargs=1, help="The <port> number you want the app to run on : <PORT_NUMBER>")
@click.option('--https', default="false", nargs=1, help="The <https> mode you want the app to run on : true | false")
def app_runner(mode, host, port, https) :
"""
app_runner
"""
print "= "*50
print "= = = RERUN FLASK APP FROM APP RUNNER = = ="
print "= "*50
### WARNING : CLIck will treat every input as string as defaults values are string too
print "\n=== CUSTOM CONFIG FROM CLI ===\n"
print "=== mode : ", mode
print "=== host : ", host
print "=== port : ", port
print "=== https : ", https
if https == "true" :
http_mode = "https"
else :
http_mode = "http"
### apply / overwrites host configuration
if mode != "default" :
print "=== mode : ", mode
os.environ["FLASK_CONFIGURATION"] = str(mode)
config_name = os.getenv('FLASK_CONFIGURATION', 'default') ### 'default' for local dev
print "=== config_name : ", config_name
### SET UP ENV VARS FROM CLI
os.environ["DOMAIN_ROOT"] = host
os.environ["DOMAIN_PORT"] = port
os.environ["SERVER_NAME"] = host + ":" + port
os.environ["DOMAIN_NAME"] = http_mode + "://" + host + ":" + port
### create app by importing app.__init__
from app import app
### simple flask runner
app.run( debug=debug, host=host, port=port, threaded=True )
if __name__ == '__main__':
"""
runner for the CIS front Flask app
- gets most of its variables at start from environment variables
-
in command line just type :
"python run_apiviz.py"
"""
app_runner()