Fixed the order of arguments on debversion and made it only do one package at a time.

This commit is contained in:
Jeremy Fincher 2003-10-16 14:03:12 +00:00
parent 1e00aab6d2
commit a6ddd4816c
1 changed files with 30 additions and 30 deletions

View File

@ -40,6 +40,7 @@ import gzip
import sets import sets
import getopt import getopt
import popen2 import popen2
#import urllib
import fnmatch import fnmatch
import os.path import os.path
import urllib2 import urllib2
@ -182,46 +183,45 @@ class Debian(callbacks.Privmsg, plugins.PeriodicFileDownloader):
_debnumpkgsre = re.compile(r'out of total of (\d+)', _debreflags) _debnumpkgsre = re.compile(r'out of total of (\d+)', _debreflags)
_debBranches = ('stable', 'testing', 'unstable', 'experimental') _debBranches = ('stable', 'testing', 'unstable', 'experimental')
def debversion(self, irc, msg, args): def debversion(self, irc, msg, args):
"""<package name> [stable|testing|unstable|experimental] """[stable|testing|unstable|experimental] <package name>
Returns the current version(s) of a Debian package in the given branch Returns the current version(s) of a Debian package in the given branch
(if any, otherwise all available ones are displayed). (if any, otherwise all available ones are displayed).
""" """
if args and args[-1] in self._debBranches: if args and args[0] in self._debBranches:
branch = args.pop() branch = args.pop(0)
else: else:
branch = 'all' branch = 'all'
if not args: if not args:
irc.error(msg, 'You must give a package name.') irc.error(msg, 'You must give a package name.')
responses = [] responses = []
numberOfPackages = 0 numberOfPackages = 0
for package in args: package = privmsgs.getArgs(args)
fd = urllib2.urlopen('http://packages.debian.org/cgi-bin/' \ package = urllib.quote(package)
'search_packages.pl?' \ url = 'http://packages.debian.org/cgi-bin/search_packages.pl?keywords'\
'keywords=%s&searchon=names&' \ '=%s&searchon=names&version=%s&release=all' % (package, branch)
'version=%s&release=all' % \ fd = urllib2.urlopen(url)
(package, branch)) html = fd.read()
html = fd.read() fd.close()
fd.close() m = self._debnumpkgsre.search(html)
m = self._debnumpkgsre.search(html) if m:
if m: numberOfPackages = m.group(1)
numberOfPackages = m.group(1) m = self._debtablere.search(html)
m = self._debtablere.search(html) if m is None:
if m is None: irc.reply(msg, 'No package found for %s (%s)' % \
irc.reply(msg, 'No package found for: %s (%s)' % \ (urllib.unquote(package), branch))
(package, branch)) else:
else: tableData = m.group(1)
tableData = m.group(1) rows = tableData.split('</TR>')
rows = tableData.split('</TR>') for row in rows:
for row in rows: pkgMatch = self._debpkgre.search(row)
pkgMatch = self._debpkgre.search(row) brMatch = self._debbrre.search(row)
brMatch = self._debbrre.search(row) if pkgMatch and brMatch:
if pkgMatch and brMatch: s = '%s (%s)' % (pkgMatch.group(1), brMatch.group(1))
s = '%s (%s)' % (pkgMatch.group(1), brMatch.group(1)) responses.append(s)
responses.append(s) resp = 'Total matches: %s, shown: %s. %s' % \
resp = 'Total matches: %s, shown: %s. %s' % \ (numberOfPackages, len(responses), ', '.join(responses))
(numberOfPackages, len(responses), ', '.join(responses)) irc.reply(msg, resp)
irc.reply(msg, resp)
_incomingRe = re.compile(r'<a href="(.*?\.deb)">', re.I) _incomingRe = re.compile(r'<a href="(.*?\.deb)">', re.I)
def debincoming(self, irc, msg, args): def debincoming(self, irc, msg, args):