commands.wrap update

This commit is contained in:
James Vega 2004-10-15 13:28:27 +00:00
parent d761590f3c
commit 8dd75b1ff2
2 changed files with 34 additions and 29 deletions

View File

@ -48,7 +48,7 @@ from htmlentitydefs import entitydefs as entities
import supybot.conf as conf import supybot.conf as conf
import supybot.utils as utils import supybot.utils as utils
import supybot.plugins as plugins import supybot.plugins as plugins
from supybot.commands import wrap from supybot.commands import *
import supybot.ircutils as ircutils import supybot.ircutils as ircutils
import supybot.privmsgs as privmsgs import supybot.privmsgs as privmsgs
import supybot.registry as registry import supybot.registry as registry
@ -98,7 +98,7 @@ conf.registerChannelValue(conf.supybot.plugins.Bugzilla, 'snarfTarget',
class Bugzillae(registry.SpaceSeparatedListOfStrings): class Bugzillae(registry.SpaceSeparatedListOfStrings):
List = ircutils.IrcSet List = ircutils.IrcSet
conf.registerGlobalValue(conf.supybot.plugins.Bugzilla, 'bugzillae', conf.registerGlobalValue(conf.supybot.plugins.Bugzilla, 'bugzillae',
Bugzillae([], """Determines what bugzillae will be added to the bot when it Bugzillae([], """Determines what bugzillae will be added to the bot when it
starts.""")) starts."""))
@ -147,7 +147,7 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp):
query.append('ctype=csv') query.append('ctype=csv')
return query return query
def add(self, irc, msg, args): def add(self, irc, msg, args, name, url, description):
"""<name> <url> [<description>] """<name> <url> [<description>]
Add a bugzilla <url> to the list of defined bugzillae. <name> Add a bugzilla <url> to the list of defined bugzillae. <name>
@ -156,7 +156,6 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp):
<description> is the common name for the bugzilla and will <description> is the common name for the bugzilla and will
be listed with the bugzilla query; if not given, it defaults to <name>. be listed with the bugzilla query; if not given, it defaults to <name>.
""" """
(name, url, description) = privmsgs.getArgs(args,required=2,optional=1)
if not description: if not description:
description = name description = name
if url[-1] == '/': if url[-1] == '/':
@ -165,14 +164,14 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp):
registerBugzilla(name, url, description) registerBugzilla(name, url, description)
self.shorthand = utils.abbrev(self.db.keys()) self.shorthand = utils.abbrev(self.db.keys())
irc.replySuccess() irc.replySuccess()
add = wrap(add, ['text', 'url', additional('text')])
def remove(self, irc, msg, args): def remove(self, irc, msg, args, name):
"""<abbreviation> """<abbreviation>
Remove the bugzilla associated with <abbreviation> from the list of Remove the bugzilla associated with <abbreviation> from the list of
defined bugzillae. defined bugzillae.
""" """
name = privmsgs.getArgs(args)
try: try:
name = self.shorthand[name] name = self.shorthand[name]
del self.db[name] del self.db[name]
@ -182,14 +181,14 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp):
except KeyError: except KeyError:
s = self.registryValue('replyNoBugzilla', msg.args[0]) s = self.registryValue('replyNoBugzilla', msg.args[0])
irc.error(s % name) irc.error(s % name)
remove = wrap(remove, ['text'])
def list(self, irc, msg, args): def list(self, irc, msg, args, name):
"""[<abbreviation>] """[<abbreviation>]
List defined bugzillae. If <abbreviation> is specified, list the List defined bugzillae. If <abbreviation> is specified, list the
information for that bugzilla. information for that bugzilla.
""" """
name = privmsgs.getArgs(args, required=0, optional=1)
if name: if name:
try: try:
name = self.shorthand[name] name = self.shorthand[name]
@ -205,10 +204,11 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp):
irc.reply(utils.commaAndify(L)) irc.reply(utils.commaAndify(L))
else: else:
irc.reply('I have no defined bugzillae.') irc.reply('I have no defined bugzillae.')
list = wrap(list, [additional('text')])
def bugzSnarf(self, irc, msg, match): def bugzSnarf(self, irc, msg, match):
r"""\bbug\b(?:id|ids|#)?\s+(?:id|ids|#)?(?P<bug>\d+)""" r"""\bbug\b(?:id|ids|#)?\s+(?:id|ids|#)?(?P<bug>\d+)"""
snarfTarget = self.registryValue('snarfTarget') snarfTarget = self.registryValue('snarfTarget')
if not snarfTarget: if not snarfTarget:
return return
@ -304,18 +304,16 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp):
u.close() u.close()
return bugs return bugs
def search(self, irc, msg, args): def search(self, irc, msg, args, optlist, name, searchstr):
"""[--keywords=<keyword>] <bugzilla name> <search string in desc> """[--keywords=<keyword>] <bugzilla name> <search string in desc>
Look for bugs with <search string in the desc>, also matching Look for bugs with <search string in the desc>, also matching
<keywords>. <keywords> can be statuses, severities, priorities, or <keywords>. <keywords> can be statuses, severities, priorities, or
resolutions, separated by commas""" resolutions, separated by commas"""
keywords = None keywords = None
(optlist, rest) = getopt.getopt(args, '', ['keywords='])
for (option, arguments) in optlist: for (option, arguments) in optlist:
if option == '--keywords': if option == 'keywords':
keywords = arguments.split(',') keywords = arguments.split(',')
(name,searchstr)= privmsgs.getArgs(rest, required=2)
if not keywords: if not keywords:
keywords = ['UNCONFIRMED', 'NEW', 'ASSIGNED', 'REOPENED'] keywords = ['UNCONFIRMED', 'NEW', 'ASSIGNED', 'REOPENED']
query = self.keywords2query(keywords) query = self.keywords2query(keywords)
@ -339,13 +337,13 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp):
(utils.nItems('bug', len(bugs)), searchstr, (utils.nItems('bug', len(bugs)), searchstr,
' AND '.join(keywords), utils.commaAndify(map(str, bugids))) ' AND '.join(keywords), utils.commaAndify(map(str, bugids)))
irc.reply(s) irc.reply(s)
search = wrap(search, [getopts({'keywords':'text'}), 'text', 'text'])
def bug(self, irc, msg, args): def bug(self, irc, msg, args, name, number):
"""<abbreviation> <number> """<abbreviation> <number>
Look up bug <number> in the bugzilla associated with <abbreviation>. Look up bug <number> in the bugzilla associated with <abbreviation>.
""" """
(name, number) = privmsgs.getArgs(args, required=2)
try: try:
name = self.shorthand[name] name = self.shorthand[name]
(url, description) = self.db[name] (url, description) = self.db[name]
@ -371,6 +369,7 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp):
report['summary'] = self._mk_summary_string(summary, bold) report['summary'] = self._mk_summary_string(summary, bold)
s = '%(zilla)s bug #%(id)s: %(title)s %(summary)s %(url)s' % report s = '%(zilla)s bug #%(id)s: %(title)s %(summary)s %(url)s' % report
irc.reply(s) irc.reply(s)
bug = wrap(bug, ['text', ('id', 'bug')])
def _mk_summary_string(self, summary, bold): def _mk_summary_string(self, summary, bold):
L = [] L = []

View File

@ -30,7 +30,7 @@
from testsupport import * from testsupport import *
if network: if network:
class BugzillaTest(PluginTestCase, PluginDocumentation): class BugzillaTest(ChannelPluginTestCase):
plugins = ('Bugzilla',) plugins = ('Bugzilla',)
def testBug(self): def testBug(self):
self.assertNotError('add gcc http://gcc.gnu.org/bugzilla gcc') self.assertNotError('add gcc http://gcc.gnu.org/bugzilla gcc')
@ -44,25 +44,31 @@ if network:
def testSearch(self): def testSearch(self):
self.assertNotError('add gcc http://gcc.gnu.org/bugzilla gcc') self.assertNotError('add gcc http://gcc.gnu.org/bugzilla gcc')
self.assertNotError('search gcc alpha') self.assertNotError('bugzilla search gcc alpha')
self.assertNotError('search --keywords=fixed gcc alpha') self.assertNotError('bugzilla search --keywords=fixed gcc alpha')
def testConfigBugzillaSnarfer(self): def testConfigBugzillaSnarfer(self):
self.assertNotError('add gcc http://gcc.gnu.org/bugzilla gcc') try:
conf.supybot.plugins.bugzilla.bugSnarfer.setValue(False) self.assertNotError('add gcc http://gcc.gnu.org/bugzilla gcc')
self.assertNoResponse( conf.supybot.plugins.bugzilla.bugSnarfer.setValue(False)
self.assertSnarfNoResponse(
'http://gcc.gnu.org/bugzilla/show_bug.cgi?id=5') 'http://gcc.gnu.org/bugzilla/show_bug.cgi?id=5')
conf.supybot.plugins.bugzilla.bugSnarfer.setValue(True) conf.supybot.plugins.bugzilla.bugSnarfer.setValue(True)
self.assertNotError( self.assertSnarfNotError(
'http://gcc.gnu.org/bugzilla/show_bug.cgi?id=5') 'http://gcc.gnu.org/bugzilla/show_bug.cgi?id=5')
finally:
conf.supybot.plugins.bugzilla.bugSnarfer.setValue(False)
def testConfigBugSnarfer(self): def testConfigBugSnarfer(self):
self.assertNotError('add gcc http://gcc.gnu.org/bugzilla gcc') try:
conf.supybot.plugins.bugzilla.snarfTarget.setValue('gcc') self.assertNotError('add gcc http://gcc.gnu.org/bugzilla gcc')
conf.supybot.plugins.bugzilla.bugSnarfer.setValue(False) conf.supybot.plugins.bugzilla.snarfTarget.setValue('gcc')
self.assertNoResponse('blah blah bug 5') conf.supybot.plugins.bugzilla.bugSnarfer.setValue(False)
conf.supybot.plugins.bugzilla.bugSnarfer.setValue(True) self.assertNoResponse('blah blah bug 5')
self.assertNotError('blah blah bug 5') conf.supybot.plugins.bugzilla.bugSnarfer.setValue(True)
self.assertNotError('blah blah bug 5')
finally:
conf.supybot.plugins.bugzilla.bugSnarfer.setValue(False)
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: