comicbox readinglist, or comicbox rl: work with reading lists.
Its own parser with real subcommands, not the main parser: that parser’s positionals are always comic archives and its option dests are tested against the config template. Exits 0 on success, 1 when a reading-list, file or network error stops it or any file fails, 2 for a usage error and 130 when a fetch is cancelled with Ctrl-C.
stdout carries only what was asked for, a list or a table; warnings, losses, reports and log lines go to stderr. Nothing is written over an input, and nothing over an existing file without --overwrite.
build_parser()
Build the comicbox readinglist parser.
Source code in comicbox/readinglists/cli/__init__.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 | def build_parser() -> ArgumentParser:
"""Build the ``comicbox readinglist`` parser."""
parser = RichArgumentParser(prog=PROG, description=_DESCRIPTION, epilog=_EPILOG)
parser.add_argument(
"-Q",
"--quiet",
action="count",
default=0,
help="Log less, as in a comicbox run.",
)
# prog given, argparse doesn't render this parser's usage to make the
# actions' prog, which with rich help writes to stdout before any
# action runs: an rl piped into a closed reader then failed at once.
actions = parser.add_subparsers(
dest="action", required=True, metavar="ACTION", prog=PROG
)
files.add_file_actions(actions)
online.add_online_actions(actions)
comics.add_comic_actions(actions)
return parser
|
main(params)
Run comicbox readinglist on the args after it; return the exit code.
Source code in comicbox/readinglists/cli/__init__.py
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95 | def main(params: Sequence[str]) -> int:
"""Run ``comicbox readinglist`` on the args after it; return the exit code."""
from comicbox.logger import init_logging
args = build_parser().parse_args(params)
run = Run(args)
init_logging(run.log_level, sink="stderr")
try:
_ACTIONS[args.action](run)
except (OSError, ReadingListError, ConfigError, ConfigurationError) as exc:
run.fail(None, exc)
return 1
except OnlineLookupAbortedError as exc:
if not run.cancelled:
# The gate's own abort, such as a spent daily quota.
run.fail(None, exc)
return 1
print_note(run.err, "Cancelled.")
return EXIT_CANCELLED
except KeyboardInterrupt:
print_note(run.err, "Cancelled.")
return EXIT_CANCELLED
return run.exit_code
|
write_text(path, text)
Write a UTF-8 file whole, or leave whatever was there.
Source code in comicbox/readinglists/cli/run.py
66
67
68
69
70
71
72
73
74
75
76
77
78 | def write_text(path: Path, text: str) -> None:
"""Write a UTF-8 file whole, or leave whatever was there."""
temp = path.with_name(f".{path.name}.{os.getpid()}.tmp")
try:
temp.write_text(text, encoding="utf-8")
temp.replace(path)
except OSError as exc:
if exc.filename is not None:
# Name the destination, not the temporary file beside it.
exc.filename = str(path)
raise
finally:
temp.unlink(missing_ok=True)
|