archivebox_server.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env python3
  2. __package__ = 'archivebox.cli'
  3. __command__ = 'archivebox server'
  4. import sys
  5. import argparse
  6. from typing import Optional, List, IO
  7. from ..main import server
  8. from ..util import docstring
  9. from ..config import OUTPUT_DIR, BIND_ADDR
  10. from ..logging_util import SmartFormatter, reject_stdin
  11. @docstring(server.__doc__)
  12. def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional[str]=None) -> None:
  13. parser = argparse.ArgumentParser(
  14. prog=__command__,
  15. description=server.__doc__,
  16. add_help=True,
  17. formatter_class=SmartFormatter,
  18. )
  19. parser.add_argument(
  20. 'runserver_args',
  21. nargs='*',
  22. type=str,
  23. default=[BIND_ADDR],
  24. help='Arguments to pass to Django runserver'
  25. )
  26. parser.add_argument(
  27. '--reload',
  28. action='store_true',
  29. help='Enable auto-reloading when code or templates change',
  30. )
  31. parser.add_argument(
  32. '--debug',
  33. action='store_true',
  34. help='Enable DEBUG=True mode with more verbose errors',
  35. )
  36. parser.add_argument(
  37. '--nothreading',
  38. action='store_true',
  39. help='Force runserver to run in single-threaded mode',
  40. )
  41. parser.add_argument(
  42. '--init',
  43. action='store_true',
  44. help='Run a full archivebox init/upgrade before starting the server',
  45. )
  46. parser.add_argument(
  47. '--quick-init', '-i',
  48. action='store_true',
  49. help='Run quick archivebox init/upgrade before starting the server',
  50. )
  51. parser.add_argument(
  52. '--createsuperuser',
  53. action='store_true',
  54. help='Run archivebox manage createsuperuser before starting the server',
  55. )
  56. command = parser.parse_args(args or ())
  57. reject_stdin(__command__, stdin)
  58. server(
  59. runserver_args=command.runserver_args + (['--nothreading'] if command.nothreading else []),
  60. reload=command.reload,
  61. debug=command.debug,
  62. init=command.init,
  63. quick_init=command.quick_init,
  64. createsuperuser=command.createsuperuser,
  65. out_dir=pwd or OUTPUT_DIR,
  66. )
  67. if __name__ == '__main__':
  68. main(args=sys.argv[1:], stdin=sys.stdin)