Skip to content

Commit

Permalink
* Use isinstance() instead of type()
Browse files Browse the repository at this point in the history
* update_bugs now understands single bug id, list or tuples of bugs
  • Loading branch information
kad committed Mar 26, 2008
1 parent c468d55 commit a06bf15
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
36 changes: 27 additions & 9 deletions bugzilla/BugzillaSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def __init__(self, baseurl, use_cache=True):
self._password = None
self._login_dict = None
if use_cache:
if type(use_cache) == types.DictType:
if isinstance(use_cache, types.DictType):
self._bug_cache = use_cache
else:
self._bug_cache = {}
Expand Down Expand Up @@ -198,6 +198,10 @@ def comment_bugs(self, bugs, comment):
def update_bugs(self, bugs, params = None):
"""
Group update operation for bugs.
Possible bugs specifications:
id -- single bug id (integer)
[id,id,id] or (id,id,id) -- List of bug IDs
"id,id,id" -- List of bugs, alternative way (string)
params should be non-empty dictionary with valid bugzilla update form fields
"""
reqdict = { 'dontchange': 'dont_change',
Expand All @@ -217,14 +221,24 @@ def update_bugs(self, bugs, params = None):
'keywords': '',
'keywordaction': 'add',
'knob': 'none' }
if type(params) == types.DictType and params:
if isinstance(params, types.DictType) and params:
reqdict.update(params)
else:
return "Not valid params dictionary"
if self._login_dict:
reqdict.update(self._login_dict)
for bug in bugs:
reqdict['id_' + bug] = bug

if isinstance(bugs, (types.ListType, types.TupleType)):
# List of bugs
lbugs = bugs
elif isinstance(bugs, types.StringType):
# String ? Hmm, assume as list of bugs separated by ','
lbugs = re.split("\s*,\s*", bugs)
elif isinstance(params, types.IntType):
# Just one bug id
lbugs = [ str(bugs) ]
for bug in lbugs:
reqdict['id_' + str(bug)] = str(bug)
_result = StringIO.StringIO()
self._curl.setopt(pycurl.URL, os.path.join(self._baseurl, "process_bug.cgi"))
self._curl.setopt(pycurl.POST, 1)
Expand Down Expand Up @@ -253,7 +267,8 @@ def fetch_buglist_csv(self, params):
"""
Fetches csv from buglist.cgi.
Possible parameters:
[id,id,id] -- List of bug IDs
id -- single bug id (integer)
[id,id,id] or (id,id,id) -- List of bug IDs
"id,id,id" -- List of bugs, alternative way (string)
{'bugzilla_internal_param1': 'value',...} -- advanced parameters to request
"""
Expand All @@ -262,13 +277,16 @@ def fetch_buglist_csv(self, params):
'columnlist': 'all'}
if self._login_dict:
reqdict.update(self._login_dict)
if type(params) == types.ListType:
if isinstance(params, (types.ListType, types.TupleType)):
# List of bugs
reqdict['bug_id'] = ",".join([str(bug) for bug in params])
elif type(params) == types.StringType:
elif isinstance(params, types.StringType):
# String ? Hmm, assume as list of bugs separated by ','
reqdict['bug_id'] = params
elif type(params) == types.DictType:
elif isinstance(params, types.IntType):
# Just one bug id
reqdict['bug_id'] = str(params)
elif isinstance(params, types.DictType):
# Some advanced query
reqdict.update(params)
else:
Expand Down Expand Up @@ -296,7 +314,7 @@ def fetch_buglist_info(self, params):

def showbug_url(self, bug):
""" Returns link to showbug.cgi, with a parameter of bug """
if type(bug) == types.ListType:
if isinstance(bug, (types.ListType, types.TupleType)):
return [self.showbug_url(obg) for obg in bug]
else:
return os.path.join(self._baseurl, "show_bug.cgi?id=%s" % urllib.quote(str(bug)))
Expand Down
2 changes: 2 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
python-bugzilla (0.9) unstable; urgency=low

* Bugzilla 3.0.x: Don't fetch attachment data by default in fetch_bug_xml
* Use isinstance() instead of type()
* update_bugs now understands single bug id, list or tuples of bugs

-- Alexandr D. Kanevskiy <[email protected]> Tue, 25 Mar 2008 22:43:50 +0200

Expand Down

0 comments on commit a06bf15

Please sign in to comment.