From b0ccbb024fe8f50737eefa47f229dd909b61f83d Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jan 24 2016 08:36:07 +0000 Subject: Rework the runserver script to offer more options --- diff --git a/runserver.py b/runserver.py index 922f528..b24c408 100755 --- a/runserver.py +++ b/runserver.py @@ -1,16 +1,46 @@ -#!/usr/bin/env python -import __main__ -__main__.__requires__ = ['SQLAlchemy >= 0.7', 'jinja2 >= 2.4'] +#!/usr/bin/env python2 + +# These two lines are needed to run on EL6 +__requires__ = ['SQLAlchemy >= 0.8', 'jinja2 >= 2.4'] import pkg_resources +import argparse import sys -from werkzeug.contrib.profiler import ProfilerMiddleware +import os + + +parser = argparse.ArgumentParser( + description='Run the packages2 app') +parser.add_argument( + '--config', '-c', dest='config', + help='Configuration file to use for packages.') +parser.add_argument( + '--debug', dest='debug', action='store_true', + default=False, + help='Expand the level of data returned.') +parser.add_argument( + '--profile', dest='profile', action='store_true', + default=False, + help='Profile the packages2 application.') +parser.add_argument( + '--port', '-p', default=5000, + help='Port for the flask application.') + +args = parser.parse_args() from fedora_elections import APP -APP.debug = True -if '--profile' in sys.argv: +if args.profile: + from werkzeug.contrib.profiler import ProfilerMiddleware APP.config['PROFILE'] = True APP.wsgi_app = ProfilerMiddleware(APP.wsgi_app, restrictions=[30]) -APP.run() +if args.config: + config = args.config + if not config.startswith('/'): + here = os.path.join(os.path.dirname(os.path.abspath(__file__))) + config = os.path.join(here, config) + os.environ['FEDORA_ELECTIONS_CONFIG'] = config + +APP.debug = True +APP.run(host='0.0.0.0', port=int(args.port))