1
0

runserver.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. '--plugins', dest='plugins',
  16. help='Configuration file for pagure plugin.')
  17. parser.add_argument(
  18. '--debug', dest='debug', action='store_true',
  19. default=False,
  20. help='Expand the level of data returned.')
  21. parser.add_argument(
  22. '--profile', dest='profile', action='store_true',
  23. default=False,
  24. help='Profile Pagure.')
  25. parser.add_argument(
  26. '--perf-verbose', dest='perfverbose', action='store_true',
  27. default=False,
  28. help='Enable per-request printing of performance statistics.')
  29. parser.add_argument(
  30. '--port', '-p', default=5000,
  31. help='Port for the Pagure to run on.')
  32. parser.add_argument(
  33. '--no-debug', action='store_true',
  34. help='Disable debugging')
  35. parser.add_argument(
  36. '--host', default="127.0.0.1",
  37. help='Hostname to listen on. When set to 0.0.0.0 the server is available '
  38. 'externally. Defaults to 127.0.0.1 making the it only visible on localhost')
  39. args = parser.parse_args()
  40. if args.config:
  41. config = args.config
  42. if not config.startswith('/'):
  43. here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
  44. config = os.path.join(here, config)
  45. os.environ['PAGURE_CONFIG'] = config
  46. if args.plugins:
  47. config = args.plugins
  48. if not config.startswith('/'):
  49. here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
  50. config = os.path.join(here, config)
  51. os.environ['PAGURE_PLUGIN'] = config
  52. if args.perfverbose:
  53. os.environ['PAGURE_PERFREPO'] = 'true'
  54. os.environ['PAGURE_PERFREPO_VERBOSE'] = 'true'
  55. from pagure.flask_app import create_app
  56. APP = create_app()
  57. if args.profile:
  58. from werkzeug.contrib.profiler import ProfilerMiddleware
  59. APP.config['PROFILE'] = True
  60. APP.wsgi_app = ProfilerMiddleware(APP.wsgi_app, restrictions=[30])
  61. APP.debug = not args.no_debug
  62. APP.run(host=args.host, port=int(args.port))