mirror of https://github.com/Mikaela/Limnoria.git
Converted to use the registry.
This commit is contained in:
parent
a7559f3686
commit
006909b909
|
@ -39,6 +39,8 @@ import getopt
|
||||||
|
|
||||||
from itertools import ifilter, imap
|
from itertools import ifilter, imap
|
||||||
|
|
||||||
|
import registry
|
||||||
|
|
||||||
import conf
|
import conf
|
||||||
import utils
|
import utils
|
||||||
__revision__ = "$Id$"
|
__revision__ = "$Id$"
|
||||||
|
@ -48,7 +50,6 @@ import ircutils
|
||||||
import privmsgs
|
import privmsgs
|
||||||
import webutils
|
import webutils
|
||||||
import callbacks
|
import callbacks
|
||||||
import configurable
|
|
||||||
|
|
||||||
|
|
||||||
def configure(onStart, afterConnect, advanced):
|
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 'supybot sees such a URL, he will parse the web page for'
|
||||||
print 'information and reply with the results.\n'
|
print 'information and reply with the results.\n'
|
||||||
if yn('Do you want this snarfer to be enabled by default?') == 'y':
|
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 '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'
|
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':
|
if yn('Do you want to specify a default project?') == 'y':
|
||||||
project = anything('Project name:')
|
project = anything('Project name:')
|
||||||
if project:
|
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 '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'
|
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):
|
class TrackerError(Exception):
|
||||||
pass
|
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
|
Module for Sourceforge stuff. Currently contains commands to query a
|
||||||
project's most recent bugs and rfes.
|
project's most recent bugs and rfes.
|
||||||
|
@ -117,21 +126,11 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
|
||||||
_regexps =(_resolution, _assigned, _submitted, _priority, _status)
|
_regexps =(_resolution, _assigned, _submitted, _priority, _status)
|
||||||
_statusOpt = {'any':100, 'open':1, 'closed':2, 'deleted':3, 'pending':4}
|
_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/'
|
_projectURL = 'http://sourceforge.net/projects/'
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
configurable.Mixin.__init__(self)
|
|
||||||
callbacks.PrivmsgCommandAndRegexp.__init__(self)
|
callbacks.PrivmsgCommandAndRegexp.__init__(self)
|
||||||
|
|
||||||
def die(self):
|
def die(self):
|
||||||
configurable.Mixin.die(self)
|
|
||||||
callbacks.PrivmsgCommandAndRegexp.die(self)
|
callbacks.PrivmsgCommandAndRegexp.die(self)
|
||||||
|
|
||||||
def _formatResp(self, text, num=''):
|
def _formatResp(self, text, num=''):
|
||||||
|
@ -210,7 +209,7 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
if not project:
|
if not project:
|
||||||
project = self.configurables.get('default-project', msg.args[0])
|
project = conf.supybot.plugins.Sourceforge.project()
|
||||||
if not project:
|
if not project:
|
||||||
raise callbacks.ArgumentError
|
raise callbacks.ArgumentError
|
||||||
try:
|
try:
|
||||||
|
@ -241,7 +240,7 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
|
||||||
irc.error('"%s" is not a proper bugnumber.' % project)
|
irc.error('"%s" is not a proper bugnumber.' % project)
|
||||||
return
|
return
|
||||||
bugnum = project
|
bugnum = project
|
||||||
project = self.configurables.get('default-project', msg.args[0])
|
project = conf.supybot.plugins.Sourceforge.project()
|
||||||
if not project:
|
if not project:
|
||||||
raise callbacks.ArgumentError
|
raise callbacks.ArgumentError
|
||||||
try:
|
try:
|
||||||
|
@ -276,7 +275,7 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
if not project:
|
if not project:
|
||||||
project = self.configurables.get('default-project', msg.args[0])
|
project = conf.supybot.plugins.Sourceforge.project()
|
||||||
if not project:
|
if not project:
|
||||||
raise callbacks.ArgumentError
|
raise callbacks.ArgumentError
|
||||||
try:
|
try:
|
||||||
|
@ -307,7 +306,7 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
|
||||||
irc.error('"%s" is not a proper rfenumber.' % project)
|
irc.error('"%s" is not a proper rfenumber.' % project)
|
||||||
return
|
return
|
||||||
rfenum = project
|
rfenum = project
|
||||||
project = self.configurables.get('default-project', msg.args[0])
|
project = conf.supybot.plugins.Sourceforge.project()
|
||||||
if not project:
|
if not project:
|
||||||
raise callbacks.ArgumentError
|
raise callbacks.ArgumentError
|
||||||
try:
|
try:
|
||||||
|
@ -323,7 +322,7 @@ class Sourceforge(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
|
||||||
def sfSnarfer(self, irc, msg, match):
|
def sfSnarfer(self, irc, msg, match):
|
||||||
r"https?://(?:www\.)?(?:sourceforge|sf)\.net/tracker/" \
|
r"https?://(?:www\.)?(?:sourceforge|sf)\.net/tracker/" \
|
||||||
r".*\?(?:&?func=detail|&?aid=\d+|&?group_id=\d+|&?atid=\d+){4}"
|
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
|
return
|
||||||
try:
|
try:
|
||||||
url = match.group(0)
|
url = match.group(0)
|
||||||
|
|
|
@ -101,11 +101,11 @@ if network:
|
||||||
|
|
||||||
def testBugs(self):
|
def testBugs(self):
|
||||||
self.assertHelp('bugs')
|
self.assertHelp('bugs')
|
||||||
self.assertNotError('config defaultproject supybot')
|
conf.supybot.plugins.Sourceforge.project.set('supybot')
|
||||||
self.assertNotError('bugs')
|
self.assertNotError('bugs')
|
||||||
self.assertRegexp('bugs alkjfi83fa8', 'find the Bugs')
|
self.assertRegexp('bugs alkjfi83fa8', 'find the Bugs')
|
||||||
self.assertNotError('bugs gaim')
|
self.assertNotError('bugs gaim')
|
||||||
self.assertNotError('config defaultproject')
|
conf.supybot.plugins.Sourceforge.project.set('')
|
||||||
self.assertRegexp('bugs 83423', 'Use the bug command')
|
self.assertRegexp('bugs 83423', 'Use the bug command')
|
||||||
|
|
||||||
def testRfe(self):
|
def testRfe(self):
|
||||||
|
@ -118,58 +118,70 @@ if network:
|
||||||
|
|
||||||
def testRfes(self):
|
def testRfes(self):
|
||||||
self.assertHelp('rfes')
|
self.assertHelp('rfes')
|
||||||
self.assertNotError('config defaultproject gaim')
|
conf.supybot.plugins.Sourceforge.project.set('gaim')
|
||||||
self.assertNotError('rfes')
|
self.assertNotError('rfes')
|
||||||
self.assertRegexp('rfes alkjfi83hfa8', 'find the RFEs')
|
self.assertRegexp('rfes alkjfi83hfa8', 'find the RFEs')
|
||||||
self.assertNotError('rfes gaim')
|
self.assertNotError('rfes gaim')
|
||||||
self.assertNotError('config defaultproject')
|
conf.supybot.plugins.Sourceforge.project.set('')
|
||||||
self.assertRegexp('rfes 83423', 'Use the rfe command')
|
self.assertRegexp('rfes 83423', 'Use the rfe command')
|
||||||
|
|
||||||
def testDefaultproject(self):
|
def testDefaultproject(self):
|
||||||
self.assertHelp('bugs')
|
self.assertHelp('bugs')
|
||||||
self.assertNotError('config defaultproject supybot')
|
conf.supybot.plugins.Sourceforge.project.set('supybot')
|
||||||
self.assertNotError('bugs')
|
self.assertNotError('bugs')
|
||||||
m = self.getMsg('bugs')
|
m = self.getMsg('bugs')
|
||||||
n = re.search('#(\d+)', m.args[1]).group(1)
|
n = re.search('#(\d+)', m.args[1]).group(1)
|
||||||
self.assertNotError('bug supybot %s' % n)
|
self.assertNotError('bug supybot %s' % n)
|
||||||
# This should have the same effect as calling 'bug supybot %s'
|
# This should have the same effect as calling 'bug supybot %s'
|
||||||
self.assertNotError('bug %s' % n)
|
self.assertNotError('bug %s' % n)
|
||||||
self.assertNotError('config defaultproject ""')
|
conf.supybot.plugins.Sourceforge.project.set('')
|
||||||
|
|
||||||
def testSnarfer(self):
|
def testSnarfer(self):
|
||||||
s = r'.*Status.*: \w+'
|
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?'
|
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)
|
s)
|
||||||
self.assertRegexp('http://sourceforge.net/tracker/index.php?'
|
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)
|
s)
|
||||||
self.assertRegexp('http://sourceforge.net/tracker/index.php?'
|
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?'
|
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?'
|
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
|
# test that it works without index.php
|
||||||
self.assertNotError('http://sourceforge.net/tracker/?'
|
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
|
# test that it works with www
|
||||||
self.assertNotError('http://www.sourceforge.net/tracker/index.php?'
|
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
|
# test that it works with www and without index.php
|
||||||
self.assertNotError('http://www.sourceforge.net/tracker/?'
|
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
|
# test that it works with sf.net
|
||||||
self.assertNotError('http://sf.net/tracker/?'
|
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
|
# test that it works
|
||||||
self.assertNotError('https://sourceforge.net/tracker/?'
|
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/?'
|
self.assertNoResponse('https://sourceforge.net/tracker/?'
|
||||||
'group_id=58965&atid=489447')
|
'group_id=58965&atid=489447')
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue