mirror of
https://github.com/jlu5/SupyPlugins.git
synced 2025-04-30 07:21:12 -05:00
PkgInfo: reduce code duplication between guess_distro and get_distro_fetcher
This commit is contained in:
parent
f6e499d85e
commit
8b6ab5965d
@ -113,7 +113,7 @@ addrs = {'ubuntu': 'https://packages.ubuntu.com/',
|
|||||||
'debian-archive': 'http://archive.debian.net/'}
|
'debian-archive': 'http://archive.debian.net/'}
|
||||||
_normalize = lambda text: utils.str.normalizeWhitespace(text).strip()
|
_normalize = lambda text: utils.str.normalizeWhitespace(text).strip()
|
||||||
|
|
||||||
def _getDistro(release):
|
def _guess_distro(release):
|
||||||
"""<release>
|
"""<release>
|
||||||
|
|
||||||
Guesses the distribution from the release name."""
|
Guesses the distribution from the release name."""
|
||||||
@ -121,15 +121,12 @@ def _getDistro(release):
|
|||||||
debian = ("oldoldstable", "oldstable", "wheezy", "stable",
|
debian = ("oldoldstable", "oldstable", "wheezy", "stable",
|
||||||
"jessie", "testing", "sid", "unstable", "stretch", "buster",
|
"jessie", "testing", "sid", "unstable", "stretch", "buster",
|
||||||
"experimental", "bullseye")
|
"experimental", "bullseye")
|
||||||
debian_archive = ("bo", "hamm", "slink", "potato", "woody", "sarge",
|
|
||||||
"etch", "lenny", "squeeze")
|
|
||||||
ubuntu = ("precise", "trusty", "xenial", "yakkety", "zesty", "artful")
|
ubuntu = ("precise", "trusty", "xenial", "yakkety", "zesty", "artful")
|
||||||
|
|
||||||
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"
|
|
||||||
|
|
||||||
class UnknownDistributionError(ValueError):
|
class UnknownDistributionError(ValueError):
|
||||||
pass
|
pass
|
||||||
@ -150,16 +147,11 @@ class PkgInfo(callbacks.Plugin):
|
|||||||
})
|
})
|
||||||
|
|
||||||
def get_distro_fetcher(self, dist):
|
def get_distro_fetcher(self, dist):
|
||||||
dist = dist.lower()
|
dist = _guess_distro(dist)
|
||||||
|
|
||||||
debian = ("oldoldstable", "oldstable", "wheezy", "stable",
|
if dist == 'debian':
|
||||||
"jessie", "testing", "sid", "unstable", "stretch", "buster",
|
|
||||||
"experimental", "bullseye")
|
|
||||||
ubuntu = ("precise", "trusty", "xenial", "yakkety", "zesty", "artful")
|
|
||||||
|
|
||||||
if dist.startswith(debian):
|
|
||||||
return self.debian_fetcher
|
return self.debian_fetcher
|
||||||
elif dist.startswith(ubuntu):
|
elif dist == 'ubuntu':
|
||||||
return self.ubuntu_fetcher
|
return self.ubuntu_fetcher
|
||||||
|
|
||||||
def debian_fetcher(self, release, query, baseurl='https://packages.debian.org/', fetch_source=False, fetch_depends=False):
|
def debian_fetcher(self, release, query, baseurl='https://packages.debian.org/', fetch_source=False, fetch_depends=False):
|
||||||
@ -302,7 +294,7 @@ class PkgInfo(callbacks.Plugin):
|
|||||||
pkg, distro = map(str.lower, (pkg, distro))
|
pkg, distro = map(str.lower, (pkg, distro))
|
||||||
supported = ("debian", "ubuntu", "derivatives", "all")
|
supported = ("debian", "ubuntu", "derivatives", "all")
|
||||||
if distro not in supported:
|
if distro not in supported:
|
||||||
distro = _getDistro(distro)
|
distro = _guess_distro(distro)
|
||||||
if distro is None:
|
if distro is None:
|
||||||
irc.error(unknowndist, Raise=True)
|
irc.error(unknowndist, Raise=True)
|
||||||
opts = dict(opts)
|
opts = dict(opts)
|
||||||
@ -411,7 +403,7 @@ class PkgInfo(callbacks.Plugin):
|
|||||||
'debian', 'ubuntu', and 'debian-archive'."""
|
'debian', 'ubuntu', and 'debian-archive'."""
|
||||||
distro = distro.lower()
|
distro = distro.lower()
|
||||||
if distro not in addrs.keys():
|
if distro not in addrs.keys():
|
||||||
distro = _getDistro(distro)
|
distro = _guess_distro(distro)
|
||||||
try:
|
try:
|
||||||
url = '%ssearch?keywords=%s' % (addrs[distro], quote(query))
|
url = '%ssearch?keywords=%s' % (addrs[distro], quote(query))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@ -454,7 +446,7 @@ class PkgInfo(callbacks.Plugin):
|
|||||||
Searches what package in Debian or Ubuntu has which file. <release> is the
|
Searches what package in Debian or Ubuntu has which file. <release> is the
|
||||||
codename/release name (e.g. xenial or jessie)."""
|
codename/release name (e.g. xenial or jessie)."""
|
||||||
release = release.lower()
|
release = release.lower()
|
||||||
distro = _getDistro(release)
|
distro = _guess_distro(release)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
url = '%ssearch?keywords=%s&searchon=contents&suite=%s' % (addrs[distro], quote(query), quote(release))
|
url = '%ssearch?keywords=%s&searchon=contents&suite=%s' % (addrs[distro], quote(query), quote(release))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user