2003-10-10 15:47:06 +02:00
|
|
|
###
|
2004-08-23 15:14:06 +02:00
|
|
|
# Copyright (c) 2003-2004, James Vega
|
2003-10-10 15:47:06 +02:00
|
|
|
# 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-11 20:40:22 +02:00
|
|
|
Accesses Sourceforge.net for various things
|
2003-10-10 15:47:06 +02:00
|
|
|
"""
|
|
|
|
|
2004-09-01 08:06:54 +02:00
|
|
|
import supybot
|
|
|
|
|
2004-04-28 10:45:00 +02:00
|
|
|
__revision__ = "$Id$"
|
2004-09-01 08:06:54 +02:00
|
|
|
__author__ = supybot.authors.jamessan
|
2004-04-28 10:45:00 +02:00
|
|
|
|
2003-10-10 15:47:06 +02:00
|
|
|
import re
|
2003-10-11 22:52:35 +02:00
|
|
|
import sets
|
2004-01-13 06:44:43 +01:00
|
|
|
import getopt
|
2003-10-10 15:47:06 +02:00
|
|
|
|
2003-11-15 05:37:04 +01:00
|
|
|
from itertools import ifilter, imap
|
2003-10-10 15:47:06 +02:00
|
|
|
|
2004-10-06 23:58:02 +02:00
|
|
|
import rssparser
|
2004-01-20 05:24:21 +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-17 20:01:58 +02:00
|
|
|
from supybot.commands import *
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.ircutils as ircutils
|
|
|
|
import supybot.privmsgs as privmsgs
|
|
|
|
import supybot.registry as registry
|
|
|
|
import supybot.webutils as webutils
|
|
|
|
import supybot.callbacks as callbacks
|
2003-10-10 15:47:06 +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, something, yn
|
2004-01-28 23:19:25 +01:00
|
|
|
conf.registerPlugin('Sourceforge', True)
|
2004-01-31 23:24:43 +01:00
|
|
|
output("""The Sourceforge plugin has the functionality to watch for URLs
|
|
|
|
that match a specific pattern (we call this a snarfer). When
|
|
|
|
supybot sees such a URL, he will parse the web page for
|
|
|
|
information and reply with the results.""")
|
|
|
|
if yn('Do you want this snarfer to be enabled by default?'):
|
2004-01-20 05:24:21 +01:00
|
|
|
conf.supybot.plugins.Sourceforge.trackerSnarfer.setValue(True)
|
2003-10-27 21:24:32 +01:00
|
|
|
|
2004-01-31 23:24:43 +01:00
|
|
|
output("""The bugs and rfes commands of the Sourceforge plugin can be set
|
|
|
|
to query a default project when no project is specified. If this
|
|
|
|
project is not set, calling either of those commands will display
|
|
|
|
the associated help. With the default project set, calling
|
|
|
|
bugs/rfes with no arguments will find the most recent bugs/rfes
|
|
|
|
for the default project.""")
|
|
|
|
if yn('Do you want to specify a default project?'):
|
2003-10-27 21:24:32 +01:00
|
|
|
project = anything('Project name:')
|
|
|
|
if project:
|
2004-02-09 05:02:21 +01:00
|
|
|
conf.supybot.plugins.Sourceforge.defaultProject.set(project)
|
2003-10-10 15:47:06 +02:00
|
|
|
|
2004-01-31 23:24:43 +01:00
|
|
|
output("""Sourceforge is quite the word to type, and it may get annoying
|
|
|
|
typing it all the time because Supybot makes you use the plugin
|
|
|
|
name to disambiguate calls to ambiguous commands (i.e., the bug
|
|
|
|
command is in this plugin and the Bugzilla plugin; if both are
|
|
|
|
loaded, you\'ll have you type "sourceforge bug ..." to get this
|
|
|
|
bug command). You may save some time by making an alias for
|
2004-01-31 23:27:12 +01:00
|
|
|
"sourceforge". We like to make it "sf".""")
|
2003-11-17 19:10:53 +01:00
|
|
|
|
2003-11-05 03:13:41 +01:00
|
|
|
class TrackerError(Exception):
|
|
|
|
pass
|
2003-10-10 15:47:06 +02:00
|
|
|
|
2004-01-20 05:24:21 +01:00
|
|
|
conf.registerPlugin('Sourceforge')
|
|
|
|
conf.registerChannelValue(conf.supybot.plugins.Sourceforge, 'trackerSnarfer',
|
|
|
|
registry.Boolean(False, """Determines whether the bot will reply to SF.net
|
|
|
|
Tracker URLs in the channel with a nice summary of the tracker item."""))
|
2004-02-09 05:02:21 +01:00
|
|
|
conf.registerChannelValue(conf.supybot.plugins.Sourceforge, 'defaultProject',
|
2004-01-20 09:00:39 +01:00
|
|
|
registry.String('', """Sets the default project to use in the case that no
|
|
|
|
explicit project is given."""))
|
2004-09-06 03:32:45 +02:00
|
|
|
conf.registerGlobalValue(conf.supybot.plugins.Sourceforge, 'bold',
|
|
|
|
registry.Boolean(True, """Determines whether the results are bolded."""))
|
2004-09-16 18:11:20 +02:00
|
|
|
conf.registerGlobalValue(conf.supybot.plugins.Sourceforge,
|
|
|
|
'enableSpecificTrackerCommands', registry.Boolean(True, """Determines
|
|
|
|
whether the bug, rfe, and patch commands (convenience wrappers around
|
|
|
|
the tracker command) will be enabled."""))
|
2004-01-20 05:24:21 +01:00
|
|
|
|
|
|
|
class Sourceforge(callbacks.PrivmsgCommandAndRegexp):
|
2003-10-11 20:40:22 +02:00
|
|
|
"""
|
|
|
|
Module for Sourceforge stuff. Currently contains commands to query a
|
|
|
|
project's most recent bugs and rfes.
|
|
|
|
"""
|
2003-10-10 15:47:06 +02:00
|
|
|
threaded = True
|
2004-09-10 08:36:27 +02:00
|
|
|
callBefore = ['URL']
|
2003-10-21 23:10:20 +02:00
|
|
|
regexps = ['sfSnarfer']
|
2003-10-10 15:47:06 +02:00
|
|
|
|
2003-10-24 14:38:45 +02:00
|
|
|
_reopts = re.I
|
2004-01-09 00:03:48 +01:00
|
|
|
_infoRe = re.compile(r'<td nowrap>(\d+)</td><td><a href='
|
2004-09-04 07:51:30 +02:00
|
|
|
r'"([^"]+)">([^<]+)</a>', re.I)
|
2004-01-13 06:44:43 +01:00
|
|
|
_hrefOpts = '&set=custom&_assigned_to=0&_status=%s&_category=100' \
|
2004-01-09 00:03:48 +01:00
|
|
|
'&_group=100&order=artifact_id&sort=DESC'
|
2003-11-04 08:03:18 +01:00
|
|
|
_resolution=re.compile(r'<b>(Resolution):</b> <a.+?<br>(.+?)</td>',_reopts)
|
|
|
|
_assigned=re.compile(r'<b>(Assigned To):</b> <a.+?<br>(.+?)</td>', _reopts)
|
2004-04-15 08:20:21 +02:00
|
|
|
_submitted = re.compile(r'<b>(Submitted By):</b><br>([^-]+) - '
|
|
|
|
r'(?:nobody|<a href)', _reopts)
|
2004-07-25 03:02:37 +02:00
|
|
|
_submitDate = re.compile(r'<b>(Date Submitted):</b><br>([^<]+)</', _reopts)
|
2003-11-02 20:46:35 +01:00
|
|
|
_priority = re.compile(r'<b>(Priority):</b> <a.+?<br>(.+?)</td>', _reopts)
|
|
|
|
_status = re.compile(r'<b>(Status):</b> <a.+?<br>(.+?)</td>', _reopts)
|
2004-07-25 03:02:37 +02:00
|
|
|
_regexps =(_resolution, _submitDate, _submitted, _assigned, _priority,
|
|
|
|
_status)
|
2004-01-13 06:44:43 +01:00
|
|
|
_statusOpt = {'any':100, 'open':1, 'closed':2, 'deleted':3, 'pending':4}
|
2004-10-17 20:01:58 +02:00
|
|
|
_optDict = {'any':'', 'open':'', 'closed':'', 'deleted':'', 'pending':''}
|
2003-10-18 16:19:06 +02:00
|
|
|
|
2003-11-05 03:13:41 +01:00
|
|
|
_projectURL = 'http://sourceforge.net/projects/'
|
2004-05-01 23:38:49 +02:00
|
|
|
_trackerURL = 'http://sourceforge.net/support/tracker.php?aid='
|
2004-02-12 05:25:37 +01:00
|
|
|
def __init__(self):
|
2004-09-20 01:51:21 +02:00
|
|
|
self.__parent = super(Sourceforge, self)
|
|
|
|
self.__parent.__init__()
|
2004-02-12 05:25:37 +01:00
|
|
|
self.__class__.sf = self.__class__.sourceforge
|
2004-07-21 21:36:35 +02:00
|
|
|
|
2004-09-16 18:11:20 +02:00
|
|
|
def isCommand(self, name):
|
|
|
|
if name in ('bug', 'rfe', 'patch'):
|
|
|
|
return self.registryValue('enableSpecificTrackerCommands')
|
|
|
|
else:
|
2004-09-20 01:51:21 +02:00
|
|
|
return self.__parent.isCommand(name)
|
2004-09-16 18:11:20 +02:00
|
|
|
|
2003-11-05 03:13:41 +01:00
|
|
|
def _formatResp(self, text, num=''):
|
2003-10-11 20:40:22 +02:00
|
|
|
"""
|
|
|
|
Parses the Sourceforge query to return a list of tuples that
|
2004-09-04 07:51:30 +02:00
|
|
|
contain the tracker information.
|
2003-10-11 20:40:22 +02:00
|
|
|
"""
|
2003-11-05 03:13:41 +01:00
|
|
|
if num:
|
|
|
|
for item in ifilter(lambda s, n=num: s and n in s,
|
2003-10-11 20:40:22 +02:00
|
|
|
self._infoRe.findall(text)):
|
2004-09-06 03:32:45 +02:00
|
|
|
if self.registryValue('bold'):
|
|
|
|
yield (ircutils.bold(utils.htmlToText(item[2])),
|
|
|
|
utils.htmlToText(item[1]))
|
|
|
|
else:
|
|
|
|
yield (utils.htmlToText(item[2]),
|
|
|
|
utils.htmlToText(item[1]))
|
2003-11-05 03:13:41 +01:00
|
|
|
else:
|
2003-10-11 20:40:22 +02:00
|
|
|
for item in ifilter(None, self._infoRe.findall(text)):
|
2004-09-06 03:32:45 +02:00
|
|
|
if self.registryValue('bold'):
|
|
|
|
yield (ircutils.bold(item[0]), utils.htmlToText(item[2]))
|
|
|
|
else:
|
|
|
|
yield (item[0], utils.htmlToText(item[2]))
|
2003-10-11 20:40:22 +02:00
|
|
|
|
2004-01-13 06:44:43 +01:00
|
|
|
def _getTrackerURL(self, project, regex, status):
|
2004-09-04 07:51:30 +02:00
|
|
|
"""
|
|
|
|
Searches the project's Summary page to find the proper tracker link.
|
|
|
|
"""
|
2003-10-10 15:47:06 +02:00
|
|
|
try:
|
2003-12-02 07:03:42 +01:00
|
|
|
text = webutils.getUrl('%s%s' % (self._projectURL, project))
|
2003-10-27 21:24:32 +01:00
|
|
|
m = regex.search(text)
|
2003-10-10 15:47:06 +02:00
|
|
|
if m is None:
|
2003-11-05 03:13:41 +01:00
|
|
|
raise TrackerError, 'Invalid Tracker page'
|
2003-10-10 15:47:06 +02:00
|
|
|
else:
|
2003-11-05 03:13:41 +01:00
|
|
|
return 'http://sourceforge.net%s%s' % (utils.htmlToText(
|
2004-01-13 06:44:43 +01:00
|
|
|
m.group(1)), self._hrefOpts % self._statusOpt[status])
|
2003-12-03 05:57:30 +01:00
|
|
|
except webutils.WebError, e:
|
2003-11-26 19:21:12 +01:00
|
|
|
raise callbacks.Error, str(e)
|
2003-10-10 15:47:06 +02:00
|
|
|
|
2003-11-05 03:13:41 +01:00
|
|
|
def _getTrackerList(self, url):
|
2004-09-04 07:51:30 +02:00
|
|
|
"""
|
|
|
|
Searches the tracker list page and returns a list of the trackers.
|
|
|
|
"""
|
2003-10-10 15:47:06 +02:00
|
|
|
try:
|
2003-12-02 07:03:42 +01:00
|
|
|
text = webutils.getUrl(url)
|
2004-04-18 22:16:55 +02:00
|
|
|
if "No matches found." in text:
|
|
|
|
return 'No trackers were found.'
|
2003-11-05 03:13:41 +01:00
|
|
|
head = '#%s: %s'
|
|
|
|
resp = [head % entry for entry in self._formatResp(text)]
|
|
|
|
if resp:
|
|
|
|
if len(resp) > 10:
|
2003-11-15 05:37:04 +01:00
|
|
|
resp = imap(lambda s: utils.ellipsisify(s, 50), resp)
|
2003-11-05 03:13:41 +01:00
|
|
|
return '%s' % utils.commaAndify(resp)
|
2004-01-09 00:03:48 +01:00
|
|
|
raise callbacks.Error, 'No Trackers were found. (%s)' % \
|
2004-01-18 08:58:26 +01:00
|
|
|
conf.supybot.replies.possibleBug()
|
2003-12-03 05:57:30 +01:00
|
|
|
except webutils.WebError, e:
|
2004-01-13 06:44:43 +01:00
|
|
|
raise callbacks.Error, str(e)
|
2004-07-21 21:36:35 +02:00
|
|
|
|
2004-04-15 08:20:21 +02:00
|
|
|
_bold = lambda self, m: (ircutils.bold(m[0]),) + m[1:]
|
|
|
|
_sfTitle = re.compile(r'Detail:(\d+) - ([^<]+)</title>', re.I)
|
|
|
|
_linkType = re.compile(r'(\w+ \w+|\w+): Tracker Detailed View', re.I)
|
|
|
|
def _getTrackerInfo(self, url):
|
2004-09-04 07:51:30 +02:00
|
|
|
"""
|
|
|
|
Parses the specific tracker page, returning useful information.
|
|
|
|
"""
|
2003-11-05 03:13:41 +01:00
|
|
|
try:
|
2004-09-06 03:32:45 +02:00
|
|
|
bold = self.registryValue('bold')
|
2004-04-15 08:20:21 +02:00
|
|
|
s = webutils.getUrl(url)
|
|
|
|
resp = []
|
|
|
|
head = ''
|
|
|
|
m = self._linkType.search(s)
|
|
|
|
n = self._sfTitle.search(s)
|
|
|
|
if m and n:
|
|
|
|
linktype = m.group(1)
|
|
|
|
linktype = utils.depluralize(linktype)
|
|
|
|
(num, desc) = n.groups()
|
2004-09-06 03:32:45 +02:00
|
|
|
if bold:
|
|
|
|
head = '%s #%s: %s' % (ircutils.bold(linktype), num, desc)
|
|
|
|
else:
|
|
|
|
head = '%s #%s: %s' % (linktype, num, desc)
|
2004-04-16 18:31:17 +02:00
|
|
|
resp.append(head)
|
2004-04-15 08:20:21 +02:00
|
|
|
else:
|
|
|
|
return None
|
|
|
|
for r in self._regexps:
|
|
|
|
m = r.search(s)
|
|
|
|
if m:
|
2004-09-06 03:32:45 +02:00
|
|
|
if bold:
|
|
|
|
resp.append('%s: %s' % self._bold(m.groups()))
|
|
|
|
else:
|
|
|
|
resp.append('%s: %s' % m.groups())
|
2004-04-16 18:31:17 +02:00
|
|
|
return '; '.join(resp)
|
2003-12-03 05:57:30 +01:00
|
|
|
except webutils.WebError, e:
|
2004-04-15 08:20:21 +02:00
|
|
|
raise TrackerError, str(e)
|
|
|
|
|
2004-10-17 20:01:58 +02:00
|
|
|
def bug(self, irc, msg, args, id):
|
2004-09-16 18:11:20 +02:00
|
|
|
"""<id>
|
|
|
|
|
|
|
|
Returns a description of the bug with id <id>. Really, this is
|
|
|
|
just a wrapper for the tracker command; it won't even complain if the
|
|
|
|
<id> you give isn't a bug.
|
|
|
|
"""
|
2004-10-17 20:01:58 +02:00
|
|
|
self.tracker(irc, msg, args, id)
|
|
|
|
bug = wrap(bug, [('id', 'bug')])
|
|
|
|
|
|
|
|
def patch(self, irc, msg, args, id):
|
2004-09-16 18:11:20 +02:00
|
|
|
"""<id>
|
|
|
|
|
|
|
|
Returns a description of the patch with id <id>. Really, this is
|
|
|
|
just a wrapper for the tracker command; it won't even complain if the
|
|
|
|
<id> you give isn't a patch.
|
|
|
|
"""
|
2004-10-17 20:01:58 +02:00
|
|
|
self.tracker(irc, msg, args, id)
|
|
|
|
patch = wrap(patch, [('id', 'patch')])
|
|
|
|
|
|
|
|
def rfe(self, irc, msg, args, id):
|
2004-09-16 18:11:20 +02:00
|
|
|
"""<id>
|
|
|
|
|
|
|
|
Returns a description of the rfe with id <id>. Really, this is
|
|
|
|
just a wrapper for the tracker command; it won't even complain if the
|
|
|
|
<id> you give isn't an rfe.
|
|
|
|
"""
|
2004-10-17 20:01:58 +02:00
|
|
|
self.tracker(irc, msg, args, id)
|
|
|
|
rfe = wrap(rfe, [('id', 'rfe')])
|
|
|
|
|
|
|
|
def tracker(self, irc, msg, args, id):
|
2004-09-16 18:11:20 +02:00
|
|
|
"""<id>
|
2004-04-15 08:20:21 +02:00
|
|
|
|
2004-09-16 18:11:20 +02:00
|
|
|
Returns a description of the tracker with id <id> and the corresponding
|
|
|
|
url.
|
2004-04-15 08:20:21 +02:00
|
|
|
"""
|
|
|
|
try:
|
2004-10-17 20:01:58 +02:00
|
|
|
url = '%s%s' % (self._trackerURL, id)
|
2004-04-15 08:20:21 +02:00
|
|
|
resp = self._getTrackerInfo(url)
|
|
|
|
if resp is None:
|
|
|
|
irc.error('Invalid Tracker page snarfed: %s' % url)
|
|
|
|
else:
|
2004-04-16 18:31:17 +02:00
|
|
|
irc.reply('%s <%s>' % (resp, url))
|
2004-04-15 08:20:21 +02:00
|
|
|
except TrackerError, e:
|
2004-01-13 06:44:43 +01:00
|
|
|
irc.error(str(e))
|
2004-10-17 20:01:58 +02:00
|
|
|
tracker = wrap(tracker, [('id', 'tracker')])
|
2003-10-10 15:47:06 +02:00
|
|
|
|
2004-09-03 21:46:50 +02:00
|
|
|
_trackerLink = {'bugs': re.compile(r'"([^"]+)">Bugs'),
|
|
|
|
'rfes': re.compile(r'"([^"]+)">RFE'),
|
|
|
|
'patches': re.compile(r'"([^"]+)">Patches'),
|
|
|
|
}
|
2004-10-17 20:01:58 +02:00
|
|
|
def _trackers(self, irc, args, msg, optlist, project, tracker):
|
2004-01-13 06:44:43 +01:00
|
|
|
status = 'open'
|
|
|
|
for (option, _) in optlist:
|
|
|
|
if option in self._statusOpt:
|
|
|
|
status = option
|
2003-11-11 17:04:27 +01:00
|
|
|
try:
|
2004-09-04 07:51:30 +02:00
|
|
|
int(project)
|
2004-09-30 07:25:54 +02:00
|
|
|
s = 'Use the tracker command to get information about a specific '\
|
|
|
|
'tracker.'
|
2004-01-09 00:03:48 +01:00
|
|
|
irc.error(s)
|
2003-11-11 17:04:27 +01:00
|
|
|
return
|
|
|
|
except ValueError:
|
|
|
|
pass
|
2003-10-27 21:24:32 +01:00
|
|
|
if not project:
|
2004-02-09 05:02:21 +01:00
|
|
|
project = self.registryValue('defaultProject', msg.args[0])
|
2003-11-08 10:02:30 +01:00
|
|
|
if not project:
|
|
|
|
raise callbacks.ArgumentError
|
2003-11-05 03:13:41 +01:00
|
|
|
try:
|
2004-09-03 21:46:50 +02:00
|
|
|
url = self._getTrackerURL(project, self._trackerLink[tracker],
|
|
|
|
status)
|
2003-11-11 17:04:27 +01:00
|
|
|
except TrackerError, e:
|
2004-09-03 21:46:50 +02:00
|
|
|
irc.error('%s. I can\'t find the %s link.' %
|
|
|
|
(e, tracker.capitalize()))
|
2003-11-05 03:13:41 +01:00
|
|
|
return
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(self._getTrackerList(url))
|
2003-11-05 03:13:41 +01:00
|
|
|
|
2004-10-17 20:01:58 +02:00
|
|
|
def bugs(self, irc, msg, args, optlist, project):
|
2004-09-04 07:51:30 +02:00
|
|
|
"""[--{any,open,closed,deleted,pending}] [<project>]
|
|
|
|
|
|
|
|
Returns a list of the most recent bugs filed against <project>.
|
|
|
|
<project> is not needed if there is a default project set. Search
|
|
|
|
defaults to open bugs.
|
|
|
|
"""
|
2004-10-17 20:01:58 +02:00
|
|
|
self._trackers(irc, args, msg, optlist, project, 'bugs')
|
|
|
|
bugs = wrap(bugs, [getopts(_optDict), additional('text', '')])
|
2004-09-04 07:51:30 +02:00
|
|
|
|
2004-10-17 20:01:58 +02:00
|
|
|
def rfes(self, irc, msg, args, optlist, project):
|
2004-09-04 07:51:30 +02:00
|
|
|
"""[--{any,open,closed,deleted,pending}] [<project>]
|
|
|
|
|
|
|
|
Returns a list of the most recent rfes filed against <project>.
|
|
|
|
<project> is not needed if there is a default project set. Search
|
|
|
|
defaults to open rfes.
|
|
|
|
"""
|
2004-10-17 20:01:58 +02:00
|
|
|
self._trackers(irc, args, msg, optlist, project, 'rfes')
|
|
|
|
rfes = wrap(rfes, [getopts(_optDict), additional('text', '')])
|
2004-09-04 07:51:30 +02:00
|
|
|
|
2004-10-17 20:01:58 +02:00
|
|
|
def patches(self, irc, msg, args, optlist, project):
|
2004-09-04 07:51:30 +02:00
|
|
|
"""[--{any,open,closed,deleted,pending}] [<project>]
|
|
|
|
|
|
|
|
Returns a list of the most recent patches filed against <project>.
|
|
|
|
<project> is not needed if there is a default project set. Search
|
|
|
|
defaults to open patches.
|
|
|
|
"""
|
2004-10-17 20:01:58 +02:00
|
|
|
self._trackers(irc, args, msg, optlist, project, 'patches')
|
|
|
|
patches = wrap(patches, [getopts(_optDict), additional('text', '')])
|
2004-09-04 07:51:30 +02:00
|
|
|
|
2004-09-30 07:25:54 +02:00
|
|
|
_intRe = re.compile(r'(\d+)')
|
|
|
|
_percentRe = re.compile(r'([\d.]+%)')
|
2004-10-17 20:01:58 +02:00
|
|
|
def stats(self, irc, msg, args, project):
|
2004-09-30 07:25:54 +02:00
|
|
|
"""[<project>]
|
|
|
|
|
|
|
|
Returns the current statistics for <project>. <project> is not needed
|
|
|
|
if there is a default project set.
|
|
|
|
"""
|
|
|
|
url = 'http://sourceforge.net/' \
|
|
|
|
'export/rss2_projsummary.php?project=' + project
|
|
|
|
results = rssparser.parse(url)
|
|
|
|
if not results['items']:
|
|
|
|
irc.errorInvalid('SourceForge project name', project)
|
|
|
|
class x:
|
|
|
|
pass
|
|
|
|
def get(r, s):
|
|
|
|
m = r.search(s)
|
|
|
|
if m is not None:
|
|
|
|
return m.group(0)
|
|
|
|
else:
|
|
|
|
irc.error('Sourceforge gave me a bad RSS feed.', Raise=True)
|
|
|
|
def gets(r, s):
|
|
|
|
L = []
|
|
|
|
for m in r.finditer(s):
|
|
|
|
L.append(m.group(1))
|
|
|
|
return L
|
|
|
|
def afterColon(s):
|
|
|
|
return s.split(': ', 1)[-1]
|
|
|
|
for item in results['items']:
|
|
|
|
title = item['title']
|
|
|
|
description = item['description']
|
|
|
|
if 'Project name' in title:
|
|
|
|
x.project = afterColon(title)
|
|
|
|
elif 'Developers on project' in title:
|
|
|
|
x.devs = get(self._intRe, title)
|
|
|
|
elif 'Activity percentile' in title:
|
|
|
|
x.activity = get(self._percentRe, title)
|
|
|
|
x.ranking = get(self._intRe, afterColon(description))
|
|
|
|
elif 'Downloadable files' in title:
|
|
|
|
x.downloads = get(self._intRe, title)
|
|
|
|
x.downloadsToday = afterColon(description)
|
|
|
|
elif 'Tracker: Bugs' in title:
|
|
|
|
(x.bugsOpen, x.bugsTotal) = gets(self._intRe, title)
|
|
|
|
elif 'Tracker: Patches' in title:
|
|
|
|
(x.patchesOpen, x.patchesTotal) = gets(self._intRe, title)
|
|
|
|
elif 'Tracker: Feature' in title:
|
|
|
|
(x.rfesOpen, x.rfesTotal) = gets(self._intRe, title)
|
|
|
|
irc.reply('%s has %s, '
|
|
|
|
'is %s active (ranked %s), '
|
|
|
|
'has had %s (%s today), '
|
|
|
|
'has %s (out of %s), '
|
|
|
|
'has %s (out of %s), '
|
|
|
|
'and has %s (out of %s).' %
|
|
|
|
(x.project, utils.nItems('developer', x.devs),
|
|
|
|
x.activity, x.ranking,
|
|
|
|
utils.nItems('download', x.downloads), x.downloadsToday,
|
|
|
|
utils.nItems('bug', x.bugsOpen, 'open'), x.bugsTotal,
|
|
|
|
utils.nItems('rfe', x.rfesOpen, 'open'), x.rfesTotal,
|
|
|
|
utils.nItems('patch',x.patchesOpen, 'open'), x.patchesTotal))
|
2004-10-17 20:01:58 +02:00
|
|
|
stats = wrap(stats, ['lowered'])
|
|
|
|
|
2004-05-01 23:38:49 +02:00
|
|
|
_totbugs = re.compile(r'Bugs</a>\s+?\( <b>([^<]+)</b>', re.S | re.I)
|
|
|
|
def _getNumBugs(self, project):
|
|
|
|
text = webutils.getUrl('%s%s' % (self._projectURL, project))
|
|
|
|
m = self._totbugs.search(text)
|
|
|
|
if m:
|
|
|
|
return m.group(1)
|
|
|
|
else:
|
|
|
|
return ''
|
|
|
|
|
|
|
|
_totrfes = re.compile(r'Feature Requests</a>\s+?\( <b>([^<]+)</b>',
|
|
|
|
re.S | re.I)
|
|
|
|
def _getNumRfes(self, project):
|
|
|
|
text = webutils.getUrl('%s%s' % (self._projectURL, project))
|
|
|
|
m = self._totrfes.search(text)
|
|
|
|
if m:
|
|
|
|
return m.group(1)
|
|
|
|
else:
|
|
|
|
return ''
|
|
|
|
|
2004-08-23 21:53:29 +02:00
|
|
|
def total(self, irc, msg, args):
|
2004-09-04 07:51:30 +02:00
|
|
|
"""{bugs,rfes} [<project>]
|
2004-08-23 21:53:29 +02:00
|
|
|
|
|
|
|
Returns the total count of open bugs or rfes. <project> is only
|
|
|
|
necessary if a default project is not set.
|
|
|
|
"""
|
|
|
|
if not args:
|
|
|
|
raise callbacks.ArgumentError
|
|
|
|
type = args.pop(0)
|
|
|
|
if type == 'bugs':
|
|
|
|
self._totalbugs(irc, msg, args)
|
|
|
|
elif type == 'rfes':
|
|
|
|
self._totalrfes(irc, msg, args)
|
|
|
|
else:
|
|
|
|
raise callbacks.ArgumentError
|
2004-09-03 21:46:50 +02:00
|
|
|
|
2004-08-23 21:53:29 +02:00
|
|
|
def _totalbugs(self, irc, msg, args):
|
2004-01-20 09:00:39 +01:00
|
|
|
"""[<project>]
|
|
|
|
|
|
|
|
Returns a count of the open/total bugs. <project> is not needed if a
|
|
|
|
default project is set.
|
|
|
|
"""
|
|
|
|
project = privmsgs.getArgs(args, required=0, optional=1)
|
2004-02-09 05:02:21 +01:00
|
|
|
project = project or self.registryValue('defaultProject', msg.args[0])
|
2004-01-20 09:00:39 +01:00
|
|
|
if not project:
|
|
|
|
raise callbacks.ArgumentError
|
2004-05-01 23:38:49 +02:00
|
|
|
total = self._getNumBugs(project)
|
|
|
|
if total:
|
|
|
|
irc.reply(total)
|
2004-01-20 09:00:39 +01:00
|
|
|
else:
|
|
|
|
irc.error('Could not find bug statistics.')
|
|
|
|
|
2004-08-23 21:53:29 +02:00
|
|
|
def _totalrfes(self, irc, msg, args):
|
2004-05-01 23:38:49 +02:00
|
|
|
"""[<project>]
|
|
|
|
|
|
|
|
Returns a count of the open/total RFEs. <project> is not needed if a
|
|
|
|
default project is set.
|
|
|
|
"""
|
|
|
|
project = privmsgs.getArgs(args, required=0, optional=1)
|
|
|
|
project = project or self.registryValue('defaultProject', msg.args[0])
|
|
|
|
if not project:
|
|
|
|
raise callbacks.ArgumentError
|
|
|
|
total = self._getNumRfes(project)
|
|
|
|
if total:
|
|
|
|
irc.reply(total)
|
|
|
|
else:
|
|
|
|
irc.error('Could not find RFE statistics.')
|
|
|
|
|
2004-10-17 20:01:58 +02:00
|
|
|
def fight(self, irc, msg, args, optlist, projects):
|
|
|
|
"""[--{bugs,rfes}] [--{open,closed}] <project name> <project name> \
|
|
|
|
[<project name> ...]
|
2004-01-20 09:00:39 +01:00
|
|
|
|
2004-05-01 23:38:49 +02:00
|
|
|
Returns the projects, in order, from greatest number of bugs to least.
|
|
|
|
Defaults to bugs and open.
|
2004-01-20 09:00:39 +01:00
|
|
|
"""
|
2004-05-01 23:38:49 +02:00
|
|
|
search = self._getNumBugs
|
|
|
|
type = 0
|
|
|
|
for (option, _) in optlist:
|
2004-10-17 20:01:58 +02:00
|
|
|
if option == 'bugs':
|
2004-05-01 23:38:49 +02:00
|
|
|
search = self._getNumBugs
|
2004-10-17 20:01:58 +02:00
|
|
|
if option == 'rfes':
|
2004-05-01 23:38:49 +02:00
|
|
|
search = self._getNumRfes
|
2004-10-17 20:01:58 +02:00
|
|
|
if option == 'open':
|
2004-05-01 23:38:49 +02:00
|
|
|
type = 0
|
2004-10-17 20:01:58 +02:00
|
|
|
if option == 'closed':
|
2004-05-01 23:38:49 +02:00
|
|
|
type = 1
|
|
|
|
results = []
|
2004-10-17 20:01:58 +02:00
|
|
|
for proj in projects:
|
2004-05-01 23:38:49 +02:00
|
|
|
num = search(proj)
|
|
|
|
if num:
|
|
|
|
results.append((int(num.split('/')[type].split()[0]), proj))
|
|
|
|
results.sort()
|
|
|
|
results.reverse()
|
|
|
|
s = ', '.join(['\'%s\': %s' % (s, i) for (i, s) in results])
|
|
|
|
irc.reply(s)
|
2004-10-17 20:01:58 +02:00
|
|
|
fight = wrap(fight, [getopts({'bugs':'','rfes':'','open':'','closed':''}),
|
|
|
|
many('text')])
|
2004-01-20 09:00:39 +01:00
|
|
|
|
2003-10-21 14:20:23 +02:00
|
|
|
def sfSnarfer(self, irc, msg, match):
|
2003-10-30 01:13:00 +01:00
|
|
|
r"https?://(?:www\.)?(?:sourceforge|sf)\.net/tracker/" \
|
|
|
|
r".*\?(?:&?func=detail|&?aid=\d+|&?group_id=\d+|&?atid=\d+){4}"
|
2004-01-21 02:19:54 +01:00
|
|
|
if not self.registryValue('trackerSnarfer', msg.args[0]):
|
2003-10-20 19:52:09 +02:00
|
|
|
return
|
2003-10-11 22:52:35 +02:00
|
|
|
try:
|
2003-11-02 20:46:35 +01:00
|
|
|
url = match.group(0)
|
2004-04-15 08:20:21 +02:00
|
|
|
resp = self._getTrackerInfo(url)
|
|
|
|
if resp is None:
|
2004-01-09 00:03:48 +01:00
|
|
|
self.log.warning('Invalid Tracker page snarfed: %s', url)
|
2004-04-15 08:20:21 +02:00
|
|
|
else:
|
|
|
|
irc.reply(resp, prefixName=False)
|
|
|
|
except TrackerError, e:
|
2003-11-26 19:21:12 +01:00
|
|
|
self.log.warning(str(e))
|
2004-09-30 12:04:22 +02:00
|
|
|
sfSnarfer = wrap(sfSnarfer, decorators=['urlSnarfer'])
|
2003-10-11 22:52:35 +02:00
|
|
|
|
2003-10-21 18:43:02 +02:00
|
|
|
Class = Sourceforge
|
2003-10-10 15:47:06 +02:00
|
|
|
|
|
|
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|