2003-10-16 16:53:42 +02:00
|
|
|
#!/usr/bin/env python
|
2003-10-10 15:47:06 +02:00
|
|
|
|
|
|
|
###
|
2003-10-11 20:40:22 +02:00
|
|
|
# Copyright (c) 2003, 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
|
|
|
"""
|
|
|
|
|
|
|
|
import re
|
2003-10-11 22:52:35 +02:00
|
|
|
import sets
|
2003-10-10 15:47:06 +02:00
|
|
|
import urllib2
|
|
|
|
|
2003-10-11 20:40:22 +02:00
|
|
|
from itertools import ifilter
|
2003-10-10 15:47:06 +02:00
|
|
|
|
2003-10-20 19:52:09 +02:00
|
|
|
import conf
|
2003-10-10 15:47:06 +02:00
|
|
|
import debug
|
|
|
|
import utils
|
2003-10-11 20:40:22 +02:00
|
|
|
import ircutils
|
2003-10-10 15:47:06 +02:00
|
|
|
import privmsgs
|
|
|
|
import callbacks
|
|
|
|
|
|
|
|
|
|
|
|
def configure(onStart, afterConnect, advanced):
|
|
|
|
# This will be called by setup.py to configure this module. onStart and
|
|
|
|
# afterConnect are both lists. Append to onStart the commands you would
|
|
|
|
# like to be run when the bot is started; append to afterConnect the
|
|
|
|
# commands you would like to be run when the bot has finished connecting.
|
|
|
|
from questions import expect, anything, something, yn
|
2003-10-21 18:43:02 +02:00
|
|
|
onStart.append('load Sourceforge')
|
2003-10-22 20:51:16 +02:00
|
|
|
print 'The Sourceforge plugin has the functionality to watch for URLs'
|
|
|
|
print 'that match a specific pattern (we call this a snarfer). When'
|
|
|
|
print 'supybot sees such a URL, he will parse the web page for information'
|
|
|
|
print 'and reply with the results.\n'
|
|
|
|
if yn('Do you want the Sourceforge snarfer enabled by default?') == 'n':
|
|
|
|
onStart.append('Sourceforge togglesnarfer')
|
2003-10-10 15:47:06 +02:00
|
|
|
|
|
|
|
example = utils.wrapLines("""
|
2003-10-10 15:55:38 +02:00
|
|
|
<@jamessan|work> @bugs
|
|
|
|
< supybot> jamessan|work: Bug #820702: ChannelDB bugs in stats., Bug #797823: Time reporting errors on win9x, Bug #794330: Website documentation isn't finished., Bug #708327: FreeBSD plugin doesn't automatically download the new INDEX, and Bug #708158: FreeBSD plugin's searchports doesn't do depends correctly.
|
|
|
|
<@jamessan|work> @bugs supybot 797823
|
|
|
|
< supybot> jamessan|work: Time reporting errors on win9x <http://sourceforge.net/tracker/index.php?func=detail&aid=797823&group_id=58965&atid=489447>
|
|
|
|
<@jamessan|work> @bugs gaim
|
|
|
|
< supybot> jamessan|work: Bug #821118: MSN Plugin cannot be loaded
|
|
|
|
in 0.71, Bug #820961: dock icon doesn't show up with..., Bug #820879: Cannot connect to a particular irc..., Bug #820831: © or ® render im null, Bug #820776: gaim 0.70 segfaults using certain..., Bug #820691: gaim 0.70 fails to start up on..., Bug #820687: MSN duplicating buddies at signon, Bug (6 more messages)
|
|
|
|
<@jamessan|work> @rfes pythoggoras
|
|
|
|
< supybot> jamessan|work: RFE #728701: Ability to specify 'themed' configs at command line, RFE #720757: Improve CLI interface, RFE #719248: Add config file support, and RFE #717761: Tracker for adding GUI
|
|
|
|
<@jamessan|work> @rfes pythoggoras 720757
|
|
|
|
< supybot> jamessan|work: Improve CLI interface <http://sourceforge.net/tracker/index.php?func=detail&aid=720757&group_id=75946&atid=545548>
|
2003-10-10 15:47:06 +02:00
|
|
|
""")
|
|
|
|
|
2003-10-21 18:43:02 +02: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
|
2003-10-21 23:10:20 +02:00
|
|
|
regexps = ['sfSnarfer']
|
2003-10-10 15:47:06 +02:00
|
|
|
|
2003-10-11 20:40:22 +02:00
|
|
|
_infoRe = re.compile(r'<td nowrap>(\d+)</td><td><a href="([^"]+)">'\
|
2003-10-10 15:47:06 +02:00
|
|
|
'([^<]+)</a>', re.I)
|
2003-10-11 20:40:22 +02:00
|
|
|
_hrefOpts = '&set=custom&_assigned_to=0&_status=1&_category=100&'\
|
2003-10-10 15:47:06 +02:00
|
|
|
'_group=100&order=artifact_id&sort=DESC'
|
2003-10-11 20:40:22 +02:00
|
|
|
|
2003-10-18 16:19:06 +02:00
|
|
|
_resolution = re.compile(r'<b>Resolution:</b> <a.+?<br>(.+?)</td>', re.I)
|
|
|
|
_getRes = lambda self, s: '%s: %s' % (ircutils.bold('Resolution'),
|
|
|
|
self._resolution.search(s).group(1))
|
|
|
|
_assigned = re.compile(r'<b>Assigned To:</b> <a.+?<br>(.+?)</td>', re.I)
|
|
|
|
_getAssign = lambda self, s: '%s: %s' % (ircutils.bold('Assigned to'),
|
|
|
|
self._assigned.search(s).group(1))
|
|
|
|
_priority = re.compile(r'<b>Priority:</b> <a.+?<br>(.+?)</td>', re.I)
|
|
|
|
_getPri = lambda self, s: '%s: %s' % (ircutils.bold('Priority'),
|
|
|
|
self._priority.search(s).group(1))
|
|
|
|
_status = re.compile(r'<b>Status:</b> <a.+?<br>(.+?)</td>', re.I)
|
|
|
|
_getStatus = lambda self, s: '%s: %s' % (ircutils.bold('Status'),
|
|
|
|
self._status.search(s).group(1))
|
|
|
|
|
2003-10-20 19:52:09 +02:00
|
|
|
def __init__(self):
|
|
|
|
callbacks.PrivmsgCommandAndRegexp.__init__(self)
|
|
|
|
self.snarfer = True
|
|
|
|
|
2003-10-11 20:40:22 +02:00
|
|
|
def _formatResp(self, num, text):
|
|
|
|
"""
|
|
|
|
Parses the Sourceforge query to return a list of tuples that
|
|
|
|
contain the bug/rfe information.
|
|
|
|
"""
|
|
|
|
|
|
|
|
matches = []
|
|
|
|
try:
|
|
|
|
int(num)
|
|
|
|
for item in ifilter(lambda s, n=num: s is not None and n in s,
|
|
|
|
self._infoRe.findall(text)):
|
|
|
|
matches.append((ircutils.bold(utils.htmlToText(item[2])),
|
|
|
|
utils.htmlToText(item[1])))
|
|
|
|
except ValueError:
|
|
|
|
for item in ifilter(None, self._infoRe.findall(text)):
|
|
|
|
matches.append((item[0], utils.htmlToText(item[2])))
|
|
|
|
return matches
|
|
|
|
|
2003-10-21 18:43:02 +02:00
|
|
|
def togglesnarfer(self, irc, msg, args):
|
2003-10-20 19:52:09 +02:00
|
|
|
"""takes no argument
|
|
|
|
|
|
|
|
Disables the snarfer that responds to all Sourceforge Tracker links
|
|
|
|
"""
|
2003-10-21 18:43:02 +02:00
|
|
|
self.snarfer = not self.snarfer
|
|
|
|
if self.snarfer:
|
|
|
|
irc.reply(msg, '%s (Snarfer is enabled)' % conf.replySuccess)
|
|
|
|
else:
|
|
|
|
irc.reply(msg, '%s (Snarfer is disabled)' % conf.replySuccess)
|
|
|
|
togglesnarfer=privmsgs.checkCapability(togglesnarfer,'admin')
|
2003-10-20 19:52:09 +02:00
|
|
|
|
2003-10-11 20:40:22 +02:00
|
|
|
_bugLink = re.compile(r'"([^"]+)">Bugs')
|
2003-10-10 15:47:06 +02:00
|
|
|
def bugs(self, irc, msg, args):
|
|
|
|
"""[<project> [<num>]]
|
|
|
|
|
|
|
|
Returns a list of the most recent bugs filed against <project>.
|
|
|
|
Defaults to searching for supybot bugs. If <num> is specified, the bug
|
|
|
|
description and link are retrieved.
|
|
|
|
"""
|
|
|
|
(project, bugnum) = privmsgs.getArgs(args, needed=0, optional=2)
|
|
|
|
if not project:
|
|
|
|
project = 'supybot'
|
|
|
|
url = 'http://sourceforge.net/projects/%s' % project
|
|
|
|
try:
|
|
|
|
fd = urllib2.urlopen(url)
|
|
|
|
text = fd.read()
|
|
|
|
fd.close()
|
|
|
|
m = self._bugLink.search(text)
|
|
|
|
if m is None:
|
|
|
|
irc.reply(msg, 'Can\'t find the "Bugs" link.')
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
url = 'http://sourceforge.net%s%s' %\
|
2003-10-11 20:40:22 +02:00
|
|
|
(utils.htmlToText(m.group(1)), self._hrefOpts)
|
2003-10-10 15:47:06 +02:00
|
|
|
except ValueError, e:
|
|
|
|
irc.error(msg, str(e))
|
2003-10-11 20:40:22 +02:00
|
|
|
except urllib2.HTTPError, e:
|
2003-10-10 15:47:06 +02:00
|
|
|
irc.error(msg, e.msg())
|
|
|
|
except Exception, e:
|
|
|
|
irc.error(msg, debug.exnToString(e))
|
|
|
|
|
|
|
|
try:
|
|
|
|
fd = urllib2.urlopen(url)
|
|
|
|
text = fd.read()
|
|
|
|
fd.close()
|
2003-10-11 20:40:22 +02:00
|
|
|
resp = []
|
2003-10-10 15:47:06 +02:00
|
|
|
if bugnum != '':
|
2003-10-11 20:40:22 +02:00
|
|
|
head = '%s <http://sourceforge.net%s>'
|
|
|
|
for bug in self._formatResp(bugnum, text):
|
|
|
|
resp.append(head % bug)
|
2003-10-10 15:47:06 +02:00
|
|
|
if resp:
|
|
|
|
irc.reply(msg, resp[0])
|
|
|
|
return
|
|
|
|
else:
|
2003-10-11 20:40:22 +02:00
|
|
|
head = 'Bug #%s: %s'
|
|
|
|
for bug in self._formatResp(bugnum, text):
|
|
|
|
resp.append(head % bug)
|
2003-10-10 15:47:06 +02:00
|
|
|
if resp:
|
|
|
|
if len(resp) > 10:
|
|
|
|
resp = map(lambda s: utils.ellipsisify(s, 50), resp)
|
|
|
|
irc.reply(msg, '%s' % utils.commaAndify(resp))
|
|
|
|
return
|
|
|
|
irc.reply(msg, 'No bugs were found.')
|
|
|
|
except ValueError, e:
|
|
|
|
irc.error(msg, str(e))
|
|
|
|
except Exception, e:
|
|
|
|
irc.error(msg, debug.exnToString(e))
|
|
|
|
|
|
|
|
_rfeLink = re.compile(r'"([^"]+)">RFE')
|
|
|
|
def rfes(self, irc, msg, args):
|
|
|
|
"""[<project> [<num>]]
|
|
|
|
|
2003-10-11 20:40:22 +02:00
|
|
|
Returns a list of the most recent RFEs filed against <project>.
|
|
|
|
Defaults to searching for supybot RFEs. If <num> is specified, the rfe
|
2003-10-10 15:47:06 +02:00
|
|
|
description and link are retrieved.
|
|
|
|
"""
|
|
|
|
(project, rfenum) = privmsgs.getArgs(args, needed=0, optional=2)
|
|
|
|
if not project:
|
|
|
|
project = 'supybot'
|
|
|
|
url = 'http://sourceforge.net/projects/%s' % project
|
|
|
|
try:
|
|
|
|
fd = urllib2.urlopen(url)
|
|
|
|
text = fd.read()
|
|
|
|
fd.close()
|
|
|
|
m = self._rfeLink.search(text)
|
|
|
|
if m is None:
|
|
|
|
irc.reply(msg, 'Can\'t find the "RFE" link.')
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
url = 'http://sourceforge.net%s%s' %\
|
2003-10-11 20:40:22 +02:00
|
|
|
(utils.htmlToText(m.group(1)), self._hrefOpts)
|
2003-10-10 15:47:06 +02:00
|
|
|
except ValueError, e:
|
|
|
|
irc.error(msg, str(e))
|
2003-10-11 20:40:22 +02:00
|
|
|
except urllib2.HTTPError, e:
|
2003-10-10 15:47:06 +02:00
|
|
|
irc.error(msg, e.msg())
|
|
|
|
except Exception, e:
|
|
|
|
irc.error(msg, debug.exnToString(e))
|
|
|
|
|
|
|
|
try:
|
|
|
|
fd = urllib2.urlopen(url)
|
|
|
|
text = fd.read()
|
|
|
|
fd.close()
|
2003-10-11 20:40:22 +02:00
|
|
|
resp = []
|
2003-10-10 15:47:06 +02:00
|
|
|
if rfenum != '':
|
2003-10-11 20:40:22 +02:00
|
|
|
head = '%s <http://sourceforge.net%s>'
|
|
|
|
for rfe in self._formatResp(rfenum, text):
|
|
|
|
resp.append(head % rfe)
|
2003-10-10 15:47:06 +02:00
|
|
|
if resp:
|
|
|
|
irc.reply(msg, resp[0])
|
|
|
|
return
|
|
|
|
else:
|
2003-10-11 20:40:22 +02:00
|
|
|
head = 'RFE #%s: %s'
|
|
|
|
for rfe in self._formatResp(rfenum, text):
|
|
|
|
resp.append(head % rfe)
|
2003-10-10 15:47:06 +02:00
|
|
|
if resp:
|
|
|
|
if len(resp) > 10:
|
|
|
|
resp = map(lambda s: utils.ellipsisify(s, 50), resp)
|
|
|
|
irc.reply(msg, '%s' % utils.commaAndify(resp))
|
|
|
|
return
|
|
|
|
irc.reply(msg, 'No rfes were found.')
|
|
|
|
except ValueError, e:
|
|
|
|
irc.error(msg, str(e))
|
|
|
|
except Exception, e:
|
|
|
|
irc.error(msg, debug.exnToString(e))
|
|
|
|
|
2003-10-11 22:52:35 +02:00
|
|
|
_sfTitle = re.compile(r'Detail:(\d+) - ([^<]+)</title>', re.I)
|
|
|
|
_linkType = re.compile(r'(\w+ \w+|\w+): Tracker Detailed View', re.I)
|
2003-10-21 14:20:23 +02:00
|
|
|
def sfSnarfer(self, irc, msg, match):
|
2003-10-22 17:58:07 +02:00
|
|
|
r"https?://(?:www\.)?(?:sourceforge|sf)\.net/tracker/(?:index\.php)?\?(?:&?func=detail|&?aid=\d+|&?group_id=\d+|&?atid=\d+){4}"
|
2003-10-20 19:52:09 +02:00
|
|
|
if not self.snarfer:
|
|
|
|
return
|
2003-10-11 22:52:35 +02:00
|
|
|
url = match.group(0)
|
|
|
|
fd = urllib2.urlopen(url)
|
|
|
|
s = fd.read()
|
|
|
|
fd.close()
|
2003-10-18 16:19:06 +02:00
|
|
|
searches = (self._getStatus, self._getRes, self._getPri,
|
|
|
|
self._getAssign)
|
2003-10-11 22:52:35 +02:00
|
|
|
try:
|
|
|
|
(num, desc) = self._sfTitle.search(s).groups()
|
2003-10-18 16:19:06 +02:00
|
|
|
resp = [desc]
|
2003-10-16 04:42:47 +02:00
|
|
|
linktype = self._linkType.search(s).group(1)
|
2003-10-18 16:19:06 +02:00
|
|
|
for i in searches:
|
|
|
|
try:
|
|
|
|
resp.append('%s' % i(s))
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
2003-10-18 16:21:03 +02:00
|
|
|
linktype = utils.depluralize(linktype)
|
2003-10-18 16:19:06 +02:00
|
|
|
irc.reply(msg, '%s #%s: %s' % (ircutils.bold(linktype),
|
2003-10-21 18:43:02 +02:00
|
|
|
ircutils.bold(num), '; '.join(resp)), prefixName = False)
|
2003-10-11 22:52:35 +02:00
|
|
|
except AttributeError, e:
|
2003-10-17 16:18:00 +02:00
|
|
|
irc.error(msg, 'That doesn\'t appear to be a proper Sourceforge '\
|
2003-10-21 18:43:02 +02:00
|
|
|
'Tracker page. (%s)' % conf.replyPossibleBug)
|
2003-10-11 22:52:35 +02:00
|
|
|
except Exception, e:
|
|
|
|
irc.error(msg, debug.exnToString(e))
|
|
|
|
|
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:
|