From 52ae1e1c03281eefbbf6cd2de983815063797327 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jan 29 2016 22:15:42 +0000 Subject: Merge pull request #57 from fedora-infra/improved_script Rework the runserver script to offer more options --- diff --git a/README.rst b/README.rst index 42dc6de..96a39c8 100644 --- a/README.rst +++ b/README.rst @@ -81,7 +81,7 @@ There are 2 ways to start the application: * with apache -* How to start without apache on localhost:5000 (useful for development): +* How to start without apache on http://127.0.0.1:5000 (useful for development): :: diff --git a/runserver.py b/runserver.py index 922f528..03becc0 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 Fedora election 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 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='127.0.0.1', port=int(args.port))