2017-10-09 04:39:07 +00:00
|
|
|
import logging
|
2020-08-12 18:17:10 +00:00
|
|
|
logging.basicConfig()
|
2020-08-12 18:25:59 +00:00
|
|
|
logging.getLogger('ycdl').setLevel(logging.DEBUG)
|
2017-10-09 04:39:07 +00:00
|
|
|
|
2016-11-29 04:16:16 +00:00
|
|
|
import gevent.monkey
|
|
|
|
gevent.monkey.patch_all()
|
|
|
|
|
2020-03-28 23:44:47 +00:00
|
|
|
import argparse
|
2016-11-29 04:16:16 +00:00
|
|
|
import gevent.pywsgi
|
|
|
|
import sys
|
2016-12-07 06:11:09 +00:00
|
|
|
|
2020-03-28 23:47:37 +00:00
|
|
|
import backend
|
2016-11-29 04:16:16 +00:00
|
|
|
|
2020-03-28 23:44:47 +00:00
|
|
|
def ycdl_flask_launch(port, refresh_rate):
|
|
|
|
if port == 443:
|
|
|
|
http = gevent.pywsgi.WSGIServer(
|
|
|
|
listener=('', port),
|
2020-03-28 23:47:37 +00:00
|
|
|
application=backend.site,
|
2020-03-28 23:44:47 +00:00
|
|
|
keyfile='https\\flasksite.key',
|
|
|
|
certfile='https\\flasksite.crt',
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
http = gevent.pywsgi.WSGIServer(
|
|
|
|
listener=('0.0.0.0', port),
|
2020-03-28 23:47:37 +00:00
|
|
|
application=backend.site,
|
2020-03-28 23:44:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if refresh_rate is not None:
|
2020-03-28 23:56:06 +00:00
|
|
|
backend.common.start_refresher_thread(refresh_rate)
|
2020-03-28 23:44:47 +00:00
|
|
|
|
|
|
|
print(f'Starting server on port {port}')
|
|
|
|
http.serve_forever()
|
|
|
|
|
|
|
|
def ycdl_flask_launch_argparse(args):
|
|
|
|
if args.do_refresh:
|
|
|
|
refresh_rate = args.refresh_rate
|
|
|
|
else:
|
|
|
|
refresh_rate = None
|
|
|
|
|
|
|
|
return ycdl_flask_launch(
|
|
|
|
port=args.port,
|
|
|
|
refresh_rate=refresh_rate,
|
2016-11-29 04:16:16 +00:00
|
|
|
)
|
|
|
|
|
2020-03-28 23:44:47 +00:00
|
|
|
def main(argv):
|
|
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
|
|
|
|
|
|
parser.add_argument('port', nargs='?', type=int, default=5000)
|
2020-08-09 01:58:39 +00:00
|
|
|
parser.add_argument('--no_refresh', '--no-refresh', dest='do_refresh', action='store_false', default=True)
|
|
|
|
parser.add_argument('--refresh_rate', '--refresh-rate', dest='refresh_rate', type=int, default=60 * 60 * 6)
|
2020-03-28 23:44:47 +00:00
|
|
|
parser.set_defaults(func=ycdl_flask_launch_argparse)
|
|
|
|
|
|
|
|
args = parser.parse_args(argv)
|
|
|
|
return args.func(args)
|
2016-11-29 04:16:16 +00:00
|
|
|
|
2020-03-28 23:44:47 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
raise SystemExit(main(sys.argv[1:]))
|