Cleanup of debincoming (also made sure to thread it).

This commit is contained in:
Jeremy Fincher 2003-09-29 06:08:16 +00:00
parent 1470d80a7a
commit 29fd291a5b

View File

@ -40,6 +40,7 @@ import gzip
import sets import sets
import popen2 import popen2
import random import random
import fnmatch
import os.path import os.path
import urllib2 import urllib2
from itertools import imap, ifilter from itertools import imap, ifilter
@ -203,35 +204,25 @@ class Debian(callbacks.Privmsg, PeriodicFileDownloader):
(numberOfPackages, len(responses), ', '.join(responses)) (numberOfPackages, len(responses), ', '.join(responses))
irc.reply(msg, s) irc.reply(msg, s)
_incomingRe = re.compile(r'<a href="(.*?)\.deb">', re.I)
def debincoming(self, irc, msg, args): def debincoming(self, irc, msg, args):
"""<package name> """<package name>
checks debian incoming for specified package name""" checks debian incoming for specified package name"""
pkgname = privmsgs.getArgs(args) pkgname = privmsgs.getArgs(args)
_maxnum = 15 packages = []
fd = urllib2.urlopen('http://incoming.debian.org') fd = urllib2.urlopen('http://incoming.debian.org/')
pkgre = pkgname.replace('.','\.').replace('*','.*') for line in fd:
pkgre = re.compile(r'<a href="(%s)">%s</a>' % (pkgre, pkgre)) m = self._incomingRe.search(line)
line = fd.readline() if m:
pkgs = [] name = m.group(1)
while len(line) != 0: if fnmatch.fnmatch(name, pkgname):
if '.deb"' not in line: packages.append(name)
pass if len(packages) == 0:
else: irc.error(msg, 'No packages matched that search.')
try:
pkgs.append('%s :: ' % pkgre.search(line).group(1))
except AttributeError:
pass
line = fd.readline()
fd.close()
if len(pkgs) <= _maxnum:
s = 'Total matches: %s. %s' % (len(pkgs), ', '.join(pkgs))
elif len(pkgs) > _maxnum:
s = 'Total matches: %s, shown: %s. %s' % \
(len(pkgs), _maxnum, ', '.join(pkgs[:14]))
else: else:
s = 'I didn\'t find any matches for %s' % pkgname irc.reply(msg, utils.commaAndify(packages))
irc.reply(msg, s) debincoming = privmsgs.thread(debincoming)
Class = Debian Class = Debian