Updated to use registry

This commit is contained in:
James Vega 2004-01-20 07:11:00 +00:00
parent 0b11192acf
commit 5f82d72b7e
2 changed files with 33 additions and 25 deletions

View File

@ -38,23 +38,25 @@ __revision__ = "$Id$"
import os import os
import re import re
import csv
import getopt
import string import string
import urllib import urllib
import urllib2 import urllib2
import xml.dom.minidom as minidom import xml.dom.minidom as minidom
from itertools import imap, ifilter from itertools import imap, ifilter
from htmlentitydefs import entitydefs as entities from htmlentitydefs import entitydefs as entities
import csv
import getopt import registry
import conf import conf
import utils import utils
import plugins import plugins
import ircutils import ircutils
import privmsgs import privmsgs
import callbacks import callbacks
import structures import structures
import configurable
statusKeys = ['unconfirmed', 'new', 'assigned', 'reopened', 'resolved', statusKeys = ['unconfirmed', 'new', 'assigned', 'reopened', 'resolved',
'verified', 'closed'] 'verified', 'closed']
@ -96,23 +98,24 @@ 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 bug snarfer enabled by default?') == 'y': if yn('Do you want this bug snarfer enabled by default?') == 'y':
onStart.append('Bugzilla config bug-snarfer on') conf.supybot.plugins.Bugzilla.bugSnarfer.setValue(True)
replyNoBugzilla = 'I don\'t have a bugzilla %r' replyNoBugzilla = 'I don\'t have a bugzilla %r'
conf.registerPlugin('Bugzilla')
conf.registerChannelValue(conf.supybot.plugins.Bugzilla, 'bugSnarfer',
registry.Boolean(False, """Determines whether the bug snarfer will be
enabled, such that any Bugzilla URLs seen in the channel will have their
information reported into the channel."""))
conf.registerChannelValue(conf.supybot.plugins.Bugzilla, 'bold',
registry.Boolean(True, """Determines whether results are bolded."""))
class Bugzilla(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin): class Bugzilla(callbacks.PrivmsgCommandAndRegexp):
"""Show a link to a bug report with a brief description""" """Show a link to a bug report with a brief description"""
threaded = True threaded = True
regexps = ['bzSnarfer'] regexps = ['bzSnarfer']
configurables = configurable.Dictionary(
[('bug-snarfer', configurable.BoolType, False,
"""Determines whether the bug snarfer will be enabled, such that any
Bugzilla URLs seen in the channel will have their information reported
into the channel.""")]
)
def __init__(self): def __init__(self):
configurable.Mixin.__init__(self)
callbacks.PrivmsgCommandAndRegexp.__init__(self) callbacks.PrivmsgCommandAndRegexp.__init__(self)
self.entre = re.compile('&(\S*?);') self.entre = re.compile('&(\S*?);')
# Schema: {name, [url, description]} # Schema: {name, [url, description]}
@ -137,7 +140,6 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
def die(self): def die(self):
self.db.close() self.db.close()
configurable.Mixin.die(self)
def add(self, irc, msg, args): def add(self, irc, msg, args):
"""<name> <url> <description> """<name> <url> <description>
@ -194,7 +196,7 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
def bzSnarfer(self, irc, msg, match): def bzSnarfer(self, irc, msg, match):
r"(http://\S+)/show_bug.cgi\?id=([0-9]+)" r"(http://\S+)/show_bug.cgi\?id=([0-9]+)"
if not self.configurables.get('bug-snarfer', channel=msg.args[0]): if not conf.supybot.plugins.Bugzilla.bugSnarfer():
return return
queryurl = '%s/xml.cgi?id=%s' % (match.group(1), match.group(2)) queryurl = '%s/xml.cgi?id=%s' % (match.group(1), match.group(2))
try: try:
@ -307,18 +309,22 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp, configurable.Mixin):
def _mk_summary_string(self, summary): def _mk_summary_string(self, summary):
L = [] L = []
if conf.supybot.plugins.Bugzilla.bold():
decorate = lambda s: ircutils.bold(s)
else:
decorate = lambda s: s
if 'product' in summary: if 'product' in summary:
L.append(ircutils.bold('Product: ') + summary['product']) L.append(decorate('Product: ') + summary['product'])
if 'component' in summary: if 'component' in summary:
L.append(ircutils.bold('Component: ') + summary['component']) L.append(decorate('Component: ') + summary['component'])
if 'severity' in summary: if 'severity' in summary:
L.append(ircutils.bold('Severity: ') + summary['severity']) L.append(decorate('Severity: ') + summary['severity'])
if 'assigned to' in summary: if 'assigned to' in summary:
L.append(ircutils.bold('Assigned to: ') + summary['assigned to']) L.append(decorate('Assigned to: ') + summary['assigned to'])
if 'status' in summary: if 'status' in summary:
L.append(ircutils.bold('Status: ') + summary['status']) L.append(decorate('Status: ') + summary['status'])
if 'resolution' in summary: if 'resolution' in summary:
L.append(ircutils.bold('Resolution: ') + summary['resolution']) L.append(decorate('Resolution: ') + summary['resolution'])
return ', '.join(imap(str, L)) return ', '.join(imap(str, L))
def _get_short_bug_summary(self, url, desc, number): def _get_short_bug_summary(self, url, desc, number):

View File

@ -48,10 +48,12 @@ if network:
self.assertNotError('search --keywords=fixed gcc alpha') self.assertNotError('search --keywords=fixed gcc alpha')
def testConfigBugzillaSnarfer(self): def testConfigBugzillaSnarfer(self):
self.assertNotError('bugzilla config bug-snarfer off') conf.supybot.plugins.bugzilla.bugSnarfer.setValue(False)
self.assertNoResponse('http://gcc.gnu.org/bugzilla/show_bug.cgi?id=5') self.assertNoResponse(
self.assertNotError('bugzilla config bug-snarfer on') 'http://gcc.gnu.org/bugzilla/show_bug.cgi?id=5')
self.assertNotError('http://gcc.gnu.org/bugzilla/show_bug.cgi?id=5') conf.supybot.plugins.bugzilla.bugSnarfer.setValue(True)
self.assertNotError(
'http://gcc.gnu.org/bugzilla/show_bug.cgi?id=5')
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: