Skip to content

Commit b5d7815

Browse files
ckalinacrobinso
authored andcommitted
cli: add the option to skip obsolete attachments with --get-all
Introduce --ignore-obsolete. When used (e.g., with attach --get-all), obsolete attachments are ignored and not downloaded. Signed-off-by: Čestmír Kalina <[email protected]>
1 parent d3c7ae7 commit b5d7815

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

bugzilla/_cli.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def _setup_action_modify_parser(subparsers):
403403
def _setup_action_attach_parser(subparsers):
404404
usage = """
405405
bugzilla attach --file=FILE --desc=DESC [--type=TYPE] BUGID [BUGID...]
406-
bugzilla attach --get=ATTACHID --getall=BUGID [...]
406+
bugzilla attach --get=ATTACHID --getall=BUGID [--ignore-obsolete] [...]
407407
bugzilla attach --type=TYPE BUGID [BUGID...]"""
408408
description = "Attach files or download attachments."
409409
p = subparsers.add_parser("attach", description=description, usage=usage)
@@ -420,6 +420,8 @@ def _setup_action_attach_parser(subparsers):
420420
default=[], help="Download the attachment with the given ID")
421421
p.add_argument("--getall", "--get-all", metavar="BUGID", action="append",
422422
default=[], help="Download all attachments on the given bug")
423+
p.add_argument('--ignore-obsolete', action="store_true",
424+
help='Do not download attachments marked as obsolete.')
423425
p.add_argument('-l', '--comment', '--long_desc',
424426
help="Add comment with attachment")
425427
p.add_argument('--private', action='store_true', default=False,
@@ -977,6 +979,11 @@ def _do_get_attach(bz, opt):
977979
opt.get += bug.get_attachment_ids()
978980

979981
for attid in set(opt.get):
982+
if opt.ignore_obsolete:
983+
metadata = bz.get_attachments(None, attid,
984+
include_fields=["is_obsolete"])
985+
if metadata["attachments"][str(attid)]['is_obsolete'] == 1:
986+
continue
980987
att = bz.openattachment(attid)
981988
outfile = open_without_clobber(att.name, "wb")
982989
data = att.read(4096)

0 commit comments

Comments
 (0)