archivebox_schedule.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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
  8. from ..util import docstring
  9. from ..config import OUTPUT_DIR
  10. from ..logging_util import SmartFormatter, reject_stdin
  11. @docstring(schedule.__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=schedule.__doc__,
  16. add_help=True,
  17. formatter_class=SmartFormatter,
  18. )
  19. parser.add_argument(
  20. '--quiet', '-q',
  21. action='store_true',
  22. help=("Don't warn about storage space."),
  23. )
  24. group = parser.add_mutually_exclusive_group()
  25. group.add_argument(
  26. '--add', # '-a',
  27. action='store_true',
  28. help='Add a new scheduled ArchiveBox update job to cron',
  29. )
  30. parser.add_argument(
  31. '--every', # '-e',
  32. type=str,
  33. default=None,
  34. help='Run ArchiveBox once every [timeperiod] (hour/day/month/year or cron format e.g. "0 0 * * *")',
  35. )
  36. parser.add_argument(
  37. '--depth', # '-d',
  38. type=int,
  39. choices=[0, 1],
  40. default=0,
  41. help='Depth to archive to [0] or 1, see "add" command help for more info.',
  42. )
  43. group.add_argument(
  44. '--clear', # '-c'
  45. action='store_true',
  46. help=("Stop all ArchiveBox scheduled runs (remove cron jobs)"),
  47. )
  48. group.add_argument(
  49. '--show', # '-s'
  50. action='store_true',
  51. help=("Print a list of currently active ArchiveBox cron jobs"),
  52. )
  53. group.add_argument(
  54. '--foreground', '-f',
  55. action='store_true',
  56. help=("Launch ArchiveBox scheduler as a long-running foreground task "
  57. "instead of using cron."),
  58. )
  59. group.add_argument(
  60. '--run-all', # '-a',
  61. action='store_true',
  62. help=("Run all the scheduled jobs once immediately, independent of "
  63. "their configured schedules, can be used together with --foreground"),
  64. )
  65. parser.add_argument(
  66. 'import_path',
  67. nargs='?',
  68. type=str,
  69. default=None,
  70. help=("Check this path and import any new links on every run "
  71. "(can be either local file or remote URL)"),
  72. )
  73. command = parser.parse_args(args or ())
  74. reject_stdin(__command__, stdin)
  75. schedule(
  76. add=command.add,
  77. show=command.show,
  78. clear=command.clear,
  79. foreground=command.foreground,
  80. run_all=command.run_all,
  81. quiet=command.quiet,
  82. every=command.every,
  83. depth=command.depth,
  84. import_path=command.import_path,
  85. out_dir=pwd or OUTPUT_DIR,
  86. )
  87. if __name__ == '__main__':
  88. main(args=sys.argv[1:], stdin=sys.stdin)