From: Arun Babu Neelicattu <abn(a)redhat.com>
- make the --field option available with new, modify and query commands
- refactor reused code relating to implementation of --field option
---
bin/bugzilla | 47 ++++++++++++++++++++++++++++++-----------------
1 file changed, 30 insertions(+), 17 deletions(-)
diff --git a/bin/bugzilla b/bin/bugzilla
index f7766ca..14ed6b6 100755
--- a/bin/bugzilla
+++ b/bin/bugzilla
@@ -298,13 +298,6 @@ def setup_action_parser(action):
p.set_usage("%prog modify [options] BUGID [BUGID...]")
p.set_description("Modify one or more bugs.")
- p.add_option('--field',
- help="Modify a specified field. FIELD is expected to be \
- the raw name used by the bugzilla instance. No safety \
- checks are perfomed when using this option.",
- action="append", type="str", dest="fields",
- metavar="FIELD=VALUE")
-
bgrp = optparse.OptionGroup(p, "Bug details")
bgrp.add_option('--product',
help="Reassign bug to different product")
@@ -443,6 +436,18 @@ def setup_action_parser(action):
"section 'OUTPUT FORMAT' for more details.")
p.add_option_group(outg)
+ if action in ['new', 'query', 'modify']:
+ message = {
+ 'new': 'Set a specified field.',
+ 'query': 'Query a specified field.',
+ 'modify': 'Modify a specified field.'
+ }.get(action)
+ p.add_option('--field', help="%s FIELD is expected to be \
+ the raw name used by the bugzilla instance. No safety \
+ checks are perfomed when using this option." % (message),
+ action="append", type="str", dest="fields",
+ metavar="FIELD=VALUE")
+
# Used by unit tests, not for end user consumption
if action in ['new', 'query', 'modify']:
@@ -572,6 +577,17 @@ https://bugzilla.redhat.com/docs/en/html/api/Bugzilla/WebService/Bug.html'''
print(manpage)
+def _merge_field_opts(query, opt, parser):
+ # Add any custom fields if specified
+ if opt.fields is not None:
+ for f in opt.fields:
+ try:
+ f, v = f.split('=', 1)
+ query[f] = v
+ except:
+ parser.error("Invalid field argument provided: %s" % (f))
+
+
def _do_query(bz, opt, parser):
# Construct the query from the list of queryable options
q = dict()
@@ -689,6 +705,8 @@ def _do_query(bz, opt, parser):
savedsearch_sharer_id=getattr(opt, "savedsearch_sharer_id", None),
tags=getattr(opt, "tags", None))
+ _merge_field_opts(built_query, opt, parser)
+
built_query.update(q)
q = built_query
@@ -874,7 +892,7 @@ def _parse_triset(vallist, checkplus=True, checkminus=True, checkequal=True,
return add_val, rm_val, set_val
-def _do_new(bz, opt):
+def _do_new(bz, opt, parser):
# Parse options that accept comma separated list
def parse_multi(val):
return _parse_triset(val, checkplus=False, checkminus=False,
@@ -901,6 +919,8 @@ def _do_new(bz, opt):
sub_component=opt.sub_component or None,
)
+ _merge_field_opts(ret, opt, parser)
+
if opt.test_return_result:
return ret
@@ -994,14 +1014,7 @@ def _do_modify(bz, parser, opt, args):
if not v[0] and not v[1]:
del(wbmap[k])
- # Add any custom fields if specified
- if opt.fields is not None:
- for f in opt.fields:
- try:
- f, v = f.split('=', 1)
- update[f] = v
- except:
- parser.error("Invalid field argument provided: %s" % (f))
+ _merge_field_opts(update, opt, parser)
log.debug("update bug dict=%s", update)
log.debug("update flags dict=%s", flags)
@@ -1235,7 +1248,7 @@ def main(bzinstance=None):
elif action == 'new':
if args:
parser.error("Extra arguments '%s'" % args)
- buglist = _do_new(bz, opt)
+ buglist = _do_new(bz, opt, parser)
if opt.test_return_result:
return buglist
--
1.9.3
From: Arun Babu Neelicattu <abn(a)redhat.com>
- make the --field option available with new, modify and query commands
- refactor reused code relating to implementation of --field option
---
bin/bugzilla | 47 ++++++++++++++++++++++++++++++-----------------
1 file changed, 30 insertions(+), 17 deletions(-)
diff --git a/bin/bugzilla b/bin/bugzilla
index f7766ca..1a923a6 100755
--- a/bin/bugzilla
+++ b/bin/bugzilla
@@ -298,13 +298,6 @@ def setup_action_parser(action):
p.set_usage("%prog modify [options] BUGID [BUGID...]")
p.set_description("Modify one or more bugs.")
- p.add_option('--field',
- help="Modify a specified field. FIELD is expected to be \
- the raw name used by the bugzilla instance. No safety \
- checks are perfomed when using this option.",
- action="append", type="str", dest="fields",
- metavar="FIELD=VALUE")
-
bgrp = optparse.OptionGroup(p, "Bug details")
bgrp.add_option('--product',
help="Reassign bug to different product")
@@ -443,6 +436,18 @@ def setup_action_parser(action):
"section 'OUTPUT FORMAT' for more details.")
p.add_option_group(outg)
+ if action in ['new', 'query', 'modify']:
+ message = {
+ 'new': 'Set a specified field.',
+ 'query': 'Query a specified field.',
+ 'modify': 'Modify a specified field.'
+ }.get(action)
+ p.add_option('--field', help="%s FIELD is expected to be \
+ the raw name used by the bugzilla instance. No safety \
+ checks are perfomed when using this option." % (message),
+ action="append", type="str", dest="fields",
+ metavar="FIELD=VALUE")
+
# Used by unit tests, not for end user consumption
if action in ['new', 'query', 'modify']:
@@ -572,6 +577,17 @@ https://bugzilla.redhat.com/docs/en/html/api/Bugzilla/WebService/Bug.html'''
print(manpage)
+def _merge_field_opts(query, opt, parser):
+ # Add any custom fields if specified
+ if opt.fields is not None:
+ for f in opt.fields:
+ try:
+ f, v = f.split('=', 1)
+ query[f] = v
+ except:
+ parser.error("Invalid field argument provided: %s" % (f))
+
+
def _do_query(bz, opt, parser):
# Construct the query from the list of queryable options
q = dict()
@@ -689,6 +705,8 @@ def _do_query(bz, opt, parser):
savedsearch_sharer_id=getattr(opt, "savedsearch_sharer_id", None),
tags=getattr(opt, "tags", None))
+ _merge_field_opts(built_query, opt, parser)
+
built_query.update(q)
q = built_query
@@ -874,7 +892,7 @@ def _parse_triset(vallist, checkplus=True, checkminus=True, checkequal=True,
return add_val, rm_val, set_val
-def _do_new(bz, opt):
+def _do_new(bz, opt, parser):
# Parse options that accept comma separated list
def parse_multi(val):
return _parse_triset(val, checkplus=False, checkminus=False,
@@ -901,6 +919,8 @@ def _do_new(bz, opt):
sub_component=opt.sub_component or None,
)
+ _merge_field_opts(ret, opt, parser)
+
if opt.test_return_result:
return ret
@@ -994,14 +1014,7 @@ def _do_modify(bz, parser, opt, args):
if not v[0] and not v[1]:
del(wbmap[k])
- # Add any custom fields if specified
- if opt.fields is not None:
- for f in opt.fields:
- try:
- f, v = f.split('=', 1)
- update[f] = v
- except:
- parser.error("Invalid field argument provided: %s" % (f))
+ _merge_field_opts(built_query, opt, parser)
log.debug("update bug dict=%s", update)
log.debug("update flags dict=%s", flags)
@@ -1235,7 +1248,7 @@ def main(bzinstance=None):
elif action == 'new':
if args:
parser.error("Extra arguments '%s'" % args)
- buglist = _do_new(bz, opt)
+ buglist = _do_new(bz, opt, parser)
if opt.test_return_result:
return buglist
--
1.9.3
I'm trying to use the getbug() method of python-bugzilla to get more
details (extract additional fields) from specific bugs; however, I am
apparently missing something.
>>> import bugzilla
>>> bz = bugzilla.Bugzilla('https://bugzilla.redhat.com/xmlrpc.cgi')
>>> bz.login(user,password)
>>> bz.getbug('111111')
<Bug #111111 on https://bugzilla.redhat.com/xmlrpc.cgi at 0x175fd90>
>>> print bz.getbug('111111')
#111111 CLOSED - hp(a)redhat.com - libgnomeui should BuildRequires:
libjpeg-devel
>>> print bz.getbug('111111', include_fields=['cf_qa_whiteboard']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/bugzilla/base.py", line 983, in
getbug
exclude_fields=exclude_fields, extra_fields=extra_fields)
File "/usr/lib/python2.7/site-packages/bugzilla/base.py", line 976, in
_getbug
extra_fields=extra_fields)[0]
File "/usr/lib/python2.7/site-packages/bugzilla/base.py", line 951, in
_getbugs
bugdict = dict([(b['id'], b) for b in r['bugs']])
KeyError: 'id'
>>> print bz.getbug('111111',['cf_qa_whiteboard'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/bugzilla/base.py", line 983, in
getbug
exclude_fields=exclude_fields, extra_fields=extra_fields)
File "/usr/lib/python2.7/site-packages/bugzilla/base.py", line 976, in
_getbug
extra_fields=extra_fields)[0]
File "/usr/lib/python2.7/site-packages/bugzilla/base.py", line 951, in
_getbugs
bugdict = dict([(b['id'], b) for b in r['bugs']])
KeyError: 'id'
Appreciate any insight here.
Thanks!
--
[image: Eric Sammons on about.me]
Eric Sammons
about.me/ericsammons
<http://about.me/ericsammons>