mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 19:19:32 +01:00
Moved debversion to Debian from Http.
This commit is contained in:
parent
d3fd184995
commit
35c33276ea
@ -35,10 +35,11 @@ Add the module docstring here. This will be used by the setup.py script.
|
||||
|
||||
from baseplugin import *
|
||||
|
||||
import re
|
||||
import sre_constants
|
||||
import gzip
|
||||
import popen2
|
||||
import random
|
||||
import urllib2
|
||||
import re, sre_constants
|
||||
from itertools import imap, ifilter
|
||||
|
||||
import conf
|
||||
@ -123,6 +124,56 @@ class Debian(callbacks.Privmsg, PeriodicFileDownloader):
|
||||
else:
|
||||
irc.reply(msg, ircutils.privmsgPayload(packages, ', '))
|
||||
|
||||
_debreflags = re.DOTALL | re.IGNORECASE
|
||||
_debpkgre = re.compile(r'<a.*>(.*?)</a>', _debreflags)
|
||||
_debbrre = re.compile(r'<td align="center">(\S+)\s*</?td>', _debreflags)
|
||||
_debtablere = re.compile(r'<table\s*[^>]*>(.*?)</table>', _debreflags)
|
||||
_debnumpkgsre = re.compile(r'out of total of (\d+)', _debreflags)
|
||||
_debBranches = ('stable', 'testing', 'unstable', 'experimental')
|
||||
def debversion(self, irc, msg, args):
|
||||
"""<package name> [stable|testing|unstable|experimental]
|
||||
|
||||
Returns the current version(s) of a Debian package in the given branch
|
||||
(if any, otherwise all available ones are displayed).
|
||||
"""
|
||||
if args and args[-1] in self._debBranches:
|
||||
branch = args.pop()
|
||||
else:
|
||||
branch = 'all'
|
||||
if not args:
|
||||
irc.error(msg, 'You must give a package name.')
|
||||
responses = []
|
||||
numberOfPackages = 0
|
||||
for package in args:
|
||||
fd = urllib2.urlopen('http://packages.debian.org/cgi-bin/' \
|
||||
'search_packages.pl?' \
|
||||
'keywords=%s&searchon=names&' \
|
||||
'version=%s&release=all' % \
|
||||
(package, branch))
|
||||
html = fd.read()
|
||||
fd.close()
|
||||
m = self._debnumpkgsre.search(html)
|
||||
if m:
|
||||
numberOfPackages = m.group(1)
|
||||
m = self._debtablere.search(html)
|
||||
if m is None:
|
||||
responses.append('No package found for: %s (%s)' % \
|
||||
(package, branch))
|
||||
else:
|
||||
tableData = m.group(1)
|
||||
rows = tableData.split('</TR>')
|
||||
for row in rows:
|
||||
pkgMatch = self._debpkgre.search(row)
|
||||
brMatch = self._debbrre.search(row)
|
||||
if pkgMatch and brMatch:
|
||||
s = '%s (%s)' % (pkgMatch.group(1), brMatch.group(1))
|
||||
responses.append(s)
|
||||
random.shuffle(responses)
|
||||
ircutils.shrinkList(responses, ', ', 400)
|
||||
s = 'Total matches: %s, shown: %s. %s' % \
|
||||
(numberOfPackages, len(responses), ', '.join(responses))
|
||||
irc.reply(msg, s)
|
||||
|
||||
|
||||
Class = Debian
|
||||
|
||||
|
@ -297,56 +297,6 @@ class Http(callbacks.Privmsg):
|
||||
else:
|
||||
irc.error(msg, 'The format of the was odd.')
|
||||
|
||||
_debreflags = re.DOTALL | re.IGNORECASE
|
||||
_debpkgre = re.compile(r'<a.*>(.*?)</a>', _debreflags)
|
||||
_debbrre = re.compile(r'<td align="center">(\S+)\s*</?td>', _debreflags)
|
||||
_debtablere = re.compile(r'<table\s*[^>]*>(.*?)</table>', _debreflags)
|
||||
_debnumpkgsre = re.compile(r'out of total of (\d+)', _debreflags)
|
||||
_debBranches = ('stable', 'testing', 'unstable', 'experimental')
|
||||
def debversion(self, irc, msg, args):
|
||||
"""<package name> [stable|testing|unstable|experimental]
|
||||
|
||||
Returns the current version(s) of a Debian package in the given branch
|
||||
(if any, otherwise all available ones are displayed).
|
||||
"""
|
||||
if args and args[-1] in self._debBranches:
|
||||
branch = args.pop()
|
||||
else:
|
||||
branch = 'all'
|
||||
if not args:
|
||||
irc.error(msg, 'You must give a package name.')
|
||||
responses = []
|
||||
numberOfPackages = 0
|
||||
for package in args:
|
||||
fd = urllib2.urlopen('http://packages.debian.org/cgi-bin/' \
|
||||
'search_packages.pl?' \
|
||||
'keywords=%s&searchon=names&' \
|
||||
'version=%s&release=all' % \
|
||||
(package, branch))
|
||||
html = fd.read()
|
||||
fd.close()
|
||||
m = self._debnumpkgsre.search(html)
|
||||
if m:
|
||||
numberOfPackages = m.group(1)
|
||||
m = self._debtablere.search(html)
|
||||
if m is None:
|
||||
responses.append('No package found for: %s (%s)' % \
|
||||
(package, branch))
|
||||
else:
|
||||
tableData = m.group(1)
|
||||
rows = tableData.split('</TR>')
|
||||
for row in rows:
|
||||
pkgMatch = self._debpkgre.search(row)
|
||||
brMatch = self._debbrre.search(row)
|
||||
if pkgMatch and brMatch:
|
||||
s = '%s (%s)' % (pkgMatch.group(1), brMatch.group(1))
|
||||
responses.append(s)
|
||||
random.shuffle(responses)
|
||||
ircutils.shrinkList(responses, ', ', 400)
|
||||
s = 'Total matches: %s, shown: %s. %s' % \
|
||||
(numberOfPackages, len(responses), ', '.join(responses))
|
||||
irc.reply(msg, s)
|
||||
|
||||
_abbrevs = utils.abbrev(map(str.lower, babelfish.available_languages))
|
||||
_abbrevs['de'] = 'german'
|
||||
_abbrevs['jp'] = 'japanese'
|
||||
|
Loading…
Reference in New Issue
Block a user