mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-02 17:29:22 +01:00
Lots of changes to make it follow the format of a typical supybot plugin
This commit is contained in:
parent
fcd4919bab
commit
1d1d7a87c2
@ -109,18 +109,15 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp, plugins.Toggleable):
|
|||||||
self.db.close()
|
self.db.close()
|
||||||
del self.db
|
del self.db
|
||||||
|
|
||||||
def addzilla(self, irc, msg, args):
|
def add(self, irc, msg, args):
|
||||||
"""shorthand url description
|
"""<abbreviation> <url> <description>
|
||||||
Add a bugzilla to the list of defined bugzillae.
|
|
||||||
E.g.: addzilla rh http://bugzilla.redhat.com/bugzilla Red Hat Zilla"""
|
Add a bugzilla <url> to the list of defined bugzillae. <abbreviation>
|
||||||
try:
|
is the name that will be used to reference the zilla in all other
|
||||||
words = args
|
commands. <description> is the common name for the bugzilla and will
|
||||||
shorthand = words.pop(0)
|
be listed with the bugzilla query.
|
||||||
url = words.pop(0)
|
E.g.: add rh http://bugzilla.redhat.com/bugzilla Red Hat Zilla"""
|
||||||
description = ' '.join(words)
|
(shorthand, url, description) = privmsgs.getArgs(args, needed=3)
|
||||||
except:
|
|
||||||
irc.reply(msg, 'Invalid format, please see help addzilla')
|
|
||||||
return
|
|
||||||
cursor = self.db.cursor()
|
cursor = self.db.cursor()
|
||||||
cursor.execute("""INSERT INTO bugzillas VALUES (%s, %s, %s)""",
|
cursor.execute("""INSERT INTO bugzillas VALUES (%s, %s, %s)""",
|
||||||
shorthand, url, description)
|
shorthand, url, description)
|
||||||
@ -129,29 +126,37 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp, plugins.Toggleable):
|
|||||||
description, shorthand))
|
description, shorthand))
|
||||||
return
|
return
|
||||||
|
|
||||||
def delzilla(self, irc, msg, args):
|
def remove(self, irc, msg, args):
|
||||||
"""shorthand
|
"""<abbreviation>
|
||||||
Delete a bugzilla from the list of define bugzillae.
|
|
||||||
E.g.: delzilla rh"""
|
Remove the bugzilla associated with <abbreviation> from the list of
|
||||||
shorthand = ' '.join(args)
|
defined bugzillae.
|
||||||
|
E.g.: remove rh"""
|
||||||
|
shorthand = privmsgs.getArgs(args)
|
||||||
cursor = self.db.cursor()
|
cursor = self.db.cursor()
|
||||||
cursor.execute("""SELECT * from bugzillas where shorthand = %s""", shorthand)
|
cursor.execute("""SELECT * from bugzillas where shorthand = %s""",
|
||||||
|
shorthand)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.reply(msg, 'Bugzilla "%s" not defined. Try zillalist.' % shorthand)
|
irc.reply(msg, 'Bugzilla "%s" not defined. Try list.' %
|
||||||
|
shorthand)
|
||||||
return
|
return
|
||||||
cursor.execute("""DELETE FROM bugzillas where shorthand = %s""", shorthand)
|
cursor.execute("""DELETE FROM bugzillas where shorthand = %s""",
|
||||||
|
shorthand)
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
irc.reply(msg, 'Deleted bugzilla "%s"' % shorthand)
|
irc.reply(msg, 'Deleted bugzilla "%s"' % shorthand)
|
||||||
return
|
return
|
||||||
|
|
||||||
def listzilla(self, irc, msg, args):
|
def list(self, irc, msg, args):
|
||||||
"""[shorthand]
|
"""[<abbreviation>]
|
||||||
List defined bugzillae
|
|
||||||
E.g.: listzilla rh; or just listzilla"""
|
List defined bugzillae. If <abbreviation> is specified, list the
|
||||||
shorthand = ' '.join(args)
|
information for that bugzilla.
|
||||||
|
E.g.: list rh; or just list"""
|
||||||
|
shorthand = privmsgs.getArgs(args, needed=0, optional=1)
|
||||||
if shorthand:
|
if shorthand:
|
||||||
cursor = self.db.cursor()
|
cursor = self.db.cursor()
|
||||||
cursor.execute("""SELECT url,description from bugzillas where shorthand = %s""", shorthand)
|
cursor.execute("""SELECT url,description from bugzillas where
|
||||||
|
shorthand = %s""", shorthand)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.reply(msg, 'No such bugzilla defined: "%s".' % shorthand)
|
irc.reply(msg, 'No such bugzilla defined: "%s".' % shorthand)
|
||||||
return
|
return
|
||||||
@ -162,18 +167,20 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp, plugins.Toggleable):
|
|||||||
cursor = self.db.cursor()
|
cursor = self.db.cursor()
|
||||||
cursor.execute("""SELECT shorthand from bugzillas""")
|
cursor.execute("""SELECT shorthand from bugzillas""")
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.reply(msg, 'No bugzillae defined. Add some with "addzilla"!')
|
irc.reply(msg, 'No bugzillae defined. Add some with "add"!')
|
||||||
return
|
return
|
||||||
results = ['%s' % (item[0]) for item in cursor.fetchall()]
|
results = ['%s' % (item[0]) for item in cursor.fetchall()]
|
||||||
irc.reply(msg, 'Defined bugzillae: %s' % ' '.join(results))
|
irc.reply(msg, 'Defined bugzillae: %s' % ' '.join(results))
|
||||||
return
|
return
|
||||||
|
|
||||||
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.toggles.get('bug', channel=msg.args[0]):
|
if not self.toggles.get('bug', channel=msg.args[0]):
|
||||||
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:
|
||||||
summary = self._get_short_bug_summary(queryurl, "Snarfed Bugzilla URL", match.group(2))
|
summary = self._get_short_bug_summary(queryurl, 'Snarfed '\
|
||||||
|
'Bugzilla URL', match.group(2))
|
||||||
except BugError, e:
|
except BugError, e:
|
||||||
irc.reply(msg, str(e))
|
irc.reply(msg, str(e))
|
||||||
return
|
return
|
||||||
@ -182,23 +189,24 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp, plugins.Toggleable):
|
|||||||
irc.reply(msg, msgtouser)
|
irc.reply(msg, msgtouser)
|
||||||
return
|
return
|
||||||
report = {}
|
report = {}
|
||||||
report['zilla'] = "Snarfed Bugzilla URL"
|
|
||||||
report['id'] = match.group(2)
|
report['id'] = match.group(2)
|
||||||
report['url'] = str('%s/show_bug.cgi?id=%s' % (match.group(1), match.group(2)))
|
report['url'] = str('%s/show_bug.cgi?id=%s' % (match.group(1),
|
||||||
|
match.group(2)))
|
||||||
report['title'] = str(summary['title'])
|
report['title'] = str(summary['title'])
|
||||||
report['summary'] = str(self._mk_summary_string(summary))
|
report['summary'] = str(self._mk_summary_string(summary))
|
||||||
irc.reply(msg, '%(zilla)s bug #%(id)s: %(title)s %(summary)s %(url)s' % report)
|
report['product'] = str(summary['product'])
|
||||||
|
irc.reply(msg, '%(product)s bug #%(id)s: %(title)s %(summary)s'
|
||||||
|
% report, prefixName = False)
|
||||||
|
|
||||||
def bug(self, irc, msg, args):
|
def bug(self, irc, msg, args):
|
||||||
"""bug shorthand number
|
"""<abbreviation> <number>
|
||||||
Look up a bug number in a bugzilla.
|
|
||||||
|
Look up bug <number> in the bugzilla associated with <abbreviation>.
|
||||||
E.g.: bug rh 10301"""
|
E.g.: bug rh 10301"""
|
||||||
try: shorthand, num = args
|
(shorthand, num) = privmsgs.getArgs(args, needed=2)
|
||||||
except:
|
|
||||||
irc.reply(msg, 'Invalid format. Try help bug')
|
|
||||||
return
|
|
||||||
cursor = self.db.cursor()
|
cursor = self.db.cursor()
|
||||||
cursor.execute("""SELECT url,description from bugzillas where shorthand = %s""", shorthand)
|
cursor.execute("""SELECT url,description from bugzillas where
|
||||||
|
shorthand = %s""", shorthand)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.reply(msg, 'Bugzilla "%s" is not defined.' % shorthand)
|
irc.reply(msg, 'Bugzilla "%s" is not defined.' % shorthand)
|
||||||
return
|
return
|
||||||
@ -223,23 +231,24 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp, plugins.Toggleable):
|
|||||||
report['url'] = str('%s/show_bug.cgi?id=%s' % (url, num))
|
report['url'] = str('%s/show_bug.cgi?id=%s' % (url, num))
|
||||||
report['title'] = str(summary['title'])
|
report['title'] = str(summary['title'])
|
||||||
report['summary'] = str(self._mk_summary_string(summary))
|
report['summary'] = str(self._mk_summary_string(summary))
|
||||||
irc.reply(msg, '%(zilla)s bug #%(id)s: %(title)s %(summary)s %(url)s' % report)
|
irc.reply(msg, '%(zilla)s bug #%(id)s: %(title)s %(summary)s %(url)s'
|
||||||
|
% report)
|
||||||
return
|
return
|
||||||
|
|
||||||
def _mk_summary_string(self, summary):
|
def _mk_summary_string(self, summary):
|
||||||
ary = []
|
ary = []
|
||||||
if summary.has_key('component'):
|
if 'product' in summary:
|
||||||
|
ary.append(ircutils.bold('Product: ') + summary['product'])
|
||||||
|
if 'component' in summary:
|
||||||
ary.append(ircutils.bold('Component: ') + summary['component'])
|
ary.append(ircutils.bold('Component: ') + summary['component'])
|
||||||
if summary.has_key('severity'):
|
if 'severity' in summary:
|
||||||
ary.append(ircutils.bold('Severity: ') + summary['severity'])
|
ary.append(ircutils.bold('Severity: ') + summary['severity'])
|
||||||
if summary.has_key('assigned to'):
|
if 'assigned to' in summary:
|
||||||
ary.append(ircutils.bold('Assigned to: ') + summary['assigned to'])
|
ary.append(ircutils.bold('Assigned to: ') + summary['assigned to'])
|
||||||
if summary.has_key('status'):
|
if 'status' in summary:
|
||||||
if summary.has_key('resolution'):
|
ary.append(ircutils.bold('Status: ') + summary['status'])
|
||||||
ary.append(ircutils.bold('Status: ') + '%s/%s' %
|
if 'resolution' in summary:
|
||||||
(summary['status'], summary['resolution']))
|
ary.append(ircutils.bold('Resolution: ') + summary['resolution'])
|
||||||
else:
|
|
||||||
ary.append(ircutils.bold('Status: ') + summary['status'])
|
|
||||||
out = string.join(ary, ', ')
|
out = string.join(ary, ', ')
|
||||||
return out
|
return out
|
||||||
|
|
||||||
@ -273,6 +282,8 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp, plugins.Toggleable):
|
|||||||
pass
|
pass
|
||||||
node = bug_n.getElementsByTagName('assigned_to')[0]
|
node = bug_n.getElementsByTagName('assigned_to')[0]
|
||||||
summary['assigned to'] = self._getnodetxt(node)
|
summary['assigned to'] = self._getnodetxt(node)
|
||||||
|
node = bug_n.getElementsByTagName('product')[0]
|
||||||
|
summary['product'] = self._getnodetxt(node)
|
||||||
node = bug_n.getElementsByTagName('component')[0]
|
node = bug_n.getElementsByTagName('component')[0]
|
||||||
summary['component'] = self._getnodetxt(node)
|
summary['component'] = self._getnodetxt(node)
|
||||||
node = bug_n.getElementsByTagName('bug_severity')[0]
|
node = bug_n.getElementsByTagName('bug_severity')[0]
|
||||||
@ -319,4 +330,7 @@ class Bugzilla(callbacks.PrivmsgCommandAndRegexp, plugins.Toggleable):
|
|||||||
else:
|
else:
|
||||||
val = re.sub(entre, '_', val)
|
val = re.sub(entre, '_', val)
|
||||||
return val
|
return val
|
||||||
|
|
||||||
Class = Bugzilla
|
Class = Bugzilla
|
||||||
|
|
||||||
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
Loading…
Reference in New Issue
Block a user