Skip to content

Commit 1bf1e93

Browse files
committed
cli: Add info --active-components
Resolves: #63
1 parent 79b0ec6 commit 1bf1e93

3 files changed

Lines changed: 36 additions & 7 deletions

File tree

bugzilla.1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ List the components in the given product
215215
List components (and their owners)
216216
.IP "--versions=PRODUCT, -v PRODUCT"
217217
List the versions for the given product
218+
.IP "--active-components"
219+
Only show active components. Combine with --components*
218220

219221

220222
.SH AUTHENTICATION COOKIES AND TOKENS

bugzilla/_cli.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def _setup_action_info_parser(subparsers):
346346
"bugzilla server.")
347347
p = subparsers.add_parser("info", description=description)
348348

349-
x = p.add_mutually_exclusive_group()
349+
x = p.add_mutually_exclusive_group(required=True)
350350
x.add_argument('-p', '--products', action='store_true',
351351
help='Get a list of products')
352352
x.add_argument('-c', '--components', metavar="PRODUCT",
@@ -355,6 +355,9 @@ def _setup_action_info_parser(subparsers):
355355
help='List components (and their owners)')
356356
x.add_argument('-v', '--versions', metavar="PRODUCT",
357357
help='List the versions for the given product')
358+
p.add_argument('--active-components', action="store_true",
359+
help='Only show active components. Combine with --components*')
360+
358361

359362

360363
def _setup_action_modify_parser(subparsers):
@@ -581,15 +584,26 @@ def _do_info(bz, opt):
581584
"""
582585
# All these commands call getproducts internally, so do it up front
583586
# with minimal include_fields for speed
587+
def _filter_components(compdetails):
588+
ret = {}
589+
for k, v in compdetails.items():
590+
if v.get("is_active", True):
591+
ret[k] = v
592+
return ret
593+
584594
productname = (opt.components or opt.component_owners or opt.versions)
585595
include_fields = ["name", "id"]
596+
fastcomponents = (opt.components and not opt.active_components)
586597
if opt.versions:
587-
include_fields.append("versions")
598+
include_fields += ["versions"]
588599
if opt.component_owners:
589600
include_fields += [
590601
"components.default_assigned_to",
591602
"components.name",
592603
]
604+
if (opt.active_components and
605+
any(["components" in i for i in include_fields])):
606+
include_fields += ["components.is_active"]
593607

594608
bz.refresh_products(names=productname and [productname] or None,
595609
include_fields=include_fields)
@@ -598,20 +612,25 @@ def _do_info(bz, opt):
598612
for name in sorted([p["name"] for p in bz.getproducts()]):
599613
print(name)
600614

601-
elif opt.components:
615+
elif fastcomponents:
602616
for name in sorted(bz.getcomponents(productname)):
603617
print(name)
604618

619+
elif opt.components:
620+
details = bz.getcomponentsdetails(productname)
621+
for name in sorted(_filter_components(details)):
622+
print(name)
623+
605624
elif opt.versions:
606625
proddict = bz.getproducts()[0]
607626
for v in proddict['versions']:
608627
print(to_encoding(v["name"]))
609628

610629
elif opt.component_owners:
611-
component_details = bz.getcomponentsdetails(productname)
612-
for c in sorted(component_details):
630+
details = bz.getcomponentsdetails(productname)
631+
for c in sorted(_filter_components(details)):
613632
print(to_encoding(u"%s: %s" % (c,
614-
component_details[c]['default_assigned_to'])))
633+
details[c]['default_assigned_to'])))
615634

616635

617636
def _convert_to_outputformat(output):

tests/ro_functional.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class RHTest(BaseTest):
213213
test01 = lambda s: BaseTest._testInfoProducts(s, 125,
214214
"Virtualization Tools")
215215
test02 = lambda s: BaseTest._testInfoComps(s, "Virtualization Tools",
216-
10, "virt-manager")
216+
10, "virtinst")
217217
test03 = lambda s: BaseTest._testInfoVers(s, "Fedora", 19, "rawhide")
218218
test04 = lambda s: BaseTest._testInfoCompOwners(s, "Virtualization Tools",
219219
"libvirt: Libvirt Maintainers")
@@ -344,3 +344,11 @@ def testExternalBugsOutput(self):
344344
expect = ("http://bugzilla.gnome.org/show_bug.cgi?id=703421\n" +
345345
"External bug: https://bugs.launchpad.net/bugs/1203576")
346346
self.assertTrue(expect in out)
347+
348+
def testActiveComps(self):
349+
out = self.clicomm("info --components 'Virtualization Tools' "
350+
"--active-components")
351+
self.assertTrue("virtinst" not in out)
352+
out = self.clicomm("info --component_owners 'Virtualization Tools' "
353+
"--active-components")
354+
self.assertTrue("virtinst" not in out)

0 commit comments

Comments
 (0)