Skip to content

Commit 2571514

Browse files
committed
bin/bugzilla: Add query --sub-component
1 parent 69a6491 commit 2571514

5 files changed

Lines changed: 58 additions & 13 deletions

File tree

bin/bugzilla

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,14 @@ def setup_action_parser(action):
170170
help="specify individual bugs by IDs, separated with commas")
171171
p.add_option('-p', '--product',
172172
help="product name, comma-separated "
173-
"(list with 'bugzilla info -p')")
173+
"(list with 'bugzilla info --products')")
174174
p.add_option('-v', '--version',
175175
help="product version, comma-separated")
176176
p.add_option('-c', '--component',
177177
help="component name(s), comma-separated "
178-
"(list with 'bugzilla info -c PRODUCT')")
178+
"(list with 'bugzilla info --components PRODUCT')")
179+
p.add_option("--sub-component", action="append",
180+
help="Sub component. Can be specified multiple times")
179181
p.add_option('--components_file', default=None,
180182
help="list of component names from a file, one component "
181183
"per line (list with 'bugzilla info -c PRODUCT')")
@@ -631,6 +633,7 @@ def _do_query(bz, opt, parser):
631633
built_query = bz.build_query(
632634
product=getattr(opt, "product", None),
633635
component=getattr(opt, "component", None),
636+
sub_component=getattr(opt, "sub_component", None),
634637
version=getattr(opt, "version", None),
635638
reporter=getattr(opt, "reporter", None),
636639
bug_id=getattr(opt, "bug_id", None),

bugzilla/base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,8 @@ def build_query(self,
907907
include_fields=None,
908908
quicksearch=None,
909909
savedsearch=None,
910-
savedsearch_sharer_id=None):
910+
savedsearch_sharer_id=None,
911+
sub_component=None):
911912
"""
912913
Build a query string from passed arguments. Will handle
913914
query parameter differences between various bugzilla versions.
@@ -938,6 +939,7 @@ def build_query(self,
938939
('quicksearch', quicksearch),
939940
('savedsearch', savedsearch),
940941
('sharer_id', savedsearch_sharer_id),
942+
('sub_component', sub_component),
941943
]:
942944
if not val is None:
943945
raise RuntimeError("'%s' search not supported by this "
@@ -1119,7 +1121,7 @@ def build_update(self,
11191121
("devel_whiteboard", devel_whiteboard),
11201122
("qa_whiteboard", qa_whiteboard),
11211123
("internal_whiteboard", internal_whiteboard),
1122-
("sub_components", sub_components),
1124+
("sub_component", sub_component),
11231125
]:
11241126
if val is not None:
11251127
raise ValueError("bugzilla instance does not support "

bugzilla/rhbugzilla.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,26 +83,25 @@ def pop(key, destkey):
8383
return
8484
adddict[destkey] = val
8585

86-
def set_sub_components():
87-
val = kwargs.pop("sub_components")
86+
def get_sub_component():
87+
val = kwargs.pop("sub_component", None)
8888
if val is None:
8989
return
9090

9191
if type(val) is not dict:
92-
component = kwargs.get("component")
93-
if component is None:
92+
component = self._listify(kwargs.get("component"))
93+
if component is []:
9494
raise ValueError("component must be specified if "
9595
"specifying sub_component")
96-
val = {component: val}
97-
96+
val = {component[0]: val}
9897
adddict["sub_components"] = val
9998

10099
pop("fixed_in", "cf_fixed_in")
101100
pop("qa_whiteboard", "cf_qa_whiteboard")
102101
pop("devel_whiteboard", "cf_devel_whiteboard")
103102
pop("internal_whiteboard", "cf_internal_whiteboard")
104103

105-
set_sub_components()
104+
get_sub_component()
106105

107106
vals = _parent.build_update(self, **kwargs)
108107
vals.update(adddict)
@@ -138,8 +137,14 @@ def pre_translation(self, query):
138137
query['include_fields'] = query['column_list']
139138
del query['column_list']
140139

140+
include_aliases = (
141+
("component", "components"),
142+
("version", "versions"),
143+
("sub_components", "sub_component"),
144+
)
145+
141146
include_fields = query['include_fields']
142-
for newname, oldname in self.field_aliases:
147+
for newname, oldname in (self.field_aliases + include_aliases):
143148
if oldname in include_fields:
144149
include_fields.remove(oldname)
145150
if newname not in include_fields:
@@ -168,6 +173,17 @@ def post_translation(self, query, bug):
168173
bug['versions'] = type(val) is list and val or [val]
169174
bug['version'] = bug['versions'][0]
170175

176+
# sub_components isn't too friendly of a format, add a simpler
177+
# sub_component value
178+
if 'sub_components' in bug and 'sub_component' not in bug:
179+
val = bug['sub_components']
180+
bug['sub_component'] = ""
181+
if type(val) is dict:
182+
values = []
183+
for vallist in val.values():
184+
values += vallist
185+
bug['sub_component'] = " ".join(values)
186+
171187
if not self.rhbz_back_compat:
172188
return
173189

@@ -208,10 +224,12 @@ def post_translation(self, query, bug):
208224
def build_query(self, **kwargs):
209225
query = {}
210226

211-
def _add_key(paramname, keyname):
227+
def _add_key(paramname, keyname, listify=False):
212228
val = kwargs.pop(paramname, None)
213229
if val is None:
214230
return
231+
if listify:
232+
val = self._listify(val)
215233
query[keyname] = val
216234

217235
def add_longdesc():
@@ -338,6 +356,7 @@ def make_bool_str(prefix):
338356
_add_key("quicksearch", "quicksearch")
339357
_add_key("savedsearch", "savedsearch")
340358
_add_key("savedsearch_sharer_id", "sharer_id")
359+
_add_key("sub_component", "sub_components", listify=True)
341360

342361
newquery = _parent.build_query(self, **kwargs)
343362
query.update(newquery)

tests/query.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ def testSavedsearch(self):
116116
self.clicomm("--savedsearch 'my saved search' "
117117
"--savedsearch-sharer-id 123456", self._savedsearch_out)
118118

119+
def testSubComponent(self):
120+
self.clicomm("--component lvm2,kernel "
121+
"--sub-component 'Command-line tools (RHEL5)'",
122+
self._sub_component_out)
119123

120124
# Test data. This is what subclasses need to fill in
121125
bz = bz34
@@ -146,6 +150,7 @@ def testSavedsearch(self):
146150
_longdesc_out = None
147151
_quicksearch_out = None
148152
_savedsearch_out = None
153+
_sub_component_out = None
149154

150155

151156
class BZ4Test(BZ34Test):
@@ -233,6 +238,9 @@ class RHBZTest(BZ4Test):
233238
'quicksearch': 'foo bar baz'}
234239
_savedsearch_out = {'include_fields': BZ4Test._default_includes,
235240
'savedsearch': "my saved search", 'sharer_id': "123456"}
241+
_sub_component_out = {'include_fields': BZ4Test._default_includes,
242+
'component': ["lvm2", "kernel"],
243+
'sub_components': ["Command-line tools (RHEL5)"]}
236244

237245

238246
class TestURLToQuery(unittest.TestCase):

tests/ro_functional.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,16 @@ def testGetBugAlias(self):
217217
bz = self.bzclass(url=self.url, cookiefile=None)
218218
bug = bz.getbug("CVE-2011-2527")
219219
self.assertTrue(bug.bug_id == 720773)
220+
221+
def testQuerySubComponent(self):
222+
# As of this writing, the feature is quite new and
223+
# partner-bugzilla doesn't seem to have any actual bugs
224+
# with sub components set. After a few months and a
225+
# partner-bugzilla refresh we should be able to find something
226+
# to check
227+
228+
#out = self.clicomm("query --product 'Red Hat Enterprise Linux 5' "
229+
# "--component lvm2 --sub-component 'Command-line tools (RHEL5)'")
230+
#self.assertEquals(len(out.splitlines()), 3)
231+
#self.assertTrue("#186437 CLOSED" in out)
232+
pass

0 commit comments

Comments
 (0)