runserver.py 2.2 KB

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