runserver.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env python2
  2. # These two lines are needed to run on EL6
  3. __requires__ = ['SQLAlchemy >= 0.8', 'jinja2 >= 2.4']
  4. import pkg_resources
  5. import argparse
  6. import sys
  7. import os
  8. parser = argparse.ArgumentParser(
  9. description='Run the Pagure app')
  10. parser.add_argument(
  11. '--config', '-c', dest='config',
  12. help='Configuration file to use for pagure.')
  13. parser.add_argument(
  14. '--debug', dest='debug', action='store_true',
  15. default=False,
  16. help='Expand the level of data returned.')
  17. parser.add_argument(
  18. '--profile', dest='profile', action='store_true',
  19. default=False,
  20. help='Profile Pagure.')
  21. parser.add_argument(
  22. '--perf-verbose', dest='perfverbose', action='store_true',
  23. default=False,
  24. help='Enable per-request printing of performance statistics.')
  25. parser.add_argument(
  26. '--port', '-p', default=5000,
  27. help='Port for the Pagure to run on.')
  28. parser.add_argument(
  29. '--no-debug', action='store_true',
  30. help='Disable debugging')
  31. parser.add_argument(
  32. '--host', default="127.0.0.1",
  33. help='Hostname to listen on. When set to 0.0.0.0 the server is available '
  34. 'externally. Defaults to 127.0.0.1 making the it only visible on localhost')
  35. args = parser.parse_args()
  36. if args.config:
  37. config = args.config
  38. if not config.startswith('/'):
  39. here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
  40. config = os.path.join(here, config)
  41. os.environ['PAGURE_CONFIG'] = config
  42. if args.perfverbose:
  43. os.environ['PAGURE_PERFREPO'] = 'true'
  44. os.environ['PAGURE_PERFREPO_VERBOSE'] = 'true'
  45. from pagure.flask_app import create_app
  46. APP = create_app()
  47. if args.profile:
  48. from werkzeug.contrib.profiler import ProfilerMiddleware
  49. APP.config['PROFILE'] = True
  50. APP.wsgi_app = ProfilerMiddleware(APP.wsgi_app, restrictions=[30])
  51. APP.debug = not args.no_debug
  52. APP.run(host=args.host, port=int(args.port))