archivebox_shell.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python3
  2. __package__ = 'archivebox.cli'
  3. __command__ = 'archivebox shell'
  4. import sys
  5. import argparse
  6. from pathlib import Path
  7. from typing import Optional, List, IO
  8. from archivebox.misc.util import docstring
  9. from archivebox.config import DATA_DIR
  10. from archivebox.misc.logging_util import SmartFormatter, reject_stdin
  11. #@enforce_types
  12. def shell(out_dir: Path=DATA_DIR) -> None:
  13. """Enter an interactive ArchiveBox Django shell"""
  14. check_data_folder()
  15. from django.core.management import call_command
  16. call_command("shell_plus")
  17. @docstring(shell.__doc__)
  18. def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional[str]=None) -> None:
  19. parser = argparse.ArgumentParser(
  20. prog=__command__,
  21. description=shell.__doc__,
  22. add_help=True,
  23. formatter_class=SmartFormatter,
  24. )
  25. parser.parse_args(args or ())
  26. reject_stdin(__command__, stdin)
  27. shell(
  28. out_dir=Path(pwd) if pwd else DATA_DIR,
  29. )
  30. if __name__ == '__main__':
  31. main(args=sys.argv[1:], stdin=sys.stdin)