mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-06 17:44:09 +01:00
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:
parent
adad9c1081
commit
349245a78e
@ -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:
|
||||||
@ -143,7 +143,7 @@ class Debian(callbacks.Privmsg,
|
|||||||
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
|
||||||
@ -181,25 +183,35 @@ class Debian(callbacks.Privmsg,
|
|||||||
_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:
|
||||||
|
@ -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):
|
||||||
|
Loading…
Reference in New Issue
Block a user