runserver.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/env python
  2. from __future__ import unicode_literals, absolute_import
  3. import argparse
  4. import sys
  5. import os
  6. parser = argparse.ArgumentParser(
  7. description='Run the Pagure app')
  8. parser.add_argument(
  9. '--config', '-c', dest='config',
  10. help='Configuration file to use for pagure.')
  11. parser.add_argument(
  12. '--plugins', dest='plugins',
  13. help='Configuration file for pagure plugin.')
  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.plugins:
  44. config = args.plugins
  45. if not config.startswith('/'):
  46. here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
  47. config = os.path.join(here, config)
  48. os.environ['PAGURE_PLUGIN'] = config
  49. if args.perfverbose:
  50. os.environ['PAGURE_PERFREPO'] = 'true'
  51. os.environ['PAGURE_PERFREPO_VERBOSE'] = 'true'
  52. from pagure.flask_app import create_app
  53. APP = create_app()
  54. if args.profile:
  55. from werkzeug.contrib.profiler import ProfilerMiddleware
  56. APP.config['PROFILE'] = True
  57. APP.wsgi_app = ProfilerMiddleware(APP.wsgi_app, restrictions=[30])
  58. APP.debug = not args.no_debug
  59. APP.run(host=args.host, port=int(args.port))