Use argparse to expose refresher thread controls.
This commit is contained in:
parent
9fe7057021
commit
201ae70ba0
1 changed files with 41 additions and 17 deletions
|
@ -4,29 +4,53 @@ logging.getLogger('googleapicliet.discovery_cache').setLevel(logging.ERROR)
|
||||||
import gevent.monkey
|
import gevent.monkey
|
||||||
gevent.monkey.patch_all()
|
gevent.monkey.patch_all()
|
||||||
|
|
||||||
|
import argparse
|
||||||
import gevent.pywsgi
|
import gevent.pywsgi
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import ycdl_flask
|
import ycdl_flask
|
||||||
|
|
||||||
if len(sys.argv) == 2:
|
def ycdl_flask_launch(port, refresh_rate):
|
||||||
port = int(sys.argv[1])
|
if port == 443:
|
||||||
else:
|
http = gevent.pywsgi.WSGIServer(
|
||||||
port = 5000
|
listener=('', port),
|
||||||
|
application=ycdl_flask.site,
|
||||||
|
keyfile='https\\flasksite.key',
|
||||||
|
certfile='https\\flasksite.crt',
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
http = gevent.pywsgi.WSGIServer(
|
||||||
|
listener=('0.0.0.0', port),
|
||||||
|
application=ycdl_flask.site,
|
||||||
|
)
|
||||||
|
|
||||||
if port == 443:
|
if refresh_rate is not None:
|
||||||
http = gevent.pywsgi.WSGIServer(
|
ycdl_flask.ycdl_flask.start_refresher_thread(refresh_rate)
|
||||||
listener=('', port),
|
|
||||||
application=ycdl_flask.site,
|
print(f'Starting server on port {port}')
|
||||||
keyfile='https\\flasksite.key',
|
http.serve_forever()
|
||||||
certfile='https\\flasksite.crt',
|
|
||||||
)
|
def ycdl_flask_launch_argparse(args):
|
||||||
else:
|
if args.do_refresh:
|
||||||
http = gevent.pywsgi.WSGIServer(
|
refresh_rate = args.refresh_rate
|
||||||
listener=('0.0.0.0', port),
|
else:
|
||||||
application=ycdl_flask.site,
|
refresh_rate = None
|
||||||
|
|
||||||
|
return ycdl_flask_launch(
|
||||||
|
port=args.port,
|
||||||
|
refresh_rate=refresh_rate,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def main(argv):
|
||||||
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
|
||||||
print('Starting server on port %d' % port)
|
parser.add_argument('port', nargs='?', type=int, default=5000)
|
||||||
http.serve_forever()
|
parser.add_argument('--no_refresh', dest='do_refresh', action='store_false', default=True)
|
||||||
|
parser.add_argument('--refresh_rate', dest='refresh_rate', type=int, default=60 * 60 * 6)
|
||||||
|
parser.set_defaults(func=ycdl_flask_launch_argparse)
|
||||||
|
|
||||||
|
args = parser.parse_args(argv)
|
||||||
|
return args.func(args)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
raise SystemExit(main(sys.argv[1:]))
|
||||||
|
|
Loading…
Reference in a new issue