1
0

runserver.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. parser.add_argument(
  60. "--cert", "-s", default=None, help="Filename of SSL cert for the flask application."
  61. )
  62. parser.add_argument(
  63. "--key",
  64. "-k",
  65. default=None,
  66. help="Filename of the SSL key for the flask application.",
  67. )
  68. args = parser.parse_args()
  69. if args.config:
  70. config = args.config
  71. if not config.startswith("/"):
  72. here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
  73. config = os.path.join(here, config)
  74. os.environ["PAGURE_CONFIG"] = config
  75. if args.plugins:
  76. config = args.plugins
  77. if not config.startswith("/"):
  78. here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
  79. config = os.path.join(here, config)
  80. os.environ["PAGURE_PLUGINS_CONFIG"] = config
  81. # If this script is ran with the deprecated env. variable PAGURE_PLUGIN
  82. # and --plugins, we need to override it too.
  83. if "PAGURE_PLUGIN" in os.environ:
  84. os.environ["PAGURE_PLUGIN"] = config
  85. if args.perfverbose:
  86. os.environ["PAGURE_PERFREPO"] = "true"
  87. os.environ["PAGURE_PERFREPO_VERBOSE"] = "true"
  88. from pagure.flask_app import create_app
  89. APP = create_app()
  90. if args.profile:
  91. from werkzeug.contrib.profiler import ProfilerMiddleware
  92. APP.config["PROFILE"] = True
  93. APP.wsgi_app = ProfilerMiddleware(APP.wsgi_app, restrictions=[30])
  94. APP.debug = not args.no_debug
  95. if args.cert and args.key:
  96. APP.run(host=args.host, port=int(args.port), ssl_context=(args.cert, args.key))
  97. else:
  98. APP.run(host=args.host, port=int(args.port))