blob: dfda0c43a1627afd3766bcab5d102bc5803b0dc0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# python-bugzilla - a Python interface to bugzilla using xmlrpclib.
#
# Copyright (C) 2007,2008 Red Hat Inc.
# Author: Will Woods <wwoods@redhat.com>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version. See http://www.gnu.org/copyleft/gpl.html for
# the full text of the license.
from bugzilla3 import Bugzilla3, Bugzilla32
from rhbugzilla import RHBugzilla, RHBugzilla3
from base import version
import xmlrpclib
import logging
log = logging.getLogger("bugzilla")
def getBugzillaClassForURL(url):
log.debug("Choosing subclass for %s" % url)
s = xmlrpclib.ServerProxy(url)
rhbz = False
bzversion = ''
c = None
# Check for a RH-only method
try:
log.debug("Checking for RH Bugzilla method bugzilla.getProdInfo()")
prodinfo = s.bugzilla.getProdInfo()
rhbz = True
except xmlrpclib.Fault:
pass
log.debug("rhbz=%s" % str(rhbz))
# Try to get the bugzilla version string
try:
log.debug("Checking return value of Buzilla.version()")
r = s.Bugzilla.version()
bzversion = r['version']
except xmlrpclib.Fault:
pass
log.debug("bzversion='%s'" % str(bzversion))
# current preference order: RHBugzilla, Bugzilla3
# RH BZ 3.2 will have rhbz == True and bzversion == 3.1.x or 3.2.x.
# To prefer Bugzilla32 over RHBugzilla do: if rhbz and (bzversion == '')
if rhbz:
if bzversion.startswith('3.'):
c = RHBugzilla3
else:
c = RHBugzilla
elif bzversion.startswith('3.'):
if bzversion.startswith('3.0'):
c = Bugzilla3
else: # 3.1 or higher
c = Bugzilla32
return c
class Bugzilla(object):
'''Magical Bugzilla class that figures out which Bugzilla implementation
to use and uses that.'''
def __init__(self,**kwargs):
log.info("Bugzilla v%s initializing" % base.version)
if 'url' in kwargs:
c = getBugzillaClassForURL(kwargs['url'])
if c:
self.__class__ = c
c.__init__(self,**kwargs)
log.info("Chose subclass %s v%s" % (c.__name__,c.version))
# FIXME no url? raise an error or something here, jeez
|