archivebox_server.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. '--init',
  38. action='store_true',
  39. help='Run archivebox init before starting the server',
  40. )
  41. parser.add_argument(
  42. '--createsuperuser',
  43. action='store_true',
  44. help='Run archivebox manage createsuperuser before starting the server',
  45. )
  46. command = parser.parse_args(args or ())
  47. reject_stdin(__command__, stdin)
  48. server(
  49. runserver_args=command.runserver_args,
  50. reload=command.reload,
  51. debug=command.debug,
  52. init=command.init,
  53. createsuperuser=command.createsuperuser,
  54. out_dir=pwd or OUTPUT_DIR,
  55. )
  56. if __name__ == '__main__':
  57. main(args=sys.argv[1:], stdin=sys.stdin)