2018-06-30 19:59:10 +00:00
|
|
|
'''
|
|
|
|
This file is the gevent launcher for local / development use.
|
|
|
|
|
|
|
|
Simply run it on the command line:
|
|
|
|
python etiquette_flask_launch.py [port]
|
|
|
|
'''
|
2018-04-16 03:34:03 +00:00
|
|
|
import gevent.monkey; gevent.monkey.patch_all()
|
2016-09-18 08:33:46 +00:00
|
|
|
|
2017-11-26 10:37:11 +00:00
|
|
|
import logging
|
|
|
|
handler = logging.StreamHandler()
|
|
|
|
log_format = '{levelname}:etiquette.{module}.{funcName}: {message}'
|
|
|
|
handler.setFormatter(logging.Formatter(log_format, style='{'))
|
|
|
|
logging.getLogger().addHandler(handler)
|
|
|
|
|
2018-04-16 03:34:03 +00:00
|
|
|
import argparse
|
2018-11-05 03:27:20 +00:00
|
|
|
import gevent.pywsgi
|
2016-09-18 08:33:46 +00:00
|
|
|
import sys
|
|
|
|
|
2018-04-16 03:34:03 +00:00
|
|
|
import etiquette_flask_entrypoint
|
2018-01-18 04:53:25 +00:00
|
|
|
|
2018-04-16 03:34:03 +00:00
|
|
|
site = etiquette_flask_entrypoint.site
|
2018-01-18 04:53:25 +00:00
|
|
|
|
2018-04-16 03:34:03 +00:00
|
|
|
def run(port=None, use_https=None):
|
|
|
|
if port is None:
|
|
|
|
port = 5000
|
|
|
|
else:
|
|
|
|
port = int(port)
|
2018-01-18 04:53:25 +00:00
|
|
|
|
2018-04-16 03:34:03 +00:00
|
|
|
if use_https is None:
|
|
|
|
use_https = port == 443
|
2016-09-18 08:33:46 +00:00
|
|
|
|
2018-04-16 03:34:03 +00:00
|
|
|
if use_https:
|
|
|
|
http = gevent.pywsgi.WSGIServer(
|
|
|
|
listener=('0.0.0.0', port),
|
|
|
|
application=site,
|
|
|
|
keyfile='D:\\git\\etiquette\\frontends\\etiquette_flask\\https\\etiquette.key',
|
|
|
|
certfile='D:\\git\\etiquette\\frontends\\etiquette_flask\\https\\etiquette.crt',
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
http = gevent.pywsgi.WSGIServer(
|
|
|
|
listener=('0.0.0.0', port),
|
|
|
|
application=site,
|
|
|
|
)
|
2016-11-27 09:06:11 +00:00
|
|
|
|
2018-04-16 03:34:03 +00:00
|
|
|
message = f'Starting server on port {port}'
|
|
|
|
if use_https:
|
|
|
|
message += ' (https)'
|
|
|
|
print(message)
|
|
|
|
try:
|
|
|
|
http.serve_forever()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|
|
|
|
return 0
|
2016-09-18 08:33:46 +00:00
|
|
|
|
2018-04-16 03:34:03 +00:00
|
|
|
def run_argparse(args):
|
|
|
|
return run(port=args.port, use_https=args.use_https)
|
|
|
|
|
|
|
|
def main(argv):
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
|
|
|
|
parser.add_argument(dest='port', nargs='?', default=None)
|
|
|
|
parser.add_argument('--https', dest='use_https', action='store_true', default=None)
|
|
|
|
parser.set_defaults(func=run_argparse)
|
|
|
|
|
|
|
|
args = parser.parse_args(argv)
|
2020-02-09 01:24:57 +00:00
|
|
|
return args.func(args)
|
2018-04-16 03:34:03 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
raise SystemExit(main(sys.argv[1:]))
|