PkgInfo: add archive.debian.net, remove ancient Ubuntu codenames, cleanup

This commit is contained in:
James Lu 2015-04-26 10:12:59 -07:00
parent aa7c9b383b
commit 4bd17f2b38

View File

@ -66,26 +66,31 @@ class PkgInfo(callbacks.Plugin):
self.__parent = super(PkgInfo, self) self.__parent = super(PkgInfo, self)
self.__parent.__init__(irc) self.__parent.__init__(irc)
self.addrs = {'ubuntu': 'http://packages.ubuntu.com/', self.addrs = {'ubuntu': 'http://packages.ubuntu.com/',
'debian': "https://packages.debian.org/"} 'debian': 'https://packages.debian.org/',
self.unknowndist = _("This command only supports package lookup " # This site is very, VERY slow, but it still works..
"for Debian and Ubuntu. For Arch Linux packages, " 'debian-archive': 'http://archive.debian.net/'}
"see the 'archpkg' and 'archaur' commands. For " self.unknowndist = _("Unknown distribution. This command only supports "
"Linux Mint, use the 'mintpkg' command.") "package lookup for Debian and Ubuntu. For Arch "
"Linux packages, see the 'archpkg' and 'archaur' "
"commands. For Linux Mint, use the 'mintpkg' command.")
def _getDistro(self, release): def _getDistro(self, release):
"""<release> """<release>
Guesses the distribution from the release name.""" Guesses the distribution from the release name."""
release = release.lower() release = release.lower()
debian = ("oldstable", "squeeze", "wheezy", "stable", "jessie", debian = ("oldoldstable", "squeeze", "oldstable", "wheezy", "stable",
"testing", "sid", "unstable", "stretch", "buster", "jessie", "testing", "sid", "unstable", "stretch", "buster",
"experimental") "experimental")
ubuntu = ("hardy", "lucid", "maverick", "natty", "oneiric", "precise", debian_archive = ("bo", "hamm", "slink", "potato", "woody", "sarge",
"quantal", "raring", "saucy", "trusty", "utopic", "vivid") "etch", "lenny")
ubuntu = ("lucid", "precise", "trusty", "utopic", "vivid")
if release.startswith(debian): if release.startswith(debian):
return "debian" return "debian"
elif release.startswith(ubuntu): elif release.startswith(ubuntu):
return "ubuntu" return "ubuntu"
elif release.startswith(debian_archive):
return "debian-archive"
def MadisonParse(self, pkg, dist, codenames='', suite='', reverse=False): def MadisonParse(self, pkg, dist, codenames='', suite='', reverse=False):
"""Parser for the madison API at https://qa.debian.org/madison.php.""" """Parser for the madison API at https://qa.debian.org/madison.php."""
@ -141,7 +146,7 @@ class PkgInfo(callbacks.Plugin):
try: try:
url = self.addrs[distro] url = self.addrs[distro]
except KeyError: except KeyError:
irc.error("Unknown distribution. " + self.unknowndist, Raise=True) irc.error(self.unknowndist, Raise=True)
if source: if source:
url += 'source/' url += 'source/'
url += "{}/{}".format(release, pkg) url += "{}/{}".format(release, pkg)
@ -208,7 +213,7 @@ class PkgInfo(callbacks.Plugin):
getopts({'depends': '', 'source': ''})]) getopts({'depends': '', 'source': ''})])
def vlist(self, irc, msg, args, distro, pkg, opts): def vlist(self, irc, msg, args, distro, pkg, opts):
"""<distribution> <package>[--reverse] """<distribution> <package> [--reverse]
Fetches all available version of <package> in <distribution>, if Fetches all available version of <package> in <distribution>, if
such package exists. Supported entries for <distribution> such package exists. Supported entries for <distribution>
@ -219,8 +224,7 @@ class PkgInfo(callbacks.Plugin):
if distro not in supported: if distro not in supported:
distro = self._getDistro(distro) distro = self._getDistro(distro)
if distro is None: if distro is None:
e = "Unknown distribution. " + self.unknowndist irc.error(self.unknowndist, Raise=True)
irc.error(e, Raise=True)
opts = dict(opts) opts = dict(opts)
reverse = 'reverse' in opts reverse = 'reverse' in opts
d = self.MadisonParse(pkg, distro, reverse=reverse) d = self.MadisonParse(pkg, distro, reverse=reverse)
@ -304,18 +308,19 @@ class PkgInfo(callbacks.Plugin):
def pkgsearch(self, irc, msg, args, opts, query): def pkgsearch(self, irc, msg, args, opts, query):
"""[--distro <distro>] <query> """[--distro <distro>] <query>
Looks up <query> in <distro>'s website (for Debian/Ubuntu).""" Looks up <query> in <distro>'s website. Valid <distro>'s include
'debian', 'ubuntu', and 'debian-archive'."""
opts = dict(opts) opts = dict(opts)
if 'distro' not in opts: if 'distro' not in opts:
distro = 'debian' distro = 'debian'
else: else:
distro = opts['distro'].lower() distro = opts['distro'].lower()
if distro not in ("debian", "ubuntu"): if distro not in self.addrs.keys():
distro = self._getDistro(distro) distro = self._getDistro(distro)
try: try:
url = '%ssearch?keywords=%s' % (self.addrs[distro], quote(query)) url = '%ssearch?keywords=%s' % (self.addrs[distro], quote(query))
except KeyError: except KeyError:
irc.error('Unknown distribution. ' + self.unknowndist, Raise=True) irc.error(self.unknowndist, Raise=True)
try: try:
fd = utils.web.getUrl(url).decode("utf-8") fd = utils.web.getUrl(url).decode("utf-8")
except utils.web.Error as e: except utils.web.Error as e: