runserver.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/usr/bin/env python
  2. ###############################################################################
  3. # Please note that this script is only used for development purposes. #
  4. # Do not start the Flask app with this script in a production environment, #
  5. # use files/pagure.wsgi instead! #
  6. ###############################################################################
  7. from __future__ import unicode_literals, absolute_import
  8. import argparse
  9. import sys
  10. import os
  11. parser = argparse.ArgumentParser(description="Run the Pagure app")
  12. parser.add_argument(
  13. "--config",
  14. "-c",
  15. dest="config",
  16. help="Configuration file to use for pagure.",
  17. )
  18. parser.add_argument(
  19. "--plugins",
  20. dest="plugins",
  21. help="Configuration file for pagure plugins. This argument takes "
  22. "precedence over the environment variable PAGURE_PLUGINS_CONFIG, which in "
  23. "turn takes precedence over the configuration variable "
  24. "PAGURE_PLUGINS_CONFIG.",
  25. )
  26. parser.add_argument(
  27. "--debug",
  28. dest="debug",
  29. action="store_true",
  30. default=False,
  31. help="Expand the level of data returned.",
  32. )
  33. parser.add_argument(
  34. "--profile",
  35. dest="profile",
  36. action="store_true",
  37. default=False,
  38. help="Profile Pagure.",
  39. )
  40. parser.add_argument(
  41. "--perf-verbose",
  42. dest="perfverbose",
  43. action="store_true",
  44. default=False,
  45. help="Enable per-request printing of performance statistics.",
  46. )
  47. parser.add_argument(
  48. "--port", "-p", default=5000, help="Port for the Pagure to run on."
  49. )
  50. parser.add_argument(
  51. "--no-debug", action="store_true", help="Disable debugging"
  52. )
  53. parser.add_argument(
  54. "--host",
  55. default="127.0.0.1",
  56. help="Hostname to listen on. When set to 0.0.0.0 the server is available "
  57. "externally. Defaults to 127.0.0.1 making the it only visible on localhost",
  58. )
  59. args = parser.parse_args()
  60. if args.config:
  61. config = args.config
  62. if not config.startswith("/"):
  63. here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
  64. config = os.path.join(here, config)
  65. os.environ["PAGURE_CONFIG"] = config
  66. if args.plugins:
  67. config = args.plugins
  68. if not config.startswith("/"):
  69. here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
  70. config = os.path.join(here, config)
  71. os.environ["PAGURE_PLUGINS_CONFIG"] = config
  72. # If this script is ran with the deprecated env. variable PAGURE_PLUGIN
  73. # and --plugins, we need to override it too.
  74. if "PAGURE_PLUGIN" in os.environ:
  75. os.environ["PAGURE_PLUGIN"] = config
  76. if args.perfverbose:
  77. os.environ["PAGURE_PERFREPO"] = "true"
  78. os.environ["PAGURE_PERFREPO_VERBOSE"] = "true"
  79. from pagure.flask_app import create_app
  80. APP = create_app()
  81. if args.profile:
  82. from werkzeug.contrib.profiler import ProfilerMiddleware
  83. APP.config["PROFILE"] = True
  84. APP.wsgi_app = ProfilerMiddleware(APP.wsgi_app, restrictions=[30])
  85. APP.debug = not args.no_debug
  86. APP.run(host=args.host, port=int(args.port))