2019-04-19 01:09:54 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
__package__ = 'archivebox.cli'
|
|
|
|
__command__ = 'archivebox schedule'
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import argparse
|
|
|
|
|
2019-04-27 21:26:24 +00:00
|
|
|
from typing import Optional, List, IO
|
2019-04-19 01:09:54 +00:00
|
|
|
|
2020-07-24 17:25:25 +00:00
|
|
|
from ..main import schedule
|
|
|
|
from ..util import docstring
|
2019-04-27 21:26:24 +00:00
|
|
|
from ..config import OUTPUT_DIR
|
2020-07-22 16:02:13 +00:00
|
|
|
from ..logging_util import SmartFormatter, reject_stdin
|
2019-04-19 01:09:54 +00:00
|
|
|
|
|
|
|
|
2019-05-01 03:10:48 +00:00
|
|
|
@docstring(schedule.__doc__)
|
2019-04-27 21:26:24 +00:00
|
|
|
def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional[str]=None) -> None:
|
2019-04-19 01:09:54 +00:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
prog=__command__,
|
2019-05-01 03:10:48 +00:00
|
|
|
description=schedule.__doc__,
|
2019-04-19 01:09:54 +00:00
|
|
|
add_help=True,
|
2019-05-01 03:10:48 +00:00
|
|
|
formatter_class=SmartFormatter,
|
2019-04-19 01:09:54 +00:00
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--quiet', '-q',
|
|
|
|
action='store_true',
|
|
|
|
help=("Don't warn about storage space."),
|
|
|
|
)
|
|
|
|
group = parser.add_mutually_exclusive_group()
|
|
|
|
group.add_argument(
|
|
|
|
'--add', # '-a',
|
|
|
|
action='store_true',
|
|
|
|
help='Add a new scheduled ArchiveBox update job to cron',
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--every', # '-e',
|
|
|
|
type=str,
|
2020-08-18 08:32:36 +00:00
|
|
|
default=None,
|
|
|
|
help='Run ArchiveBox once every [timeperiod] (hour/day/month/year or cron format e.g. "0 0 * * *")',
|
2019-04-19 01:09:54 +00:00
|
|
|
)
|
2020-08-18 05:58:54 +00:00
|
|
|
parser.add_argument(
|
|
|
|
'--depth', # '-d',
|
|
|
|
type=int,
|
2021-01-20 23:42:10 +00:00
|
|
|
choices=[0, 1],
|
2020-08-18 05:58:54 +00:00
|
|
|
default=0,
|
|
|
|
help='Depth to archive to [0] or 1, see "add" command help for more info.',
|
|
|
|
)
|
2019-04-19 01:09:54 +00:00
|
|
|
group.add_argument(
|
|
|
|
'--clear', # '-c'
|
|
|
|
action='store_true',
|
2019-04-27 21:26:24 +00:00
|
|
|
help=("Stop all ArchiveBox scheduled runs (remove cron jobs)"),
|
2019-04-19 01:09:54 +00:00
|
|
|
)
|
|
|
|
group.add_argument(
|
|
|
|
'--show', # '-s'
|
|
|
|
action='store_true',
|
|
|
|
help=("Print a list of currently active ArchiveBox cron jobs"),
|
|
|
|
)
|
|
|
|
group.add_argument(
|
|
|
|
'--foreground', '-f',
|
|
|
|
action='store_true',
|
2019-04-27 21:26:24 +00:00
|
|
|
help=("Launch ArchiveBox scheduler as a long-running foreground task "
|
2019-04-19 01:09:54 +00:00
|
|
|
"instead of using cron."),
|
|
|
|
)
|
|
|
|
group.add_argument(
|
|
|
|
'--run-all', # '-a',
|
|
|
|
action='store_true',
|
2019-04-27 21:26:24 +00:00
|
|
|
help=("Run all the scheduled jobs once immediately, independent of "
|
|
|
|
"their configured schedules, can be used together with --foreground"),
|
2019-04-19 01:09:54 +00:00
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'import_path',
|
|
|
|
nargs='?',
|
|
|
|
type=str,
|
|
|
|
default=None,
|
|
|
|
help=("Check this path and import any new links on every run "
|
|
|
|
"(can be either local file or remote URL)"),
|
|
|
|
)
|
2019-04-27 21:26:24 +00:00
|
|
|
command = parser.parse_args(args or ())
|
|
|
|
reject_stdin(__command__, stdin)
|
|
|
|
|
|
|
|
schedule(
|
|
|
|
add=command.add,
|
|
|
|
show=command.show,
|
|
|
|
clear=command.clear,
|
|
|
|
foreground=command.foreground,
|
|
|
|
run_all=command.run_all,
|
|
|
|
quiet=command.quiet,
|
|
|
|
every=command.every,
|
2020-08-18 05:58:54 +00:00
|
|
|
depth=command.depth,
|
2019-04-27 21:26:24 +00:00
|
|
|
import_path=command.import_path,
|
|
|
|
out_dir=pwd or OUTPUT_DIR,
|
|
|
|
)
|
2019-04-19 01:09:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-04-27 21:26:24 +00:00
|
|
|
main(args=sys.argv[1:], stdin=sys.stdin)
|