rundocserver.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env python
  2. from __future__ import unicode_literals, absolute_import
  3. # These two lines are needed to run on EL6
  4. __requires__ = ["jinja2 >= 2.4"]
  5. import pkg_resources
  6. import argparse
  7. import sys
  8. import os
  9. parser = argparse.ArgumentParser(description="Run the Pagure doc server")
  10. parser.add_argument(
  11. "--config",
  12. "-c",
  13. dest="config",
  14. help="Configuration file to use for the pagure doc server.",
  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 the doc server.",
  29. )
  30. parser.add_argument(
  31. "--port",
  32. "-p",
  33. default=5001,
  34. help="Port for the Pagure doc server to run on.",
  35. )
  36. parser.add_argument(
  37. "--host",
  38. default="127.0.0.1",
  39. help="Hostname to listen on. When set to 0.0.0.0 the server is "
  40. "available externally. Defaults to 127.0.0.1 making the it only "
  41. "visible on localhost",
  42. )
  43. args = parser.parse_args()
  44. if args.config:
  45. config = args.config
  46. if not config.startswith("/"):
  47. here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
  48. config = os.path.join(here, config)
  49. os.environ["PAGURE_CONFIG"] = config
  50. from pagure.docs_server import APP
  51. if args.profile:
  52. from werkzeug.contrib.profiler import ProfilerMiddleware
  53. APP.config["PROFILE"] = True
  54. APP.wsgi_app = ProfilerMiddleware(APP.wsgi_app, restrictions=[30])
  55. APP.debug = True
  56. APP.run(host=args.host, port=int(args.port))