archivebox_schedule.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. '--tag', '-t',
  38. type=str,
  39. default='',
  40. help="Tag the added URLs with the provided tags e.g. --tag=tag1,tag2,tag3",
  41. )
  42. parser.add_argument(
  43. '--depth', # '-d',
  44. type=int,
  45. choices=[0, 1],
  46. default=0,
  47. help='Depth to archive to [0] or 1, see "add" command help for more info',
  48. )
  49. parser.add_argument(
  50. '--overwrite',
  51. action='store_true',
  52. help='Re-archive any URLs that have been previously archived, overwriting existing Snapshots',
  53. )
  54. parser.add_argument(
  55. '--update',
  56. action='store_true',
  57. help='Re-pull any URLs that have been previously added, as needed to fill missing ArchiveResults',
  58. )
  59. group.add_argument(
  60. '--clear', # '-c'
  61. action='store_true',
  62. help=("Stop all ArchiveBox scheduled runs (remove cron jobs)"),
  63. )
  64. group.add_argument(
  65. '--show', # '-s'
  66. action='store_true',
  67. help=("Print a list of currently active ArchiveBox cron jobs"),
  68. )
  69. group.add_argument(
  70. '--foreground', '-f',
  71. action='store_true',
  72. help=("Launch ArchiveBox scheduler as a long-running foreground task "
  73. "instead of using cron."),
  74. )
  75. group.add_argument(
  76. '--run-all', # '-a',
  77. action='store_true',
  78. help=("Run all the scheduled jobs once immediately, independent of "
  79. "their configured schedules, can be used together with --foreground"),
  80. )
  81. parser.add_argument(
  82. 'import_path',
  83. nargs='?',
  84. type=str,
  85. default=None,
  86. help=("Check this path and import any new links on every run "
  87. "(can be either local file or remote URL)"),
  88. )
  89. command = parser.parse_args(args or ())
  90. reject_stdin(__command__, stdin)
  91. schedule(
  92. add=command.add,
  93. show=command.show,
  94. clear=command.clear,
  95. foreground=command.foreground,
  96. run_all=command.run_all,
  97. quiet=command.quiet,
  98. every=command.every,
  99. tag=command.tag,
  100. depth=command.depth,
  101. overwrite=command.overwrite,
  102. update=command.update,
  103. import_path=command.import_path,
  104. out_dir=pwd or OUTPUT_DIR,
  105. )
  106. if __name__ == '__main__':
  107. main(args=sys.argv[1:], stdin=sys.stdin)