@@ -109,6 +109,28 @@ def _build_cookiejar(cookiefile):
109109 cookiefile )
110110
111111
112+ _default_configpaths = [
113+ '/etc/bugzillarc' ,
114+ '~/.bugzillarc' ,
115+ '~/.config/python-bugzilla/bugzillarc' ,
116+ ]
117+
118+
119+ def _open_bugzillarc (configpaths = - 1 ):
120+ if configpaths == - 1 :
121+ configpaths = _default_configpaths [:]
122+
123+ configpaths = [os .path .expanduser (p ) for p in
124+ Bugzilla ._listify (configpaths )]
125+ cfg = SafeConfigParser ()
126+ read_files = cfg .read (configpaths )
127+ if not read_files :
128+ return
129+
130+ log .info ("Found bugzillarc files: %s" , read_files )
131+ return cfg
132+
133+
112134class _FieldAlias (object ):
113135 """
114136 Track API attribute names that differ from what we expose in users.
@@ -220,6 +242,15 @@ def fix_url(url):
220242 url = url + '/xmlrpc.cgi'
221243 return url
222244
245+ @staticmethod
246+ def _listify (val ):
247+ if val is None :
248+ return val
249+ if isinstance (val , list ):
250+ return val
251+ return [val ]
252+
253+
223254 def __init__ (self , url = - 1 , user = None , password = None , cookiefile = - 1 ,
224255 sslverify = True , tokenfile = - 1 , use_creds = True , api_key = None ):
225256 """
@@ -267,8 +298,7 @@ def __init__(self, url=-1, user=None, password=None, cookiefile=-1,
267298 self ._field_aliases = []
268299 self ._init_field_aliases ()
269300
270- self .configpath = ['/etc/bugzillarc' , '~/.bugzillarc' ,
271- '~/.config/python-bugzilla/bugzillarc' ]
301+ self .configpath = _default_configpaths [:]
272302 if not use_creds :
273303 cookiefile = None
274304 tokenfile = None
@@ -360,13 +390,6 @@ def _check_version(self, major, minor):
360390 return True
361391 return False
362392
363- def _listify (self , val ):
364- if val is None :
365- return val
366- if isinstance (val , list ):
367- return val
368- return [val ]
369-
370393 def _product_id_to_name (self , productid ):
371394 '''Convert a product ID (int) to a product name (str).'''
372395 for p in self .products :
@@ -448,24 +471,16 @@ def readconfig(self, configpath=None):
448471 api_key = key
449472
450473 The file can have multiple sections for different bugzilla instances.
451- You can also use the [DEFAULT] section to set defaults that apply to
452- any site without a specific section of its own .
474+ A 'url' field in the [DEFAULT] section can be used to set a default
475+ URL for the bugzilla command line tool .
453476
454477 Be sure to set appropriate permissions on bugzillarc if you choose to
455478 store your password in it!
456479 """
457- if not configpath :
458- configpath = self .configpath
459-
460- configpath = [os .path .expanduser (p ) for p in
461- self ._listify (configpath )]
462- cfg = SafeConfigParser ()
463- read_files = cfg .read (configpath )
464- if not read_files :
480+ cfg = _open_bugzillarc (configpath or self .configpath )
481+ if not cfg :
465482 return
466483
467- log .info ("Found bugzillarc files: %s" , read_files )
468-
469484 section = ""
470485 log .debug ("bugzillarc: Searching for config section matching %s" ,
471486 self .url )
0 commit comments