Skip to content

Commit 6a16ed5

Browse files
committed
Try and clarify the official API bits in __init__
Export BugzillaError but remove the other exceptions which were barely used.
1 parent 27ba081 commit 6a16ed5

4 files changed

Lines changed: 44 additions & 40 deletions

File tree

bugzilla/__init__.py

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,12 @@
1818
log = logging.getLogger("bugzilla")
1919

2020

21+
from bugzilla.base import BugzillaError
2122
from bugzilla.bugzilla3 import Bugzilla3, Bugzilla32, Bugzilla34, Bugzilla36
22-
from bugzilla.bugzilla4 import Bugzilla4
23+
from bugzilla.bugzilla4 import Bugzilla4, Bugzilla42, Bugzilla44
2324
from bugzilla.nvlbugzilla import NovellBugzilla
2425
from bugzilla.rhbugzilla import RHBugzilla, RHBugzilla3, RHBugzilla4
2526

26-
# advertised class list
27-
classlist = ['Bugzilla3', 'Bugzilla32', 'Bugzilla34',
28-
'Bugzilla36', 'Bugzilla4', 'RHBugzilla3', 'RHBugzilla4',
29-
'NovellBugzilla']
30-
31-
32-
3327

3428
def getBugzillaClassForURL(url):
3529
log.debug("Choosing subclass for %s" % url)
@@ -60,10 +54,16 @@ def getBugzillaClassForURL(url):
6054
# note preference order: RHBugzilla* wins if available
6155
if rhbz:
6256
c = RHBugzilla
63-
else:
64-
if bzversion.startswith("4."):
57+
elif bzversion.startswith("4."):
58+
if bzversion.startswith("4.0"):
6559
c = Bugzilla4
66-
elif bzversion.startswith('3.6'):
60+
elif bzversion.startswith("4.2"):
61+
c = Bugzilla42
62+
else:
63+
log.debug("No explicit match for %s, using latest bz4" % bzversion)
64+
c = Bugzilla44
65+
else:
66+
if bzversion.startswith('3.6'):
6767
c = Bugzilla36
6868
elif bzversion.startswith('3.4'):
6969
c = Bugzilla34
@@ -77,9 +77,11 @@ def getBugzillaClassForURL(url):
7777

7878

7979
class Bugzilla(object):
80-
'''Magical Bugzilla class that figures out which Bugzilla implementation
80+
'''
81+
Magical Bugzilla class that figures out which Bugzilla implementation
8182
to use and uses that. Requires 'url' parameter so we can check available
82-
XMLRPC methods to determine the Bugzilla version.'''
83+
XMLRPC methods to determine the Bugzilla version.
84+
'''
8385
def __init__(self, **kwargs):
8486
log.info("Bugzilla v%s initializing" % __version__)
8587
if 'url' not in kwargs:
@@ -89,10 +91,28 @@ def __init__(self, **kwargs):
8991
# Use of __init__ of non parent class
9092

9193
c = getBugzillaClassForURL(kwargs['url'])
94+
if not c:
95+
raise ValueError("Couldn't determine Bugzilla version for %s" %
96+
kwargs['url'])
97+
9298
if c:
9399
self.__class__ = c
94100
c.__init__(self, **kwargs)
95101
log.info("Chose subclass %s v%s" % (c.__name__, c.version))
96-
else:
97-
raise ValueError("Couldn't determine Bugzilla version for %s" %
98-
kwargs['url'])
102+
103+
# This is the list of possible Bugzilla instances an app can use,
104+
# bin/bugzilla uses it for the --bztype field
105+
classlist = [
106+
"Bugzilla3", "Bugzilla32", "Bugzilla34", "Bugzilla36",
107+
"Bugzilla4", "Bugzilla42", "Bugzilla44",
108+
"RHBugzilla3", "RHBugzilla4", "RHBugzilla",
109+
"NovellBugzilla",
110+
]
111+
112+
# This is the public API. If you are explicitly instantiating any other
113+
# class, using some function, or poking into internal files, don't complain
114+
# if things break on you.
115+
__all__ = classlist + [
116+
'BugzillaError',
117+
'Bugzilla',
118+
]

bugzilla/base.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,6 @@ class BugzillaError(Exception):
2525
pass
2626

2727

28-
class NeedSyncError(BugzillaError):
29-
'''Must save data from this class to the bugzilla server before using this.
30-
'''
31-
pass
32-
33-
34-
class NeedParamError(BugzillaError):
35-
'''A necessary parameter was left out.'''
36-
pass
37-
38-
39-
class LoadError(BugzillaError):
40-
'''Error loading credentials'''
41-
pass
42-
43-
4428
def replace_getbug_errors_with_None(rawlist):
4529
'''r is a raw xmlrpc response.
4630
If it represents an error, None is returned.
@@ -1370,7 +1354,7 @@ def updateperms(self, action, groups):
13701354
:arg groups: list of groups to be added to (i.e. ['fedora_contrib'])
13711355
'''
13721356
if self._name_dirty:
1373-
raise NeedSyncError('name has been changed. run update() before'
1357+
raise BugzillaError('name has been changed. run update() before'
13741358
' updating perms.')
13751359
self.bugzilla._updateperms(self.name, action, groups)
13761360

bugzilla/bugzilla3.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
# option) any later version. See http://www.gnu.org/copyleft/gpl.html for
1010
# the full text of the license.
1111

12-
import bugzilla.base
12+
from bugzilla import BugzillaError
13+
from bugzilla.base import BugzillaBase
1314

1415

15-
class Bugzilla3(bugzilla.base.BugzillaBase):
16+
class Bugzilla3(BugzillaBase):
1617
'''Concrete implementation of the Bugzilla protocol. This one uses the
1718
methods provided by standard Bugzilla 3.0.x releases.'''
1819

@@ -21,7 +22,7 @@ class Bugzilla3(bugzilla.base.BugzillaBase):
2122
bz_ver_minor = 0
2223

2324
def __init__(self, **kwargs):
24-
bugzilla.base.BugzillaBase.__init__(self, **kwargs)
25+
BugzillaBase.__init__(self, **kwargs)
2526

2627
def _login(self, user, password):
2728
'''Backend login method for Bugzilla3'''
@@ -177,8 +178,8 @@ def _getusers(self, ids=None, names=None, match=None):
177178
if match:
178179
params['match'] = match
179180
if not params:
180-
raise bugzilla.base.NeedParamError('_get() needs one of ids, '
181-
' names, or match kwarg.')
181+
raise BugzillaError('_get() needs one of ids, '
182+
' names, or match kwarg.')
182183

183184
return self._proxy.User.get(params)
184185

bugzilla/nvlbugzilla.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
import urllib2
1818
import urlparse
1919

20-
from bugzilla import Bugzilla32, log
21-
from bugzilla.base import BugzillaError
20+
from bugzilla import BugzillaError, Bugzilla32, log
2221

2322

2423
class NovellBugzilla(Bugzilla32):

0 commit comments

Comments
 (0)