2
0

archivebox_schedule.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. parser.add_argument(
  44. '--overwrite',
  45. action='store_true',
  46. help='Re-archive any URLs that have been previously archived, overwriting existing Snapshots',
  47. )
  48. group.add_argument(
  49. '--clear', # '-c'
  50. action='store_true',
  51. help=("Stop all ArchiveBox scheduled runs (remove cron jobs)"),
  52. )
  53. group.add_argument(
  54. '--show', # '-s'
  55. action='store_true',
  56. help=("Print a list of currently active ArchiveBox cron jobs"),
  57. )
  58. group.add_argument(
  59. '--foreground', '-f',
  60. action='store_true',
  61. help=("Launch ArchiveBox scheduler as a long-running foreground task "
  62. "instead of using cron."),
  63. )
  64. group.add_argument(
  65. '--run-all', # '-a',
  66. action='store_true',
  67. help=("Run all the scheduled jobs once immediately, independent of "
  68. "their configured schedules, can be used together with --foreground"),
  69. )
  70. parser.add_argument(
  71. 'import_path',
  72. nargs='?',
  73. type=str,
  74. default=None,
  75. help=("Check this path and import any new links on every run "
  76. "(can be either local file or remote URL)"),
  77. )
  78. command = parser.parse_args(args or ())
  79. reject_stdin(__command__, stdin)
  80. schedule(
  81. add=command.add,
  82. show=command.show,
  83. clear=command.clear,
  84. foreground=command.foreground,
  85. run_all=command.run_all,
  86. quiet=command.quiet,
  87. every=command.every,
  88. depth=command.depth,
  89. overwrite=command.overwrite,
  90. import_path=command.import_path,
  91. out_dir=pwd or OUTPUT_DIR,
  92. )
  93. if __name__ == '__main__':
  94. main(args=sys.argv[1:], stdin=sys.stdin)