2003-10-20 21:56:17 +02:00
|
|
|
###
|
|
|
|
# Copyright (c) 2003, Daniel Berlin
|
|
|
|
# Based on code from kibot
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are met:
|
|
|
|
#
|
|
|
|
# * Redistributions of source code must retain the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
# * Neither the name of the author of this software nor the name of
|
|
|
|
# contributors to this software may be used to endorse or promote products
|
|
|
|
# derived from this software without specific prior written consent.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
###
|
2003-10-28 06:50:40 +01:00
|
|
|
|
2003-10-20 21:56:17 +02:00
|
|
|
"""
|
|
|
|
Bugzilla bug retriever
|
|
|
|
"""
|
2003-10-28 06:50:40 +01:00
|
|
|
|
2003-11-26 19:21:12 +01:00
|
|
|
__revision__ = "$Id$"
|
|
|
|
|
2003-10-28 06:50:40 +01:00
|
|
|
import os
|
|
|
|
import re
|
2004-01-20 08:11:00 +01:00
|
|
|
import csv
|
|
|
|
import getopt
|
2003-12-12 23:41:50 +01:00
|
|
|
import urllib
|
2003-10-28 06:50:40 +01:00
|
|
|
import xml.dom.minidom as minidom
|
2004-01-20 08:11:00 +01:00
|
|
|
|
2003-11-15 05:37:04 +01:00
|
|
|
from itertools import imap, ifilter
|
2003-10-22 17:20:06 +02:00
|
|
|
from htmlentitydefs import entitydefs as entities
|
2004-01-20 08:11:00 +01:00
|
|
|
|
|
|
|
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.conf as conf
|
|
|
|
import supybot.utils as utils
|
|
|
|
import supybot.plugins as plugins
|
2004-10-15 15:28:27 +02:00
|
|
|
from supybot.commands import *
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.ircutils as ircutils
|
|
|
|
import supybot.privmsgs as privmsgs
|
2004-07-29 08:58:42 +02:00
|
|
|
import supybot.registry as registry
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.webutils as webutils
|
|
|
|
import supybot.callbacks as callbacks
|
|
|
|
import supybot.structures as structures
|
2003-10-20 21:56:17 +02:00
|
|
|
|
2004-01-04 14:49:51 +01:00
|
|
|
statusKeys = ['unconfirmed', 'new', 'assigned', 'reopened', 'resolved',
|
|
|
|
'verified', 'closed']
|
|
|
|
resolutionKeys = ['fixed', 'invalid', 'worksforme', 'needinfo',
|
|
|
|
'test-request', 'wontfix', 'cantfix', 'moved', 'duplicate',
|
|
|
|
'remind', 'later', 'notabug', 'notgnome', 'incomplete',
|
|
|
|
'gnome1.x', 'moved']
|
|
|
|
priorityKeys = ['p1', 'p2', 'p3', 'p4', 'p5', 'Low', 'Normal', 'High',
|
|
|
|
'Immediate', 'Urgent']
|
|
|
|
severityKeys = ['enhancement', 'trivial', 'minor', 'normal', 'major',
|
|
|
|
'critical', 'blocker']
|
|
|
|
|
2003-11-11 15:14:34 +01:00
|
|
|
class BugzillaError(Exception):
|
2003-10-20 21:56:17 +02:00
|
|
|
"""A bugzilla error"""
|
2003-11-08 09:01:34 +01:00
|
|
|
pass
|
2003-10-20 21:56:17 +02:00
|
|
|
|
2004-01-30 00:58:27 +01:00
|
|
|
def configure(advanced):
|
2004-07-25 20:24:51 +02:00
|
|
|
from supybot.questions import output, expect, anything, yn
|
2004-01-28 23:19:25 +01:00
|
|
|
conf.registerPlugin('Bugzilla', True)
|
2004-01-31 23:24:43 +01:00
|
|
|
output("""The Bugzilla plugin has the functionality to watch for URLs
|
|
|
|
that match a specific pattern (we call this a snarfer). When
|
2004-08-19 15:33:34 +02:00
|
|
|
a Supybot sees such a URL, it will parse the web page for
|
2004-01-31 23:24:43 +01:00
|
|
|
information and reply with the results.""")
|
|
|
|
if yn('Do you want this bug snarfer enabled by default?', default=False):
|
2004-01-20 08:11:00 +01:00
|
|
|
conf.supybot.plugins.Bugzilla.bugSnarfer.setValue(True)
|
2003-10-20 21:56:17 +02:00
|
|
|
|
2004-01-20 08:11:00 +01:00
|
|
|
conf.registerPlugin('Bugzilla')
|
|
|
|
conf.registerChannelValue(conf.supybot.plugins.Bugzilla, 'bugSnarfer',
|
|
|
|
registry.Boolean(False, """Determines whether the bug snarfer will be
|
2004-08-19 07:33:15 +02:00
|
|
|
enabled, such that any Bugzilla URLs and bug ### seen in the channel
|
|
|
|
will have their information reported into the channel."""))
|
2004-01-20 08:11:00 +01:00
|
|
|
conf.registerChannelValue(conf.supybot.plugins.Bugzilla, 'bold',
|
|
|
|
registry.Boolean(True, """Determines whether results are bolded."""))
|
2004-01-26 16:35:29 +01:00
|
|
|
conf.registerChannelValue(conf.supybot.plugins.Bugzilla, 'replyNoBugzilla',
|
2004-01-20 08:57:40 +01:00
|
|
|
registry.String('I don\'t have a bugzilla %r.', """Determines the phrase
|
|
|
|
to use when notifying the user that there is no information about that
|
|
|
|
bugzilla site."""))
|
2004-08-19 07:29:56 +02:00
|
|
|
conf.registerChannelValue(conf.supybot.plugins.Bugzilla, 'snarfTarget',
|
|
|
|
registry.String('', """Determines the bugzilla site to query when the
|
|
|
|
snarf command is triggered"""))
|
2004-01-04 14:49:51 +01:00
|
|
|
|
2004-07-29 08:58:42 +02:00
|
|
|
class Bugzillae(registry.SpaceSeparatedListOfStrings):
|
|
|
|
List = ircutils.IrcSet
|
2004-10-15 15:28:27 +02:00
|
|
|
|
2004-07-29 08:58:42 +02:00
|
|
|
conf.registerGlobalValue(conf.supybot.plugins.Bugzilla, 'bugzillae',
|
2004-08-19 01:15:27 +02:00
|
|
|
Bugzillae([], """Determines what bugzillae will be added to the bot when it
|
2004-07-29 08:58:42 +02:00
|
|
|
starts."""))
|
|
|
|
|
|
|
|
def registerBugzilla(name, url='', description=''):
|
|
|
|
conf.supybot.plugins.Bugzilla.bugzillae().add(name)
|
|
|
|
group = conf.registerGroup(conf.supybot.plugins.Bugzilla.bugzillae, name)
|
|
|
|
URL = conf.registerGlobalValue(group, 'url', registry.String(url, ''))
|
|
|
|
DESC = conf.registerGlobalValue(group, 'description',
|
|
|
|
registry.String(description, ''))
|
|
|
|
if url:
|
|
|
|
URL.setValue(url)
|
|
|
|
if description:
|
|
|
|
DESC.setValue(description)
|
|
|
|
|
2004-01-20 08:11:00 +01:00
|
|
|
class Bugzilla(callbacks.PrivmsgCommandAndRegexp):
|
2003-10-20 21:56:17 +02:00
|
|
|
"""Show a link to a bug report with a brief description"""
|
|
|
|
threaded = True
|
2004-09-10 08:36:27 +02:00
|
|
|
callBefore = ['URL']
|
2004-08-19 07:29:56 +02:00
|
|
|
regexps = ['bzSnarfer', 'bugzSnarf']
|
2004-01-20 08:11:00 +01:00
|
|
|
|
2003-10-20 21:56:17 +02:00
|
|
|
def __init__(self):
|
2003-10-22 17:20:06 +02:00
|
|
|
callbacks.PrivmsgCommandAndRegexp.__init__(self)
|
|
|
|
self.entre = re.compile('&(\S*?);')
|
2003-11-11 15:14:34 +01:00
|
|
|
# Schema: {name, [url, description]}
|
2004-07-29 08:58:42 +02:00
|
|
|
self.db = ircutils.IrcDict()
|
|
|
|
for name in self.registryValue('bugzillae'):
|
|
|
|
registerBugzilla(name)
|
|
|
|
group = self.registryValue('bugzillae.%s' % name, value=False)
|
|
|
|
self.db[name] = [group.url(), group.description()]
|
2003-11-11 15:14:34 +01:00
|
|
|
self.shorthand = utils.abbrev(self.db.keys())
|
2003-10-20 21:56:17 +02:00
|
|
|
|
2003-12-12 23:41:50 +01:00
|
|
|
def keywords2query(self, keywords):
|
|
|
|
"""Turn a list of keywords into a URL query string"""
|
|
|
|
query = []
|
|
|
|
for k in keywords:
|
|
|
|
k = k.lower()
|
|
|
|
if k in statusKeys:
|
|
|
|
query.append('bug_status=%s' % k.upper())
|
|
|
|
elif k in resolutionKeys:
|
|
|
|
query.append('resolution=%s' % k.upper())
|
|
|
|
elif k in priorityKeys:
|
|
|
|
query.append('priority=%s' % k.upper())
|
|
|
|
elif k in severityKeys:
|
|
|
|
query.append('bug_severity=%s' % k.upper())
|
|
|
|
query.append('ctype=csv')
|
|
|
|
return query
|
2004-01-11 15:47:44 +01:00
|
|
|
|
2004-10-15 15:28:27 +02:00
|
|
|
def add(self, irc, msg, args, name, url, description):
|
2004-07-31 10:05:46 +02:00
|
|
|
"""<name> <url> [<description>]
|
2003-11-01 00:53:35 +01:00
|
|
|
|
2003-11-11 15:14:34 +01:00
|
|
|
Add a bugzilla <url> to the list of defined bugzillae. <name>
|
2004-08-19 01:15:27 +02:00
|
|
|
is the name that will be used to reference the bugzilla in all
|
2003-11-11 15:14:34 +01:00
|
|
|
commands. Unambiguous abbreviations of <name> will be accepted also.
|
|
|
|
<description> is the common name for the bugzilla and will
|
2004-07-31 10:05:46 +02:00
|
|
|
be listed with the bugzilla query; if not given, it defaults to <name>.
|
2003-11-08 09:01:34 +01:00
|
|
|
"""
|
2004-07-31 10:05:46 +02:00
|
|
|
if not description:
|
|
|
|
description = name
|
2003-11-17 20:57:07 +01:00
|
|
|
if url[-1] == '/':
|
|
|
|
url = url[:-1]
|
2003-11-11 15:14:34 +01:00
|
|
|
self.db[name] = [url, description]
|
2004-07-29 08:58:42 +02:00
|
|
|
registerBugzilla(name, url, description)
|
2003-11-11 15:14:34 +01:00
|
|
|
self.shorthand = utils.abbrev(self.db.keys())
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.replySuccess()
|
2004-10-15 15:28:27 +02:00
|
|
|
add = wrap(add, ['text', 'url', additional('text')])
|
2003-10-20 21:56:17 +02:00
|
|
|
|
2004-10-15 15:28:27 +02:00
|
|
|
def remove(self, irc, msg, args, name):
|
2003-11-01 00:53:35 +01:00
|
|
|
"""<abbreviation>
|
|
|
|
|
|
|
|
Remove the bugzilla associated with <abbreviation> from the list of
|
|
|
|
defined bugzillae.
|
2003-11-08 09:01:34 +01:00
|
|
|
"""
|
2003-11-11 15:14:34 +01:00
|
|
|
try:
|
|
|
|
name = self.shorthand[name]
|
|
|
|
del self.db[name]
|
2004-07-29 08:58:42 +02:00
|
|
|
self.registryValue('bugzillae').remove(name)
|
2003-11-11 15:14:34 +01:00
|
|
|
self.shorthand = utils.abbrev(self.db.keys())
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.replySuccess()
|
2003-11-11 15:14:34 +01:00
|
|
|
except KeyError:
|
2004-01-21 02:33:59 +01:00
|
|
|
s = self.registryValue('replyNoBugzilla', msg.args[0])
|
2004-01-20 08:57:40 +01:00
|
|
|
irc.error(s % name)
|
2004-10-15 15:28:27 +02:00
|
|
|
remove = wrap(remove, ['text'])
|
2003-10-20 21:56:17 +02:00
|
|
|
|
2004-10-15 15:28:27 +02:00
|
|
|
def list(self, irc, msg, args, name):
|
2003-11-01 00:53:35 +01:00
|
|
|
"""[<abbreviation>]
|
|
|
|
|
|
|
|
List defined bugzillae. If <abbreviation> is specified, list the
|
|
|
|
information for that bugzilla.
|
2003-11-08 09:01:34 +01:00
|
|
|
"""
|
2003-11-11 15:14:34 +01:00
|
|
|
if name:
|
|
|
|
try:
|
|
|
|
name = self.shorthand[name]
|
|
|
|
(url, description) = self.db[name]
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply('%s: %s, %s' % (name, description, url))
|
2003-11-11 15:14:34 +01:00
|
|
|
except KeyError:
|
2004-01-21 02:33:59 +01:00
|
|
|
s = self.registryValue('replyNoBugzilla', msg.args[0])
|
2004-01-20 08:57:40 +01:00
|
|
|
irc.error(s % name)
|
2003-10-20 21:56:17 +02:00
|
|
|
else:
|
2003-11-11 15:14:34 +01:00
|
|
|
if self.db:
|
|
|
|
L = self.db.keys()
|
|
|
|
L.sort()
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(utils.commaAndify(L))
|
2003-11-11 15:14:34 +01:00
|
|
|
else:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply('I have no defined bugzillae.')
|
2004-10-15 15:28:27 +02:00
|
|
|
list = wrap(list, [additional('text')])
|
2003-11-01 00:53:35 +01:00
|
|
|
|
2004-08-19 07:29:56 +02:00
|
|
|
def bugzSnarf(self, irc, msg, match):
|
2004-08-19 20:16:24 +02:00
|
|
|
r"""\bbug\b(?:id|ids|#)?\s+(?:id|ids|#)?(?P<bug>\d+)"""
|
2004-10-15 15:28:27 +02:00
|
|
|
|
2004-08-19 07:29:56 +02:00
|
|
|
snarfTarget = self.registryValue('snarfTarget')
|
2004-08-19 20:16:24 +02:00
|
|
|
if not snarfTarget:
|
|
|
|
return
|
|
|
|
bugid = match.group('bug')
|
2004-08-19 07:29:56 +02:00
|
|
|
name = self.shorthand[snarfTarget]
|
|
|
|
try:
|
|
|
|
(url, description) = self.db[name]
|
|
|
|
except KeyError:
|
|
|
|
s = self.registryValue('replyNoBugzilla', name)
|
|
|
|
irc.error(s % name)
|
|
|
|
return
|
|
|
|
if not self.registryValue('bugSnarfer', name):
|
|
|
|
return
|
|
|
|
queryurl = '%s/xml.cgi?id=%s' % (url, bugid)
|
|
|
|
bold = self.registryValue('bold', name)
|
|
|
|
try:
|
|
|
|
summary = self._get_short_bug_summary(queryurl,description,bugid)
|
|
|
|
except BugzillaError, e:
|
|
|
|
irc.error(str(e))
|
|
|
|
return
|
|
|
|
except IOError, e:
|
|
|
|
s = '%s. Try yourself: %s' % (e, queryurl)
|
|
|
|
irc.error(s)
|
|
|
|
report = {}
|
2004-08-19 20:16:24 +02:00
|
|
|
report['id'] = bugid
|
|
|
|
report['url'] = str('%s/show_bug.cgi?id=%s' % (url, bugid))
|
|
|
|
report['title'] = str(summary['title'])
|
2004-08-19 07:29:56 +02:00
|
|
|
report['summary'] = str(self._mk_summary_string(summary, bold))
|
|
|
|
report['product'] = str(summary['product'])
|
|
|
|
s = '%(product)s bug #%(id)s: %(title)s %(summary)s' % report
|
|
|
|
irc.reply(s, prefixName=False)
|
|
|
|
|
2003-10-22 17:20:06 +02:00
|
|
|
def bzSnarfer(self, irc, msg, match):
|
2003-10-31 23:48:43 +01:00
|
|
|
r"(http://\S+)/show_bug.cgi\?id=([0-9]+)"
|
2004-01-21 02:33:59 +01:00
|
|
|
if not self.registryValue('bugSnarfer', msg.args[0]):
|
2003-10-22 17:54:32 +02:00
|
|
|
return
|
2003-10-22 17:20:06 +02:00
|
|
|
queryurl = '%s/xml.cgi?id=%s' % (match.group(1), match.group(2))
|
|
|
|
try:
|
2004-01-09 00:03:48 +01:00
|
|
|
summary = self._get_short_bug_summary(queryurl,
|
|
|
|
'Snarfed Bugzilla URL',
|
|
|
|
match.group(2))
|
2003-11-11 15:14:34 +01:00
|
|
|
except BugzillaError, e:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(str(e))
|
2003-10-22 17:20:06 +02:00
|
|
|
return
|
|
|
|
except IOError, e:
|
|
|
|
msgtouser = '%s. Try yourself: %s' % (e, queryurl)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(msgtouser)
|
2003-10-22 17:20:06 +02:00
|
|
|
return
|
2004-01-31 18:31:04 +01:00
|
|
|
bold = self.registryValue('bold', msg.args[0])
|
2003-10-22 17:20:06 +02:00
|
|
|
report = {}
|
|
|
|
report['id'] = match.group(2)
|
2003-11-01 00:53:35 +01:00
|
|
|
report['url'] = str('%s/show_bug.cgi?id=%s' % (match.group(1),
|
|
|
|
match.group(2)))
|
2003-10-22 17:20:06 +02:00
|
|
|
report['title'] = str(summary['title'])
|
2004-01-31 18:31:04 +01:00
|
|
|
report['summary'] = str(self._mk_summary_string(summary, bold))
|
2003-11-01 00:53:35 +01:00
|
|
|
report['product'] = str(summary['product'])
|
2003-11-08 09:01:34 +01:00
|
|
|
s = '%(product)s bug #%(id)s: %(title)s %(summary)s' % report
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(s, prefixName=False)
|
2004-09-30 12:04:22 +02:00
|
|
|
bzSnarfer = wrap(bzSnarfer, decorators=['urlSnarfer'])
|
2003-12-12 23:41:50 +01:00
|
|
|
|
|
|
|
def urlquery2bugslist(self, url, query):
|
|
|
|
"""Given a URL and query list for a CSV bug list, it'll return
|
2003-12-17 14:14:33 +01:00
|
|
|
all the bugs in a dict
|
|
|
|
"""
|
2004-07-21 21:36:35 +02:00
|
|
|
bugs = {}
|
2004-05-01 21:53:28 +02:00
|
|
|
try:
|
|
|
|
url = '%s/buglist.cgi?%s' % (url, '&'.join(query))
|
|
|
|
u = webutils.getUrlFd(url)
|
|
|
|
except webutils.WebError, e:
|
|
|
|
return bugs
|
2003-12-12 23:41:50 +01:00
|
|
|
# actually read in the file
|
|
|
|
csvreader = csv.reader(u)
|
|
|
|
# read header
|
|
|
|
fields = csvreader.next()
|
|
|
|
# read the rest of the list
|
|
|
|
for bug in csvreader:
|
2004-05-01 21:53:28 +02:00
|
|
|
if isinstance(bug, basestring):
|
|
|
|
bugid = bug
|
|
|
|
else:
|
2004-07-31 10:26:29 +02:00
|
|
|
if bug:
|
|
|
|
bugid = bug[0]
|
|
|
|
else:
|
|
|
|
raise callbacks.Error, 'No bugs found.'
|
2003-12-12 23:41:50 +01:00
|
|
|
try:
|
2004-05-01 21:53:28 +02:00
|
|
|
bugid = int(bugid)
|
2003-12-12 23:41:50 +01:00
|
|
|
except ValueError:
|
2004-05-01 21:53:28 +02:00
|
|
|
pass
|
2003-12-12 23:41:50 +01:00
|
|
|
bugs[bugid] = {}
|
|
|
|
i = 1
|
|
|
|
for f in fields[1:]:
|
|
|
|
bugs[bugid][f] = bug[i]
|
|
|
|
i += 1
|
|
|
|
u.close()
|
|
|
|
return bugs
|
2004-07-21 21:36:35 +02:00
|
|
|
|
2004-10-15 15:28:27 +02:00
|
|
|
def search(self, irc, msg, args, optlist, name, searchstr):
|
2003-12-12 23:41:50 +01:00
|
|
|
"""[--keywords=<keyword>] <bugzilla name> <search string in desc>
|
2004-07-21 21:36:35 +02:00
|
|
|
|
|
|
|
Look for bugs with <search string in the desc>, also matching
|
2003-12-12 23:41:50 +01:00
|
|
|
<keywords>. <keywords> can be statuses, severities, priorities, or
|
2004-08-19 01:15:27 +02:00
|
|
|
resolutions, separated by commas"""
|
2003-12-12 23:41:50 +01:00
|
|
|
keywords = None
|
|
|
|
for (option, arguments) in optlist:
|
2004-10-15 15:28:27 +02:00
|
|
|
if option == 'keywords':
|
2003-12-12 23:41:50 +01:00
|
|
|
keywords = arguments.split(',')
|
|
|
|
if not keywords:
|
2004-07-21 21:36:35 +02:00
|
|
|
keywords = ['UNCONFIRMED', 'NEW', 'ASSIGNED', 'REOPENED']
|
2003-12-12 23:41:50 +01:00
|
|
|
query = self.keywords2query(keywords)
|
|
|
|
query.append('short_desc_type=allwordssubstr')
|
|
|
|
query.append('short_desc=%s' % urllib.quote(searchstr))
|
|
|
|
query.append('order=Bug+Number')
|
|
|
|
try:
|
|
|
|
name = self.shorthand[name]
|
|
|
|
(url, description) = self.db[name]
|
|
|
|
except KeyError:
|
2004-01-21 02:33:59 +01:00
|
|
|
s = self.registryValue('replyNoBugzilla', msg.args[0])
|
2004-01-20 08:57:40 +01:00
|
|
|
irc.error(s % name)
|
2003-12-12 23:41:50 +01:00
|
|
|
return
|
|
|
|
bugs = self.urlquery2bugslist(url, query)
|
|
|
|
bugids = bugs.keys()
|
|
|
|
bugids.sort()
|
2004-05-01 21:53:28 +02:00
|
|
|
if not bugs:
|
|
|
|
irc.error('I could not find any bugs.')
|
|
|
|
return
|
2003-12-17 14:14:33 +01:00
|
|
|
s = '%s match %r (%s): %s.' % \
|
|
|
|
(utils.nItems('bug', len(bugs)), searchstr,
|
|
|
|
' AND '.join(keywords), utils.commaAndify(map(str, bugids)))
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(s)
|
2004-10-15 15:28:27 +02:00
|
|
|
search = wrap(search, [getopts({'keywords':'text'}), 'text', 'text'])
|
2004-07-21 21:36:35 +02:00
|
|
|
|
2004-10-15 15:28:27 +02:00
|
|
|
def bug(self, irc, msg, args, name, number):
|
2003-11-01 00:53:35 +01:00
|
|
|
"""<abbreviation> <number>
|
|
|
|
|
|
|
|
Look up bug <number> in the bugzilla associated with <abbreviation>.
|
2003-11-08 09:01:34 +01:00
|
|
|
"""
|
2003-11-11 15:14:34 +01:00
|
|
|
try:
|
|
|
|
name = self.shorthand[name]
|
|
|
|
(url, description) = self.db[name]
|
|
|
|
except KeyError:
|
2004-01-21 02:33:59 +01:00
|
|
|
s = self.registryValue('replyNoBugzilla', msg.args[0])
|
2004-01-20 08:57:40 +01:00
|
|
|
irc.error(s % name)
|
2003-10-20 21:56:17 +02:00
|
|
|
return
|
2003-11-11 15:14:34 +01:00
|
|
|
queryurl = '%s/xml.cgi?id=%s' % (url, number)
|
2003-10-20 21:56:17 +02:00
|
|
|
try:
|
2003-11-11 15:14:34 +01:00
|
|
|
summary = self._get_short_bug_summary(queryurl,description,number)
|
|
|
|
except BugzillaError, e:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error(str(e))
|
2003-10-20 21:56:17 +02:00
|
|
|
return
|
|
|
|
except IOError, e:
|
2003-11-11 15:14:34 +01:00
|
|
|
s = '%s. Try yourself: %s' % (e, queryurl)
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error(s)
|
2004-01-31 18:31:04 +01:00
|
|
|
bold = self.registryValue('bold', msg.args[0])
|
2003-10-20 21:56:17 +02:00
|
|
|
report = {}
|
2003-11-11 15:14:34 +01:00
|
|
|
report['zilla'] = description
|
|
|
|
report['id'] = number
|
|
|
|
report['url'] = '%s/show_bug.cgi?id=%s' % (url, number)
|
2003-10-20 21:56:17 +02:00
|
|
|
report['title'] = str(summary['title'])
|
2004-01-31 18:31:04 +01:00
|
|
|
report['summary'] = self._mk_summary_string(summary, bold)
|
2003-11-08 09:01:34 +01:00
|
|
|
s = '%(zilla)s bug #%(id)s: %(title)s %(summary)s %(url)s' % report
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(s)
|
2004-10-15 15:28:27 +02:00
|
|
|
bug = wrap(bug, ['text', ('id', 'bug')])
|
2003-10-20 21:56:17 +02:00
|
|
|
|
2004-01-31 18:31:04 +01:00
|
|
|
def _mk_summary_string(self, summary, bold):
|
2003-11-08 09:01:34 +01:00
|
|
|
L = []
|
2004-01-31 18:31:04 +01:00
|
|
|
if bold:
|
2004-01-20 08:11:00 +01:00
|
|
|
decorate = lambda s: ircutils.bold(s)
|
|
|
|
else:
|
|
|
|
decorate = lambda s: s
|
2003-11-01 00:53:35 +01:00
|
|
|
if 'product' in summary:
|
2004-01-20 08:11:00 +01:00
|
|
|
L.append(decorate('Product: ') + summary['product'])
|
2003-11-01 00:53:35 +01:00
|
|
|
if 'component' in summary:
|
2004-01-20 08:11:00 +01:00
|
|
|
L.append(decorate('Component: ') + summary['component'])
|
2003-11-01 00:53:35 +01:00
|
|
|
if 'severity' in summary:
|
2004-01-20 08:11:00 +01:00
|
|
|
L.append(decorate('Severity: ') + summary['severity'])
|
2003-11-01 00:53:35 +01:00
|
|
|
if 'assigned to' in summary:
|
2004-01-20 08:11:00 +01:00
|
|
|
L.append(decorate('Assigned to: ') + summary['assigned to'])
|
2003-11-01 00:53:35 +01:00
|
|
|
if 'status' in summary:
|
2004-01-20 08:11:00 +01:00
|
|
|
L.append(decorate('Status: ') + summary['status'])
|
2003-11-01 00:53:35 +01:00
|
|
|
if 'resolution' in summary:
|
2004-01-20 08:11:00 +01:00
|
|
|
L.append(decorate('Resolution: ') + summary['resolution'])
|
2003-11-15 05:37:04 +01:00
|
|
|
return ', '.join(imap(str, L))
|
2003-10-20 21:56:17 +02:00
|
|
|
|
2003-11-11 15:14:34 +01:00
|
|
|
def _get_short_bug_summary(self, url, desc, number):
|
|
|
|
try:
|
2003-11-17 20:57:07 +01:00
|
|
|
bugxml = self._getbugxml(url, desc)
|
2003-11-11 15:14:34 +01:00
|
|
|
zilladom = minidom.parseString(bugxml)
|
2003-10-20 21:56:17 +02:00
|
|
|
except Exception, e:
|
2003-11-11 15:14:34 +01:00
|
|
|
s = 'Could not parse XML returned by %s bugzilla: %s' % (desc, e)
|
|
|
|
raise BugzillaError, s
|
2003-10-20 21:56:17 +02:00
|
|
|
bug_n = zilladom.getElementsByTagName('bug')[0]
|
|
|
|
if bug_n.hasAttribute('error'):
|
|
|
|
errtxt = bug_n.getAttribute('error')
|
2003-11-11 15:14:34 +01:00
|
|
|
s = 'Error getting %s bug #%s: %s' % (desc, number, errtxt)
|
|
|
|
raise BugzillaError, s
|
2003-10-20 21:56:17 +02:00
|
|
|
summary = {}
|
|
|
|
try:
|
|
|
|
node = bug_n.getElementsByTagName('short_desc')[0]
|
|
|
|
summary['title'] = self._getnodetxt(node)
|
|
|
|
node = bug_n.getElementsByTagName('bug_status')[0]
|
|
|
|
summary['status'] = self._getnodetxt(node)
|
|
|
|
try:
|
|
|
|
node = bug_n.getElementsByTagName('resolution')[0]
|
|
|
|
summary['resolution'] = self._getnodetxt(node)
|
|
|
|
except:
|
|
|
|
pass
|
2003-10-22 17:20:06 +02:00
|
|
|
node = bug_n.getElementsByTagName('assigned_to')[0]
|
|
|
|
summary['assigned to'] = self._getnodetxt(node)
|
2003-11-01 00:53:35 +01:00
|
|
|
node = bug_n.getElementsByTagName('product')[0]
|
|
|
|
summary['product'] = self._getnodetxt(node)
|
2003-10-20 21:56:17 +02:00
|
|
|
node = bug_n.getElementsByTagName('component')[0]
|
|
|
|
summary['component'] = self._getnodetxt(node)
|
|
|
|
node = bug_n.getElementsByTagName('bug_severity')[0]
|
|
|
|
summary['severity'] = self._getnodetxt(node)
|
|
|
|
except Exception, e:
|
2003-11-11 15:14:34 +01:00
|
|
|
s = 'Could not parse XML returned by %s bugzilla: %s' % (desc, e)
|
|
|
|
raise BugzillaError, s
|
2003-10-20 21:56:17 +02:00
|
|
|
return summary
|
|
|
|
|
|
|
|
def _getbugxml(self, url, desc):
|
2003-11-08 09:01:34 +01:00
|
|
|
try:
|
2004-05-01 21:53:28 +02:00
|
|
|
bugxml = webutils.getUrl(url)
|
|
|
|
except webutils.WebError, e:
|
2003-11-11 15:14:34 +01:00
|
|
|
raise IOError, 'Connection to %s bugzilla failed' % desc
|
2003-11-08 09:01:34 +01:00
|
|
|
if not bugxml:
|
|
|
|
raise IOError, 'Error getting bug content from %s' % desc
|
2003-10-20 21:56:17 +02:00
|
|
|
return bugxml
|
|
|
|
|
|
|
|
def _getnodetxt(self, node):
|
2003-11-08 09:01:34 +01:00
|
|
|
L = []
|
2003-10-20 21:56:17 +02:00
|
|
|
for childnode in node.childNodes:
|
|
|
|
if childnode.nodeType == childnode.TEXT_NODE:
|
2003-11-08 09:01:34 +01:00
|
|
|
L.append(childnode.data)
|
|
|
|
val = ''.join(L)
|
2003-10-20 21:56:17 +02:00
|
|
|
if node.hasAttribute('encoding'):
|
|
|
|
encoding = node.getAttribute('encoding')
|
|
|
|
if encoding == 'base64':
|
|
|
|
try:
|
2003-11-08 09:01:34 +01:00
|
|
|
val = val.decode('base64')
|
2003-10-20 21:56:17 +02:00
|
|
|
except:
|
2003-11-08 09:01:34 +01:00
|
|
|
val = 'Cannot convert bug data from base64.'
|
|
|
|
while self.entre.search(val):
|
|
|
|
entity = self.entre.search(val).group(1)
|
|
|
|
if entity in entities:
|
2003-11-11 15:14:34 +01:00
|
|
|
val = self.entre.sub(entities[entity], val)
|
2003-10-20 21:56:17 +02:00
|
|
|
else:
|
2003-11-11 15:14:34 +01:00
|
|
|
val = self.entre.sub('?', val)
|
2003-10-20 21:56:17 +02:00
|
|
|
return val
|
2003-11-01 00:53:35 +01:00
|
|
|
|
2003-11-08 09:01:34 +01:00
|
|
|
|
2003-10-20 21:56:17 +02:00
|
|
|
Class = Bugzilla
|
2003-11-01 00:53:35 +01:00
|
|
|
|
|
|
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|