Skip to content

Commit

Permalink
Merge pull request #7512 from ThomasWaldmann/prune-list-pruned-master
Browse files Browse the repository at this point in the history
prune --list-kept/--list-pruned, fixes #7511
  • Loading branch information
ThomasWaldmann committed Apr 8, 2023
2 parents 33599b9 + 02b2888 commit 1e1c922
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/borg/archiver/__init__.py
Expand Up @@ -441,7 +441,6 @@ def _setup_implied_logging(self, args):
"""turn on INFO level logging for args that imply that they will produce output"""
# map of option name to name of logger for that option
option_logger = {
"output_list": "borg.output.list",
"show_version": "borg.output.show-version",
"show_rc": "borg.output.show-rc",
"stats": "borg.output.stats",
Expand All @@ -451,6 +450,10 @@ def _setup_implied_logging(self, args):
option_set = args.get(option, False)
logging.getLogger(logger_name).setLevel("INFO" if option_set else "WARN")

# special-case --list / --list-kept / --list-pruned as they all work on same logger
options = [args.get(name, False) for name in ("output_list", "list_kept", "list_pruned")]
logging.getLogger("borg.output.list").setLevel("INFO" if any(options) else "WARN")

def _setup_topic_debugging(self, args):
"""Turn on DEBUG level logging for specified --debug-topics."""
for topic in args.debug_topics:
Expand Down
12 changes: 11 additions & 1 deletion src/borg/archiver/prune_cmd.py
Expand Up @@ -164,7 +164,11 @@ def checkpoint_func():
log_message = "Keeping archive (rule: {rule} #{num}):".format(
rule=kept_because[archive.id][0], num=kept_because[archive.id][1]
)
if args.output_list:
if (
args.output_list
or (args.list_pruned and archive in to_delete)
or (args.list_kept and archive not in to_delete)
):
list_logger.info(f"{log_message:<40} {formatter.format_item(archive)}")
pi.finish()
if sig_int:
Expand Down Expand Up @@ -266,6 +270,12 @@ def build_parser_prune(self, subparsers, common_parser, mid_common_parser):
"--list", dest="output_list", action="store_true", help="output verbose list of archives it keeps/prunes"
)
subparser.add_argument("--short", dest="short", action="store_true", help="use a less wide archive part format")
subparser.add_argument(
"--list-pruned", dest="list_pruned", action="store_true", help="output verbose list of archives it prunes"
)
subparser.add_argument(
"--list-kept", dest="list_kept", action="store_true", help="output verbose list of archives it keeps"
)
subparser.add_argument(
"--format",
metavar="FORMAT",
Expand Down

0 comments on commit 1e1c922

Please sign in to comment.