runserver.py 1.9 KB

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