Fix a (probably) long-standing bug with Debian.file and pythonZgrep. Update

Debian.version so that it uses the user's 'package' name as a subword for
which to search.  This better reflects the original behavior of
Debian.version.  Also added --exact option to Debian.version in case people
don't want to use the subword search.
This commit is contained in:
James Vega 2004-04-28 07:54:04 +00:00
parent adad9c1081
commit 349245a78e
2 changed files with 28 additions and 14 deletions

View File

@ -130,7 +130,7 @@ class Debian(callbacks.Privmsg,
glob = rest.pop() glob = rest.pop()
regexp = fnmatch.translate(glob.lstrip('/')) regexp = fnmatch.translate(glob.lstrip('/'))
regexp = regexp.rstrip('$') regexp = regexp.rstrip('$')
regexp += ".* " regexp = ".*%s.* " % regexp
try: try:
re_obj = re.compile(regexp, re.I) re_obj = re.compile(regexp, re.I)
except re.error, e: except re.error, e:
@ -138,12 +138,12 @@ class Debian(callbacks.Privmsg,
return return
if self.registryValue('pythonZgrep'): if self.registryValue('pythonZgrep'):
fd = gzip.open(self.contents) fd = gzip.open(self.contents)
r = imap(lambda tup: tup[0], r = imap(lambda tup: tup[0],
ifilter(lambda tup: tup[0], ifilter(lambda tup: tup[0],
imap(lambda line:(re_obj.search(line), line),fd))) imap(lambda line:(re_obj.search(line), line),fd)))
else: else:
try: try:
(r, w) = popen2.popen4(['zgrep', '-e', regexp, self.contents]) (r, w) = popen2.popen4(['zgrep', '-ie', regexp, self.contents])
w.close() w.close()
except TypeError: except TypeError:
# We're on Windows. # We're on Windows.
@ -160,7 +160,9 @@ class Debian(callbacks.Privmsg,
'please narrow your search.') 'please narrow your search.')
return return
try: try:
(filename, pkg_list) = line[:-1].split() if hasattr(line, 'group'): # we're actually using
line = line.group(0) # pythonZgrep :(
(filename, pkg_list) = line.split()
if filename == 'FILE': if filename == 'FILE':
# This is the last line before the actual files. # This is the last line before the actual files.
continue continue
@ -174,32 +176,42 @@ class Debian(callbacks.Privmsg,
irc.reply('I found no packages with that file.') irc.reply('I found no packages with that file.')
else: else:
irc.reply(utils.commaAndify(packages)) irc.reply(utils.commaAndify(packages))
_debreflags = re.DOTALL | re.IGNORECASE _debreflags = re.DOTALL | re.IGNORECASE
_debbrre = re.compile(r'<li><a href[^>]+>(.*?)</a> \(', _debreflags) _debbrre = re.compile(r'<li><a href[^>]+>(.*?)</a> \(', _debreflags)
_debverre = re.compile(r'<br>(?:\d+:)?(\S+):', _debreflags) _debverre = re.compile(r'<br>(?:\d+:)?(\S+):', _debreflags)
_deblistre = re.compile(r'<h3>Package ([^<]+)</h3>(.*?)</ul>', _debreflags) _deblistre = re.compile(r'<h3>Package ([^<]+)</h3>(.*?)</ul>', _debreflags)
_debBranches = ('stable', 'testing', 'unstable', 'experimental') _debBranches = ('stable', 'testing', 'unstable', 'experimental')
def version(self, irc, msg, args): def version(self, irc, msg, args):
"""[stable|testing|unstable|experimental] <package name> """[--exact] [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 --exact is
specified, only packages whose name exactly matches <package name>
will be reported.
""" """
url = 'http://packages.debian.org/cgi-bin/search_packages.pl?keywords'\
'=%s&searchon=names&version=%s&release=all&subword=1'
if not args: if not args:
raise callbacks.ArgumentError raise callbacks.ArgumentError
if args and args[0] in self._debBranches: (optlist, rest) = getopt.getopt(args, '', ['exact'])
branch = args.pop(0) for (option, _) in optlist:
if option == '--exact':
url = url.replace('&subword=1','')
if rest and rest[0] in self._debBranches:
branch = rest.pop(0)
else: else:
branch = 'all' branch = 'all'
if not args: if not rest:
irc.error('You must give a package name.') irc.error('You must give a package name.')
return return
responses = [] responses = []
package = privmsgs.getArgs(args) package = privmsgs.getArgs(rest)
if '*' in package:
irc.error('Wildcard characters can not be specified.')
return
package = urllib.quote(package) package = urllib.quote(package)
url = 'http://packages.debian.org/cgi-bin/search_packages.pl?keywords'\ url = url % (package, branch)
'=%s&searchon=names&version=%s&release=all' % (package, branch)
try: try:
html = webutils.getUrl(url) html = webutils.getUrl(url)
except webutils.WebError, e: except webutils.WebError, e:
@ -357,7 +369,7 @@ class Debian(callbacks.Privmsg,
irc.reply(resp) irc.reply(resp)
else: else:
irc.reply('I was unable to properly parse the BTS page.') irc.reply('I was unable to properly parse the BTS page.')
Class = Debian Class = Debian
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:

View File

@ -70,6 +70,8 @@ if network:
r'\d+ matches found:.*gaim.*\(stable') r'\d+ matches found:.*gaim.*\(stable')
self.assertRegexp('debian version linux-wlan', self.assertRegexp('debian version linux-wlan',
r'\d+ matches found:.*linux-wlan.*') r'\d+ matches found:.*linux-wlan.*')
self.assertRegexp('debian version --exact linux-wlan',
r'^No package.*\(all\)')
self.assertError('debian version unstable') self.assertError('debian version unstable')
def testDebfile(self): def testDebfile(self):