[packagedb-cli: 2/2] Merge pull request #43 from fedora-infra/bz_login
by Pierre-YvesChibon
commit 6ba8ee987a5627a37eb31280c7bbb9e920753648
Merge: 65c71d7 552bd4a
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Wed Oct 7 16:54:54 2015 +0200
Merge pull request #43 from fedora-infra/bz_login
Adjust the way we interact with bugzilla to handle the recent changes
pkgdb2client/utils.py | 22 ++++++++++++++++++----
1 files changed, 18 insertions(+), 4 deletions(-)
---
8 years, 7 months
[packagedb-cli: 1/2] Adjust the way we interact with bugzilla to handle the recent changes
by Pierre-YvesChibon
commit 552bd4a340065317eaee6fae4dbd7690154eea9b
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Wed Oct 7 14:33:45 2015 +0200
Adjust the way we interact with bugzilla to handle the recent changes
bugzilla.redhat.com recently changed to warn very early if the credentials
provided or stored on disk became invalid.
It will nowadays throw an exception.
With this code we avoid raising an exception early and ensure we are
logged in when we instantiate the bugzilla object.
pkgdb2client/utils.py | 22 ++++++++++++++++++----
1 files changed, 18 insertions(+), 4 deletions(-)
---
diff --git a/pkgdb2client/utils.py b/pkgdb2client/utils.py
index 7049df4..b2fd87e 100644
--- a/pkgdb2client/utils.py
+++ b/pkgdb2client/utils.py
@@ -24,6 +24,7 @@ from datetime import datetime
import requests
import fedora_cert
+import xmlrpclib
from bugzilla import Bugzilla
from fedora.client import AccountSystem, AuthError
@@ -37,16 +38,30 @@ except fedora_cert.fedora_cert_error:
USERNAME = None
RH_BZ_API = 'https://bugzilla.redhat.com/xmlrpc.cgi'
-BZCLIENT = Bugzilla(url=RH_BZ_API)
+BZCLIENT = None
FASCLIENT = AccountSystem(
'https://admin.fedoraproject.org/accounts',
username=USERNAME)
+def _get_bz():
+ ''' Return a bugzilla object. '''
+ if not BZCLIENT:
+ try:
+ global BZCLIENT
+ BZCLIENT= Bugzilla(url=RH_BZ_API)
+ BZCLIENT.logged_in
+ except xmlrpclib.Error, err:
+ bz_login()
+
+ return BZCLIENT
+
+
def bz_login():
''' Login on bugzilla. '''
print 'To keep going, we need to authenticate against bugzilla' \
' at {0}'.format(RH_BZ_API)
+
username = raw_input("Bugzilla user: ")
password = getpass.getpass("Bugzilla password: ")
BZCLIENT.login(username, password)
@@ -58,6 +73,7 @@ def get_bugz(pkg_name):
:arg pkg_name: the name of the package to look-up in bugzilla
'''
+ BZCLIENT = _get_bz()
bugbz = BZCLIENT.query(
{'bug_status': ['NEW', 'ASSIGNED', 'NEEDINFO'],
@@ -75,11 +91,9 @@ def get_bug(bugid):
on the specified ticket
'''
+ BZCLIENT = _get_bz()
bug = BZCLIENT.getbug(bugid)
- if '@' not in bug.creator:
- bz_login()
- bug = BZCLIENT.getbug(bugid)
return bug
8 years, 7 months