Converted to use the registry.

This commit is contained in:
James Vega 2004-01-20 04:24:21 +00:00
parent a7559f3686
commit 006909b909
2 changed files with 48 additions and 37 deletions

View File

@ -39,6 +39,8 @@ import getopt
from itertools import ifilter, imap
import registry
import conf
import utils
__revision__ = "$Id$"
@ -48,7 +50,6 @@ import ircutils
import privmsgs
import webutils
import callbacks
import configurable
def configure(onStart, afterConnect, advanced):
@ -63,7 +64,7 @@ def configure(onStart, afterConnect, advanced):
print 'supybot sees such a URL, he will parse the web page for'
print 'information and reply with the results.\n'
if yn('Do you want this snarfer to be enabled by default?') == 'y':
onStart.append('Sourceforge config tracker-snarfer on')
conf.supybot.plugins.Sourceforge.trackerSnarfer.setValue(True)
print 'The bugs and rfes commands of the Sourceforge plugin can be set'
print 'to query a default project when no project is specified. If this'
@ -74,7 +75,7 @@ def configure(onStart, afterConnect, advanced):
if yn('Do you want to specify a default project?') == 'y':
project = anything('Project name:')
if project:
onStart.append('Sourceforge config defaultproject %s' % project)
conf.supybot.plugins.Sourceforge.project.set(project)
print 'Sourceforge is quite the word to type, and it may get annoying'
print 'typing it all the time because Supybot makes you use the plugin'
@ -96,7 +97,15 @@ def configure(onStart, afterConnect, advanced):
class TrackerError(Exception):
pass
class Sourceforge(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
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."""))
conf.registerChannelValue(conf.supybot.plugins.Sourceforge, 'project',
registry.String('', """Sets the default project (used by the bugs/rfes
commands in the case that no explicit project is given)."""))
class Sourceforge(callbacks.PrivmsgCommandAndRegexp):
"""
Module for Sourceforge stuff. Currently contains commands to query a
project's most recent bugs and rfes.
@ -117,21 +126,11 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
_regexps =(_resolution, _assigned, _submitted, _priority, _status)
_statusOpt = {'any':100, 'open':1, 'closed':2, 'deleted':3, 'pending':4}
configurables = configurable.Dictionary(
[('tracker-snarfer', configurable.BoolType, False,
"""Determines whether the bot will reply to SF.net Tracker URLs in
the channel with a nice summary of the tracker item."""),
('default-project', configurable.StrType, '',
"""Sets the default project (used by the bugs/rfes commands in the
case that no explicit project is given).""")]
)
_projectURL = 'http://sourceforge.net/projects/'
def __init__(self):
configurable.Mixin.__init__(self)
callbacks.PrivmsgCommandAndRegexp.__init__(self)
def die(self):
configurable.Mixin.die(self)
callbacks.PrivmsgCommandAndRegexp.die(self)
def _formatResp(self, text, num=''):
@ -210,7 +209,7 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
except ValueError:
pass
if not project:
project = self.configurables.get('default-project', msg.args[0])
project = conf.supybot.plugins.Sourceforge.project()
if not project:
raise callbacks.ArgumentError
try:
@ -241,7 +240,7 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
irc.error('"%s" is not a proper bugnumber.' % project)
return
bugnum = project
project = self.configurables.get('default-project', msg.args[0])
project = conf.supybot.plugins.Sourceforge.project()
if not project:
raise callbacks.ArgumentError
try:
@ -276,7 +275,7 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
except ValueError:
pass
if not project:
project = self.configurables.get('default-project', msg.args[0])
project = conf.supybot.plugins.Sourceforge.project()
if not project:
raise callbacks.ArgumentError
try:
@ -307,7 +306,7 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
irc.error('"%s" is not a proper rfenumber.' % project)
return
rfenum = project
project = self.configurables.get('default-project', msg.args[0])
project = conf.supybot.plugins.Sourceforge.project()
if not project:
raise callbacks.ArgumentError
try:
@ -323,7 +322,7 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
def sfSnarfer(self, irc, msg, match):
r"https?://(?:www\.)?(?:sourceforge|sf)\.net/tracker/" \
r".*\?(?:&?func=detail|&?aid=\d+|&?group_id=\d+|&?atid=\d+){4}"
if not self.configurables.get('tracker-snarfer', channel=msg.args[0]):
if not conf.supybot.plugins.Sourceforge.trackerSnarfer():
return
try:
url = match.group(0)

View File

@ -101,11 +101,11 @@ if network:
def testBugs(self):
self.assertHelp('bugs')
self.assertNotError('config defaultproject supybot')
conf.supybot.plugins.Sourceforge.project.set('supybot')
self.assertNotError('bugs')
self.assertRegexp('bugs alkjfi83fa8', 'find the Bugs')
self.assertNotError('bugs gaim')
self.assertNotError('config defaultproject')
conf.supybot.plugins.Sourceforge.project.set('')
self.assertRegexp('bugs 83423', 'Use the bug command')
def testRfe(self):
@ -118,58 +118,70 @@ if network:
def testRfes(self):
self.assertHelp('rfes')
self.assertNotError('config defaultproject gaim')
conf.supybot.plugins.Sourceforge.project.set('gaim')
self.assertNotError('rfes')
self.assertRegexp('rfes alkjfi83hfa8', 'find the RFEs')
self.assertNotError('rfes gaim')
self.assertNotError('config defaultproject')
conf.supybot.plugins.Sourceforge.project.set('')
self.assertRegexp('rfes 83423', 'Use the rfe command')
def testDefaultproject(self):
self.assertHelp('bugs')
self.assertNotError('config defaultproject supybot')
conf.supybot.plugins.Sourceforge.project.set('supybot')
self.assertNotError('bugs')
m = self.getMsg('bugs')
n = re.search('#(\d+)', m.args[1]).group(1)
self.assertNotError('bug supybot %s' % n)
# This should have the same effect as calling 'bug supybot %s'
self.assertNotError('bug %s' % n)
self.assertNotError('config defaultproject ""')
conf.supybot.plugins.Sourceforge.project.set('')
def testSnarfer(self):
s = r'.*Status.*: \w+'
self.assertNotError('config tracker-snarfer on')
conf.supybot.plugins.Sourceforge.trackerSnarfer.setValue(True)
self.assertRegexp('http://sourceforge.net/tracker/index.php?'
'func=detail&aid=589953&group_id=58965&atid=489447',
'func=detail&aid=589953&group_id=58965&'
'atid=489447',
s)
self.assertRegexp('http://sourceforge.net/tracker/index.php?'
'func=detail&aid=712761&group_id=58965&atid=489450',
'func=detail&aid=712761&group_id=58965&'
'atid=489450',
s)
self.assertRegexp('http://sourceforge.net/tracker/index.php?'
'func=detail&aid=540223&group_id=235&atid=300235', s)
'func=detail&aid=540223&group_id=235&'
'atid=300235',
s)
self.assertRegexp('http://sourceforge.net/tracker/index.php?'
'func=detail&aid=561547&group_id=235&atid=200235', s)
'func=detail&aid=561547&group_id=235&'
'atid=200235',
s)
self.assertRegexp('http://sourceforge.net/tracker/index.php?'
'func=detail&aid=400942&group_id=235&atid=390395', s)
'func=detail&aid=400942&group_id=235&'
'atid=390395',
s)
# test that it works without index.php
self.assertNotError('http://sourceforge.net/tracker/?'
'func=detail&aid=540223&group_id=235&atid=300235')
'func=detail&aid=540223&group_id=235&'
'atid=300235')
# test that it works with www
self.assertNotError('http://www.sourceforge.net/tracker/index.php?'
'func=detail&aid=540223&group_id=235&atid=300235')
'func=detail&aid=540223&group_id=235&'
'atid=300235')
# test that it works with www and without index.php
self.assertNotError('http://www.sourceforge.net/tracker/?'
'func=detail&aid=540223&group_id=235&atid=300235')
'func=detail&aid=540223&group_id=235&'
'atid=300235')
# test that it works with sf.net
self.assertNotError('http://sf.net/tracker/?'
'func=detail&aid=540223&group_id=235&atid=300235')
'func=detail&aid=540223&group_id=235&'
'atid=300235')
# test that it works
self.assertNotError('https://sourceforge.net/tracker/?'
'func=detail&atid=105470&aid=827260&group_id=5470')
'func=detail&atid=105470&aid=827260&'
'group_id=5470')
self.assertNoResponse('https://sourceforge.net/tracker/?'
'group_id=58965&atid=489447')
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: