commit 0c6bbe9a984f4a1a53c3f579e99de48af0746f20 Author: Pierre-Yves Chibon pingou@pingoured.fr Date: Mon Nov 24 11:20:14 2014 +0100
Rework the get_bug method to ask for login only if needed
Before calling bugzilla we do not know if the user can log in or not. We could call .login() but that would require asking the user for his/her username and password everytime. So instead we query bugzilla once, and based on the output we determine if we need to call .login() or not (as bugzilla stores a token on disk credentials are not necessary for every calls).
pkgdb2client/utils.py | 19 +++++++++---------- 1 files changed, 9 insertions(+), 10 deletions(-) --- diff --git a/pkgdb2client/utils.py b/pkgdb2client/utils.py index a6e4edb..be7352e 100644 --- a/pkgdb2client/utils.py +++ b/pkgdb2client/utils.py @@ -59,21 +59,20 @@ def get_bugz(pkg_name): return bugbz
-def get_bug(bugid, login=False): +def get_bug(bugid): ''' Return the bug with the specified identifier.
:arg bugid: the identifier of the bug to retrieve - :kwarg login: a boolean specifying whether to retrieve the information - about this bug with a user logged in or not. :returns: the list of the people (their email address) that commented on the specified ticket
'''
- if login and not BZCLIENT.logged_in: + bug = BZCLIENT.getbug(bugid) + if not '@' in bug.creator: bz_login() - - return BZCLIENT.getbug(bugid) + bug = BZCLIENT.getbug(bugid) + return bug
def get_users_in_bug(bugid): @@ -86,9 +85,9 @@ def get_users_in_bug(bugid):
'''
- if isinstance(bugid, (int, basestring)): - bugbz = get_bug(bugid, login=True) - else: + try: + bugbz = get_bug(int(bugid)) + except ValueError: bugbz = bugid users = set([com['author'] for com in bugbz.comments]) users.add(bugbz.creator) @@ -155,7 +154,7 @@ def check_package_creation(info, bugid): FASCLIENT.username = username FASCLIENT.password = password
- bug = get_bug(bugid, login=True) + bug = get_bug(bugid)
# Check if the title of the bug fits the expectations expected = 'Review Request: {0} - {1}'.format(
packagedb-cli-commits@lists.stg.fedorahosted.org