Blame runserver.py

Neal Gompa 55fa35
#!/usr/bin/env python
Pierre-Yves Chibon 2088eb
Pierre-Yves Chibon 67d1cc
from __future__ import unicode_literals, absolute_import
Aurélien Bompard dcf6f6
Pierre-Yves Chibon d04562
import argparse
Pierre-Yves Chibon 281f75
import sys
Pierre-Yves Chibon d04562
import os
Pierre-Yves Chibon 281f75
Pierre-Yves Chibon 281f75
Pierre-Yves Chibon 73d120
parser = argparse.ArgumentParser(description="Run the Pagure app")
Pierre-Yves Chibon d04562
parser.add_argument(
Pierre-Yves Chibon 73d120
    "--config",
Pierre-Yves Chibon 73d120
    "-c",
Pierre-Yves Chibon 73d120
    dest="config",
Pierre-Yves Chibon 73d120
    help="Configuration file to use for pagure.",
Pierre-Yves Chibon 73d120
)
Pierre-Yves Chibon d04562
parser.add_argument(
Pierre-Yves Chibon 73d120
    "--plugins", dest="plugins", help="Configuration file for pagure plugin."
Pierre-Yves Chibon 73d120
)
Pierre-Yves Chibon 0f6d83
parser.add_argument(
Pierre-Yves Chibon 73d120
    "--debug",
Pierre-Yves Chibon 73d120
    dest="debug",
Pierre-Yves Chibon 73d120
    action="store_true",
Pierre-Yves Chibon d04562
    default=False,
Pierre-Yves Chibon 73d120
    help="Expand the level of data returned.",
Pierre-Yves Chibon 73d120
)
Pierre-Yves Chibon d04562
parser.add_argument(
Pierre-Yves Chibon 73d120
    "--profile",
Pierre-Yves Chibon 73d120
    dest="profile",
Pierre-Yves Chibon 73d120
    action="store_true",
Pierre-Yves Chibon d04562
    default=False,
Pierre-Yves Chibon 73d120
    help="Profile Pagure.",
Pierre-Yves Chibon 73d120
)
Pierre-Yves Chibon d04562
parser.add_argument(
Pierre-Yves Chibon 73d120
    "--perf-verbose",
Pierre-Yves Chibon 73d120
    dest="perfverbose",
Pierre-Yves Chibon 73d120
    action="store_true",
Patrick Uiterwijk 571575
    default=False,
Pierre-Yves Chibon 73d120
    help="Enable per-request printing of performance statistics.",
Pierre-Yves Chibon 73d120
)
Patrick Uiterwijk 571575
parser.add_argument(
Pierre-Yves Chibon 73d120
    "--port", "-p", default=5000, help="Port for the Pagure to run on."
Pierre-Yves Chibon 73d120
)
Ryan Lerch 73a5b2
parser.add_argument(
Pierre-Yves Chibon 73d120
    "--no-debug", action="store_true", help="Disable debugging"
Pierre-Yves Chibon 73d120
)
Patrick Uiterwijk 62924b
parser.add_argument(
Pierre-Yves Chibon 73d120
    "--host",
Pierre-Yves Chibon 73d120
    default="127.0.0.1",
Pierre-Yves Chibon 73d120
    help="Hostname to listen on. When set to 0.0.0.0 the server is available "
Pierre-Yves Chibon 73d120
    "externally. Defaults to 127.0.0.1 making the it only visible on localhost",
Pierre-Yves Chibon 73d120
)
Pierre-Yves Chibon d04562
Pierre-Yves Chibon d04562
args = parser.parse_args()
Pierre-Yves Chibon d04562
Pierre-Yves Chibon d04562
if args.config:
Pierre-Yves Chibon 0dcb38
    config = args.config
Pierre-Yves Chibon 73d120
    if not config.startswith("/"):
Pierre-Yves Chibon 0dcb38
        here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
Pierre-Yves Chibon 0dcb38
        config = os.path.join(here, config)
Pierre-Yves Chibon 73d120
    os.environ["PAGURE_CONFIG"] = config
Pierre-Yves Chibon 182e33
Pierre-Yves Chibon 0f6d83
if args.plugins:
Pierre-Yves Chibon 0f6d83
    config = args.plugins
Pierre-Yves Chibon 73d120
    if not config.startswith("/"):
Pierre-Yves Chibon 0f6d83
        here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
Pierre-Yves Chibon 0f6d83
        config = os.path.join(here, config)
Pierre-Yves Chibon 73d120
    os.environ["PAGURE_PLUGIN"] = config
Pierre-Yves Chibon 0f6d83
Patrick Uiterwijk 571575
if args.perfverbose:
Pierre-Yves Chibon 73d120
    os.environ["PAGURE_PERFREPO"] = "true"
Pierre-Yves Chibon 73d120
    os.environ["PAGURE_PERFREPO_VERBOSE"] = "true"
Patrick Uiterwijk 571575
Pierre-Yves Chibon b130e5
from pagure.flask_app import create_app
Pierre-Yves Chibon b130e5
Pierre-Yves Chibon b130e5
APP = create_app()
Pierre-Yves Chibon 94ab5a
Pierre-Yves Chibon 94ab5a
if args.profile:
Pierre-Yves Chibon 94ab5a
    from werkzeug.contrib.profiler import ProfilerMiddleware
Pierre-Yves Chibon 73d120
Pierre-Yves Chibon 73d120
    APP.config["PROFILE"] = True
Pierre-Yves Chibon 94ab5a
    APP.wsgi_app = ProfilerMiddleware(APP.wsgi_app, restrictions=[30])
Pierre-Yves Chibon 94ab5a
Patrick Uiterwijk 62924b
APP.debug = not args.no_debug
Ryan Lerch 73a5b2
APP.run(host=args.host, port=int(args.port))