2
0

archivebox_schedule.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/env python3
  2. __package__ = 'archivebox.cli'
  3. __command__ = 'archivebox schedule'
  4. import sys
  5. import argparse
  6. from typing import Optional, List, IO
  7. from ..main import schedule, docstring
  8. from ..config import OUTPUT_DIR
  9. from ..logging import SmartFormatter, reject_stdin
  10. @docstring(schedule.__doc__)
  11. def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional[str]=None) -> None:
  12. parser = argparse.ArgumentParser(
  13. prog=__command__,
  14. description=schedule.__doc__,
  15. add_help=True,
  16. formatter_class=SmartFormatter,
  17. )
  18. parser.add_argument(
  19. '--quiet', '-q',
  20. action='store_true',
  21. help=("Don't warn about storage space."),
  22. )
  23. group = parser.add_mutually_exclusive_group()
  24. group.add_argument(
  25. '--add', # '-a',
  26. action='store_true',
  27. help='Add a new scheduled ArchiveBox update job to cron',
  28. )
  29. parser.add_argument(
  30. '--every', # '-e',
  31. type=str,
  32. default='day',
  33. help='Run ArchiveBox once every [timeperiod] (hour/day/week/month/year or cron format e.g. "0 0 * * *")',
  34. )
  35. group.add_argument(
  36. '--clear', # '-c'
  37. action='store_true',
  38. help=("Stop all ArchiveBox scheduled runs (remove cron jobs)"),
  39. )
  40. group.add_argument(
  41. '--show', # '-s'
  42. action='store_true',
  43. help=("Print a list of currently active ArchiveBox cron jobs"),
  44. )
  45. group.add_argument(
  46. '--foreground', '-f',
  47. action='store_true',
  48. help=("Launch ArchiveBox scheduler as a long-running foreground task "
  49. "instead of using cron."),
  50. )
  51. group.add_argument(
  52. '--run-all', # '-a',
  53. action='store_true',
  54. help=("Run all the scheduled jobs once immediately, independent of "
  55. "their configured schedules, can be used together with --foreground"),
  56. )
  57. parser.add_argument(
  58. 'import_path',
  59. nargs='?',
  60. type=str,
  61. default=None,
  62. help=("Check this path and import any new links on every run "
  63. "(can be either local file or remote URL)"),
  64. )
  65. command = parser.parse_args(args or ())
  66. reject_stdin(__command__, stdin)
  67. schedule(
  68. add=command.add,
  69. show=command.show,
  70. clear=command.clear,
  71. foreground=command.foreground,
  72. run_all=command.run_all,
  73. quiet=command.quiet,
  74. every=command.every,
  75. import_path=command.import_path,
  76. out_dir=pwd or OUTPUT_DIR,
  77. )
  78. if __name__ == '__main__':
  79. main(args=sys.argv[1:], stdin=sys.stdin)