[python-bugzilla] [PATCH V2] bugzilla: use passed in cookies correctly

Don Zickus dzickus at redhat.com
Mon Apr 22 18:55:22 UTC 2013


When using the option --cookiefile for bugzilla, the cookiefile
override happens to late.  Use the passed in file during the
beginning of init.

This is addressed by defaulting the cookiefile to None to simplify
the passed in argument code.  Then the Bugzilla init routine assigns
the default of ~/.bugzillacookies if cookiefile is None.

This shouldn't affect any of the other scripts that do not use the
cookiefile as an arg.

V2: switch default from None to '' as None means use tempfile

Reported-by: Jan Pokorný <jpokorny at redhat.com>
Signed-off-by: Don Zickus <dzickus at redhat.com>
---
 bin/bugzilla     |   11 ++++-------
 bugzilla/base.py |    5 +++--
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/bin/bugzilla b/bin/bugzilla
index cd518c0..190f9db 100755
--- a/bin/bugzilla
+++ b/bin/bugzilla
@@ -94,7 +94,7 @@ def setup_parser():
             help="username")
     p.add_option('--password',
             help="password")
-    p.add_option('--cookiefile',
+    p.add_option('--cookiefile', default='',
             help="cookie file to use for bugzilla authentication")
     p.add_option('--verbose', action='store_true',
             help="give more info about what's going on")
@@ -900,7 +900,7 @@ def main(bzinstance=None):
     if bzinstance:
         bz = bzinstance
     else:
-        bz = bzclass(url=global_opt.bugzilla)
+        bz = bzclass(url=global_opt.bugzilla, cookiefile=global_opt.cookiefile)
 
 
     # Handle 'login' action
@@ -933,11 +933,8 @@ def main(bzinstance=None):
         log.info('Using username/password for authentication')
         bz.login(global_opt.user, global_opt.password)
     elif not _is_unittest:
-        if global_opt.cookiefile:
-            bz.cookiefile = global_opt.cookiefile
-        cookiefile = bz.cookiefile
-        if os.path.exists(cookiefile):
-            log.info('Using cookies in %s for authentication', cookiefile)
+        if os.path.exists(bz.cookiefile):
+            log.info('Using cookies in %s for authentication', bz.cookiefile)
         else:
             log.info('No authentication info provided.')
 
diff --git a/bugzilla/base.py b/bugzilla/base.py
index c2b9295..e90c18a 100644
--- a/bugzilla/base.py
+++ b/bugzilla/base.py
@@ -187,13 +187,14 @@ class BugzillaBase(object):
             url = url + '/xmlrpc.cgi'
         return url
 
-    def __init__(self, url=None, user=None, password=None,
-            cookiefile=os.path.expanduser('~/.bugzillacookies')):
+    def __init__(self, url=None, user=None, password=None, cookiefile=None):
         # Settings the user might want to tweak
         self.user = user or ''
         self.password = password or ''
         self.url = ''
 
+        if cookiefile is '':
+            cookiefile = os.path.expanduser('~/.bugzillacookies')
         self._cookiefobj = None
         self._cookiejar = None
         self._cookiefile = -1
-- 
1.7.1



More information about the python-bugzilla mailing list