[python-bugzilla] [PATCH] bugzilla: honor --cookiefile early so "login" follows it
Don Zickus
dzickus at redhat.com
Fri Apr 19 15:01:54 UTC 2013
On Thu, Apr 18, 2013 at 08:43:40PM +0200, Jan Pokorný wrote:
> So far, ~/.bugzillacookies was a cookie holder regardless of what
> cookiefile was specified together with "login" command.
This python seems to clever for some of us part-time python programmers.
Could we simplify it a little bit with something like the attached patch?
I assume all you want to be able to do is correctly choose a different
cookiefile using --cookiefile, right?
Cheers,
Don
diff --git a/bin/bugzilla b/bin/bugzilla
index cd518c0..b7b7f8d 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=None,
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..e573181 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 not cookiefile:
+ cookiefile=os.path.expanduser('~/.bugzillacookies')
self._cookiefobj = None
self._cookiejar = None
self._cookiefile = -1
More information about the python-bugzilla
mailing list