2003-08-22 02:46:05 +02:00
|
|
|
###
|
2004-08-23 15:14:06 +02:00
|
|
|
# Copyright (c) 2002-2004, Jeremiah Fincher
|
2003-08-22 02:46:05 +02:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are met:
|
|
|
|
#
|
|
|
|
# * Redistributions of source code must retain the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
# * Neither the name of the author of this software nor the name of
|
|
|
|
# contributors to this software may be used to endorse or promote products
|
|
|
|
# derived from this software without specific prior written consent.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
###
|
|
|
|
|
|
|
|
"""
|
2003-08-27 20:06:26 +02:00
|
|
|
This is a module to contain Debian-specific commands.
|
2003-08-22 02:46:05 +02:00
|
|
|
"""
|
|
|
|
|
2004-09-01 08:06:54 +02:00
|
|
|
import supybot
|
|
|
|
|
2003-11-25 09:23:47 +01:00
|
|
|
__revision__ = "$Id$"
|
2004-09-01 08:06:54 +02:00
|
|
|
__author__ = supybot.authors.jamessan
|
2003-11-25 09:23:47 +01:00
|
|
|
|
2003-08-26 19:08:46 +02:00
|
|
|
import re
|
2003-08-22 02:46:05 +02:00
|
|
|
import gzip
|
2003-09-11 20:46:17 +02:00
|
|
|
import sets
|
2003-10-03 02:23:03 +02:00
|
|
|
import getopt
|
2003-08-22 02:46:05 +02:00
|
|
|
import popen2
|
2003-11-21 19:16:27 +01:00
|
|
|
import socket
|
2003-10-20 19:23:08 +02:00
|
|
|
import urllib
|
2003-09-29 08:08:16 +02:00
|
|
|
import fnmatch
|
2003-08-23 01:00:10 +02:00
|
|
|
import os.path
|
2003-08-22 02:46:05 +02:00
|
|
|
|
2004-08-27 22:02:09 +02:00
|
|
|
import BeautifulSoup
|
|
|
|
|
|
|
|
from itertools import imap, ifilter
|
2004-01-21 05:17:18 +01:00
|
|
|
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.conf as conf
|
|
|
|
import supybot.utils as utils
|
2004-10-23 00:08:03 +02:00
|
|
|
from supybot.commands import *
|
2004-08-27 22:02:09 +02:00
|
|
|
import supybot.plugins as plugins
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.privmsgs as privmsgs
|
2004-08-27 22:02:09 +02:00
|
|
|
import supybot.registry as registry
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.webutils as webutils
|
|
|
|
import supybot.callbacks as callbacks
|
2003-08-22 02:46:05 +02:00
|
|
|
|
|
|
|
|
2004-01-30 00:51:20 +01:00
|
|
|
def configure(advanced):
|
2004-07-25 20:24:51 +02:00
|
|
|
from supybot.questions import output, expect, anything, something, yn
|
2004-01-28 23:19:25 +01:00
|
|
|
conf.registerPlugin('Debian', True)
|
2004-02-06 05:34:52 +01:00
|
|
|
if not utils.findBinaryInPath('zgrep'):
|
2003-08-22 02:46:05 +02:00
|
|
|
if not advanced:
|
2004-02-06 05:34:52 +01:00
|
|
|
output("""I can't find zgrep in your path. This is necessary
|
2004-01-31 23:24:43 +01:00
|
|
|
to run the file command. I'll disable this command
|
2004-02-06 05:34:52 +01:00
|
|
|
now. When you get zgrep in your path, use the command
|
2004-02-09 19:36:39 +01:00
|
|
|
'enable Debian.file' to re-enable the command.""")
|
2004-08-01 17:35:31 +02:00
|
|
|
capabilities = conf.supybot.capabilities()
|
|
|
|
capabilities.add('-Debian.file')
|
|
|
|
conf.supybot.capabilities.set(capabilities)
|
2003-08-22 02:46:05 +02:00
|
|
|
else:
|
2004-02-06 05:34:52 +01:00
|
|
|
output("""I can't find zgrep in your path. If you want to run
|
2004-01-31 23:24:43 +01:00
|
|
|
the file command with any sort of expediency, you'll
|
|
|
|
need it. You can use a python equivalent, but it's
|
|
|
|
about two orders of magnitude slower. THIS MEANS IT
|
|
|
|
WILL TAKE AGES TO RUN THIS COMMAND. Don't do this.""")
|
2004-02-06 05:34:52 +01:00
|
|
|
if yn('Do you want to use a Python equivalent of zgrep?'):
|
2004-02-12 00:39:47 +01:00
|
|
|
conf.supybot.plugins.Debian.pythonZgrep.setValue(True)
|
2003-08-22 02:46:05 +02:00
|
|
|
else:
|
2004-01-31 23:24:43 +01:00
|
|
|
output('I\'ll disable file now.')
|
2004-08-01 17:35:31 +02:00
|
|
|
capabilities = conf.supybot.capabilities()
|
|
|
|
capabilities.add('-Debian.file')
|
|
|
|
conf.supybot.capabilities.set(capabilities)
|
2003-08-22 02:46:05 +02:00
|
|
|
|
2004-01-21 05:17:18 +01:00
|
|
|
conf.registerPlugin('Debian')
|
2004-02-06 05:34:52 +01:00
|
|
|
conf.registerGlobalValue(conf.supybot.plugins.Debian, 'pythonZgrep',
|
2004-01-21 05:17:18 +01:00
|
|
|
registry.Boolean(False, """An advanced option, mostly just for testing;
|
2004-02-06 05:34:52 +01:00
|
|
|
uses a Python-coded zgrep rather than the actual zgrep executable,
|
2004-01-21 05:17:18 +01:00
|
|
|
generally resulting in a 50x slowdown. What would take 2 seconds will
|
|
|
|
take 100 with this enabled. Don't enable this."""))
|
2003-11-22 05:23:59 +01:00
|
|
|
class Debian(callbacks.Privmsg,
|
|
|
|
plugins.PeriodicFileDownloader):
|
2003-08-22 02:46:05 +02:00
|
|
|
threaded = True
|
|
|
|
periodicFiles = {
|
2003-10-03 06:21:37 +02:00
|
|
|
# This file is only updated once a week, so there's no sense in
|
|
|
|
# downloading a new one every day.
|
2003-08-22 02:46:05 +02:00
|
|
|
'Contents-i386.gz': ('ftp://ftp.us.debian.org/'
|
|
|
|
'debian/dists/unstable/Contents-i386.gz',
|
2003-10-03 06:21:37 +02:00
|
|
|
604800, None)
|
2003-08-22 02:46:05 +02:00
|
|
|
}
|
2004-12-16 08:43:13 +01:00
|
|
|
contents = conf.supybot.directories.data.dirize('Contents-i386.gz')
|
2003-08-22 02:46:05 +02:00
|
|
|
def __init__(self):
|
|
|
|
callbacks.Privmsg.__init__(self)
|
2003-10-05 14:56:56 +02:00
|
|
|
plugins.PeriodicFileDownloader.__init__(self)
|
2003-08-22 02:46:05 +02:00
|
|
|
|
2003-11-22 05:23:59 +01:00
|
|
|
def die(self):
|
|
|
|
callbacks.Privmsg.die(self)
|
2003-08-22 02:46:05 +02:00
|
|
|
|
2004-10-23 00:08:03 +02:00
|
|
|
def file(self, irc, msg, args, optlist, glob):
|
2003-10-03 06:21:37 +02:00
|
|
|
"""[--{regexp,exact}=<value>] [<glob>]
|
2003-09-06 20:29:44 +02:00
|
|
|
|
2003-10-03 06:21:37 +02:00
|
|
|
Returns packages in Debian that includes files matching <glob>. If
|
|
|
|
--regexp is given, returns packages that include files matching the
|
|
|
|
given regexp. If --exact is given, returns packages that include files
|
|
|
|
matching exactly the string given.
|
2003-09-06 20:29:44 +02:00
|
|
|
"""
|
2003-08-22 02:46:05 +02:00
|
|
|
self.getFile('Contents-i386.gz')
|
2003-08-23 01:00:10 +02:00
|
|
|
# Make sure it's anchored, make sure it doesn't have a leading slash
|
|
|
|
# (the filenames don't have leading slashes, and people may not know
|
|
|
|
# that).
|
2004-10-23 00:08:03 +02:00
|
|
|
if not optlist and not glob:
|
2003-10-16 03:59:17 +02:00
|
|
|
raise callbacks.ArgumentError
|
2004-10-26 00:59:03 +02:00
|
|
|
if optlist and glob:
|
2004-10-23 00:08:03 +02:00
|
|
|
irc.error('You must specify either a glob or a regexp/exact '
|
2004-12-08 04:19:07 +01:00
|
|
|
'search, but not both.', Raise=True)
|
2003-10-03 06:21:37 +02:00
|
|
|
for (option, arg) in optlist:
|
2004-10-23 00:08:03 +02:00
|
|
|
if option == 'exact':
|
2003-10-03 06:21:37 +02:00
|
|
|
regexp = arg.lstrip('/')
|
2004-10-23 00:08:03 +02:00
|
|
|
elif option == 'regexp':
|
2003-10-03 06:21:37 +02:00
|
|
|
regexp = arg
|
2004-10-23 00:08:03 +02:00
|
|
|
if glob:
|
2003-10-03 06:21:37 +02:00
|
|
|
regexp = fnmatch.translate(glob.lstrip('/'))
|
2004-01-30 00:51:20 +01:00
|
|
|
regexp = regexp.rstrip('$')
|
2004-04-28 09:54:04 +02:00
|
|
|
regexp = ".*%s.* " % regexp
|
2003-08-22 02:46:05 +02:00
|
|
|
try:
|
2003-09-15 04:45:39 +02:00
|
|
|
re_obj = re.compile(regexp, re.I)
|
2003-11-22 05:23:59 +01:00
|
|
|
except re.error, e:
|
2004-12-08 04:19:07 +01:00
|
|
|
irc.error("Error in regexp: %s" % e, Raise=True)
|
2004-02-12 00:39:47 +01:00
|
|
|
if self.registryValue('pythonZgrep'):
|
2003-09-15 04:45:39 +02:00
|
|
|
fd = gzip.open(self.contents)
|
2004-04-28 09:54:04 +02:00
|
|
|
r = imap(lambda tup: tup[0],
|
2003-11-22 05:23:59 +01:00
|
|
|
ifilter(lambda tup: tup[0],
|
|
|
|
imap(lambda line:(re_obj.search(line), line),fd)))
|
2003-10-03 06:21:37 +02:00
|
|
|
else:
|
2003-11-22 05:23:59 +01:00
|
|
|
try:
|
2004-04-28 09:54:04 +02:00
|
|
|
(r, w) = popen2.popen4(['zgrep', '-ie', regexp, self.contents])
|
2003-11-22 05:23:59 +01:00
|
|
|
w.close()
|
|
|
|
except TypeError:
|
|
|
|
# We're on Windows.
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('This command won\'t work on this platform. '
|
2004-12-08 04:19:07 +01:00
|
|
|
'If you think it should (i.e., you know that you '
|
|
|
|
'have a zgrep binary somewhere) then file a bug '
|
|
|
|
'about it at http://supybot.sf.net/ .', Raise=True)
|
2003-09-11 20:46:17 +02:00
|
|
|
packages = sets.Set() # Make packages unique
|
2003-09-05 08:47:12 +02:00
|
|
|
try:
|
2003-09-06 03:06:28 +02:00
|
|
|
for line in r:
|
2003-10-03 06:21:37 +02:00
|
|
|
if len(packages) > 100:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('More than 100 packages matched, '
|
2004-12-08 04:19:07 +01:00
|
|
|
'please narrow your search.', Raise=True)
|
2003-09-05 08:47:12 +02:00
|
|
|
try:
|
2004-04-28 09:54:04 +02:00
|
|
|
if hasattr(line, 'group'): # we're actually using
|
|
|
|
line = line.group(0) # pythonZgrep :(
|
|
|
|
(filename, pkg_list) = line.split()
|
2003-09-05 08:47:12 +02:00
|
|
|
if filename == 'FILE':
|
|
|
|
# This is the last line before the actual files.
|
|
|
|
continue
|
|
|
|
except ValueError: # Unpack list of wrong size.
|
|
|
|
continue # We've not gotten to the files yet.
|
2003-09-11 20:46:17 +02:00
|
|
|
packages.update(pkg_list.split(','))
|
2003-09-05 08:47:12 +02:00
|
|
|
finally:
|
2003-11-22 05:23:59 +01:00
|
|
|
if hasattr(r, 'close'):
|
|
|
|
r.close()
|
2003-08-22 02:46:05 +02:00
|
|
|
if len(packages) == 0:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply('I found no packages with that file.')
|
2003-08-22 02:46:05 +02:00
|
|
|
else:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(utils.commaAndify(packages))
|
2004-10-26 00:59:03 +02:00
|
|
|
file = wrap(file, [getopts({'regexp':'regexpMatcher','exact':'something'}),
|
|
|
|
additional('glob')])
|
2004-04-28 09:54:04 +02:00
|
|
|
|
2003-08-22 02:52:10 +02:00
|
|
|
_debreflags = re.DOTALL | re.IGNORECASE
|
2004-01-21 05:17:18 +01:00
|
|
|
_deblistre = re.compile(r'<h3>Package ([^<]+)</h3>(.*?)</ul>', _debreflags)
|
2004-10-23 00:08:03 +02:00
|
|
|
def version(self, irc, msg, args, optlist, branch, package):
|
|
|
|
"""[--exact] [{stable,testing,unstable,experimental}] <package name>
|
2003-08-22 02:52:10 +02:00
|
|
|
|
|
|
|
Returns the current version(s) of a Debian package in the given branch
|
2004-04-28 09:54:04 +02:00
|
|
|
(if any, otherwise all available ones are displayed). If --exact is
|
|
|
|
specified, only packages whose name exactly matches <package name>
|
|
|
|
will be reported.
|
2003-08-22 02:52:10 +02:00
|
|
|
"""
|
2004-04-28 09:54:04 +02:00
|
|
|
url = 'http://packages.debian.org/cgi-bin/search_packages.pl?keywords'\
|
|
|
|
'=%s&searchon=names&version=%s&release=all&subword=1'
|
|
|
|
for (option, _) in optlist:
|
2004-10-23 00:08:03 +02:00
|
|
|
if option == 'exact':
|
2004-04-28 09:54:04 +02:00
|
|
|
url = url.replace('&subword=1','')
|
2003-08-22 02:52:10 +02:00
|
|
|
responses = []
|
2004-04-28 09:54:04 +02:00
|
|
|
if '*' in package:
|
2004-10-23 00:08:03 +02:00
|
|
|
irc.error('Wildcard characters can not be specified.', Raise=True)
|
2003-10-16 16:03:12 +02:00
|
|
|
package = urllib.quote(package)
|
2004-04-28 09:54:04 +02:00
|
|
|
url = url % (package, branch)
|
2003-11-18 11:49:15 +01:00
|
|
|
try:
|
2004-01-21 05:17:18 +01:00
|
|
|
html = webutils.getUrl(url)
|
|
|
|
except webutils.WebError, e:
|
2004-12-08 04:19:07 +01:00
|
|
|
irc.error('I couldn\'t reach the search page (%s).' % e,Raise=True)
|
2003-12-09 01:32:53 +01:00
|
|
|
if 'is down at the moment' in html:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('Packages.debian.org is down at the moment. '
|
2004-10-23 00:08:03 +02:00
|
|
|
'Please try again later.', Raise=True)
|
2004-01-21 05:17:18 +01:00
|
|
|
pkgs = self._deblistre.findall(html)
|
|
|
|
if not pkgs:
|
2004-01-09 00:03:48 +01:00
|
|
|
irc.reply('No package found for %s (%s)' %
|
|
|
|
(urllib.unquote(package), branch))
|
2003-10-16 16:03:12 +02:00
|
|
|
else:
|
2004-01-21 05:17:18 +01:00
|
|
|
for pkg in pkgs:
|
|
|
|
pkgMatch = pkg[0]
|
2004-08-27 22:02:09 +02:00
|
|
|
soup = BeautifulSoup.BeautifulSoup()
|
|
|
|
soup.feed(pkg[1])
|
|
|
|
liBranches = soup.fetch('li')
|
|
|
|
branches = []
|
|
|
|
versions = []
|
|
|
|
def branchVers(br):
|
|
|
|
vers = [b.next.string.strip() for b in br]
|
|
|
|
return [rsplit(v, ':', 1)[0] for v in vers]
|
|
|
|
for li in liBranches:
|
|
|
|
branches.append(li.first('a').string)
|
|
|
|
versions.append(branchVers(li.fetch('br')))
|
|
|
|
if branches and versions:
|
|
|
|
for pairs in zip(branches, versions):
|
|
|
|
branch = pairs[0]
|
|
|
|
ver = ', '.join(pairs[1])
|
|
|
|
s = '%s (%s)' % (pkgMatch, ': '.join([branch, ver]))
|
2004-01-21 05:17:18 +01:00
|
|
|
responses.append(s)
|
|
|
|
resp = '%s matches found: %s' % \
|
|
|
|
(len(responses), '; '.join(responses))
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(resp)
|
2004-10-23 00:08:03 +02:00
|
|
|
version = wrap(version, [getopts({'exact':''}),
|
|
|
|
optional(('literal', ('stable', 'testing',
|
|
|
|
'unstable', 'experimental')), 'all'),
|
|
|
|
'text'])
|
2003-08-22 02:52:10 +02:00
|
|
|
|
2003-10-03 02:23:03 +02:00
|
|
|
_incomingRe = re.compile(r'<a href="(.*?\.deb)">', re.I)
|
2004-10-23 00:08:03 +02:00
|
|
|
def incoming(self, irc, msg, args, optlist, globs):
|
|
|
|
"""[--{regexp,arch}=<value>] [<glob> ...]
|
2004-07-21 21:36:35 +02:00
|
|
|
|
2003-10-03 02:23:03 +02:00
|
|
|
Checks debian incoming for a matching package name. The arch
|
|
|
|
parameter defaults to i386; --regexp returns only those package names
|
|
|
|
that match a given regexp, and normal matches use standard *nix
|
|
|
|
globbing.
|
|
|
|
"""
|
|
|
|
predicates = []
|
|
|
|
archPredicate = lambda s: ('_i386.' in s)
|
|
|
|
for (option, arg) in optlist:
|
2004-10-23 00:08:03 +02:00
|
|
|
if option == 'regexp':
|
|
|
|
predicates.append(r.search)
|
|
|
|
elif option == 'arch':
|
2003-10-03 02:23:03 +02:00
|
|
|
arg = '_%s.' % arg
|
|
|
|
archPredicate = lambda s, arg=arg: (arg in s)
|
|
|
|
predicates.append(archPredicate)
|
2003-12-08 17:59:46 +01:00
|
|
|
for glob in globs:
|
2004-10-26 00:59:03 +02:00
|
|
|
glob = fnmatch.translate(glob)
|
|
|
|
predicates.append(re.compile(glob).search)
|
2003-09-29 08:08:16 +02:00
|
|
|
packages = []
|
2004-01-21 05:17:18 +01:00
|
|
|
try:
|
|
|
|
fd = webutils.getUrlFd('http://incoming.debian.org/')
|
|
|
|
except webutils.WebError, e:
|
2004-12-08 04:19:07 +01:00
|
|
|
irc.error(str(e), Raise=True)
|
2003-09-29 08:08:16 +02:00
|
|
|
for line in fd:
|
|
|
|
m = self._incomingRe.search(line)
|
|
|
|
if m:
|
|
|
|
name = m.group(1)
|
2004-04-01 17:01:26 +02:00
|
|
|
if all(None, imap(lambda p: p(name), predicates)):
|
2003-10-08 22:56:22 +02:00
|
|
|
realname = rsplit(name, '_', 1)[0]
|
2003-10-03 02:23:03 +02:00
|
|
|
packages.append(realname)
|
2003-09-29 08:08:16 +02:00
|
|
|
if len(packages) == 0:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.error('No packages matched that search.')
|
2003-09-27 05:54:58 +02:00
|
|
|
else:
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.reply(utils.commaAndify(packages))
|
2004-10-23 00:08:03 +02:00
|
|
|
incoming = thread(wrap(incoming,
|
2004-11-30 14:58:50 +01:00
|
|
|
[getopts({'regexp': 'regexpMatcher',
|
|
|
|
'arch': 'something'}),
|
2004-10-26 00:59:03 +02:00
|
|
|
any('glob')]))
|
2004-01-31 01:18:04 +01:00
|
|
|
|
|
|
|
_newpkgre = re.compile(r'<li><a href[^>]+>([^<]+)</a>')
|
2004-10-26 00:59:03 +02:00
|
|
|
def new(self, irc, msg, args, section, glob):
|
2004-10-23 00:08:03 +02:00
|
|
|
"""[{main,contrib,non-free}] [<glob>]
|
2004-01-31 01:18:04 +01:00
|
|
|
|
|
|
|
Checks for packages that have been added to Debian's unstable branch
|
|
|
|
in the past week. If no glob is specified, returns a list of all
|
|
|
|
packages. If no section is specified, defaults to main.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
fd = webutils.getUrlFd(
|
|
|
|
'http://packages.debian.org/unstable/newpkg_%s' % section)
|
|
|
|
except webutils.WebError, e:
|
2004-12-08 04:19:07 +01:00
|
|
|
irc.error(str(e), Raise=True)
|
2004-01-31 01:18:04 +01:00
|
|
|
packages = []
|
|
|
|
for line in fd:
|
|
|
|
m = self._newpkgre.search(line)
|
|
|
|
if m:
|
|
|
|
m = m.group(1)
|
|
|
|
if fnmatch.fnmatch(m, glob):
|
2004-07-21 21:36:35 +02:00
|
|
|
packages.append(m)
|
2004-01-31 01:18:04 +01:00
|
|
|
fd.close()
|
|
|
|
if packages:
|
|
|
|
irc.reply(utils.commaAndify(packages))
|
|
|
|
else:
|
|
|
|
irc.error('No packages matched that search.')
|
2004-10-23 00:08:03 +02:00
|
|
|
new = wrap(new, [optional(('literal', ('main', 'contrib', 'non-free')),
|
|
|
|
'main'),
|
2004-10-26 00:59:03 +02:00
|
|
|
additional('glob', '*')])
|
2004-04-01 19:09:20 +02:00
|
|
|
|
|
|
|
_severity = re.compile(r'.*(?:severity set to `([^\']+)\'|'
|
|
|
|
r'severity:\s+([^\s]+))', re.I)
|
|
|
|
_package = re.compile(r'Package: <[^>]+>([^<]+)<', re.I | re.S)
|
|
|
|
_reporter = re.compile(r'Reported by: <[^>]+>([^<]+)<', re.I | re.S)
|
|
|
|
_subject = re.compile(r'<br>([^<]+)</h1>', re.I | re.S)
|
|
|
|
_date = re.compile(r'Date: ([^;]+);', re.I | re.S)
|
|
|
|
_searches = (_package, _subject, _reporter, _date)
|
2004-10-23 00:08:03 +02:00
|
|
|
def bug(self, irc, msg, args, bug):
|
2004-04-01 19:09:20 +02:00
|
|
|
"""<num>
|
|
|
|
|
|
|
|
Returns a description of the bug with bug id <num>.
|
|
|
|
"""
|
|
|
|
url = 'http://bugs.debian.org/%s' % bug
|
2004-12-08 04:19:07 +01:00
|
|
|
try:
|
|
|
|
text = webutils.getUrl(url)
|
|
|
|
except webutils.WebError, e:
|
|
|
|
irc.error(str(e), Raise=True)
|
2004-04-01 19:09:20 +02:00
|
|
|
if "There is no record of Bug" in text:
|
2004-12-08 04:19:07 +01:00
|
|
|
irc.error('I could not find a bug report matching that number.',
|
|
|
|
Raise=True)
|
2004-04-01 19:09:20 +02:00
|
|
|
searches = map(lambda p: p.search(text), self._searches)
|
|
|
|
sev = self._severity.search(text)
|
|
|
|
# This section should be cleaned up to ease future modifications
|
|
|
|
if all(None, searches):
|
|
|
|
resp = 'Package: %s; Subject: %s; Reported by %s on %s' %\
|
|
|
|
tuple(map(utils.htmlToText,
|
|
|
|
map(lambda p: p.group(1), searches)))
|
|
|
|
if sev:
|
|
|
|
sev = filter(None, sev.groups())
|
|
|
|
if sev:
|
|
|
|
resp = '; '.join([resp, 'Severity: %s' % sev[0],
|
|
|
|
'<%s>' % url])
|
|
|
|
irc.reply(resp)
|
|
|
|
else:
|
|
|
|
irc.reply('I was unable to properly parse the BTS page.')
|
2004-10-23 00:08:03 +02:00
|
|
|
bug = wrap(bug, [('id', 'bug')])
|
2004-04-28 09:54:04 +02:00
|
|
|
|
2004-12-08 04:19:07 +01:00
|
|
|
_dpnRe = re.compile(r'"\+2">([^<]+)</font', re.I)
|
|
|
|
def debianize(self, irc, msg, args, words):
|
|
|
|
"""<text>
|
|
|
|
|
|
|
|
Turns <text> into a 'debian package name' using
|
|
|
|
http://www.pigdog.com/features/dpn.html.
|
|
|
|
"""
|
|
|
|
url = r'http://www.pigdog.org/cgi_bin/dpn.phtml?name=%s'
|
|
|
|
try:
|
|
|
|
text = webutils.getUrl(url % '+'.join(words))
|
|
|
|
except webutils.WebError, e:
|
|
|
|
irc.error(str(e), Raise=True)
|
|
|
|
m = self._dpnRe.search(text)
|
|
|
|
if m is not None:
|
|
|
|
irc.reply(m.group(1))
|
|
|
|
else:
|
|
|
|
irc.errorPossibleBug('Unable to parse webpage.')
|
|
|
|
debianize = wrap(debianize, [many('something')])
|
|
|
|
|
2003-08-22 02:46:05 +02:00
|
|
|
Class = Debian
|
|
|
|
|
|
|
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|