mirror of
https://github.com/jlu5/SupyPlugins.git
synced 2025-04-27 05:21:10 -05:00
PkgInfo: sort 'archlinux' output and show repo when in verbose mode
This commit is contained in:
parent
2319948a47
commit
5861d5b15d
@ -250,28 +250,42 @@ class PkgInfo(callbacks.Plugin):
|
|||||||
If --exact is given, will output only exact matches.
|
If --exact is given, will output only exact matches.
|
||||||
"""
|
"""
|
||||||
pkg = pkg.lower()
|
pkg = pkg.lower()
|
||||||
|
|
||||||
if 'exact' in dict(opts):
|
if 'exact' in dict(opts):
|
||||||
encoded = urlencode({'name': pkg})
|
encoded = urlencode({'name': pkg})
|
||||||
else:
|
else:
|
||||||
encoded = urlencode({'q': pkg})
|
encoded = urlencode({'q': pkg})
|
||||||
|
|
||||||
url = 'https://www.archlinux.org/packages/search/json/?' + encoded
|
url = 'https://www.archlinux.org/packages/search/json/?' + encoded
|
||||||
friendly_url = 'https://www.archlinux.org/packages/?' + encoded
|
friendly_url = 'https://www.archlinux.org/packages/?' + encoded
|
||||||
|
|
||||||
self.log.debug("PkgInfo: using url %s for 'archlinux' command", url)
|
self.log.debug("PkgInfo: using url %s for 'archlinux' command", url)
|
||||||
|
|
||||||
fd = utils.web.getUrl(url)
|
fd = utils.web.getUrl(url)
|
||||||
data = json.loads(fd.decode("utf-8"))
|
data = json.loads(fd.decode("utf-8"))
|
||||||
|
|
||||||
if data['valid'] and data['results']:
|
if data['valid'] and data['results']:
|
||||||
# We want one entry per package, but the API gives one
|
# We want one entry per package, but the API gives one
|
||||||
# entry per architecture! Remove duplicates with a set:
|
# entry per architecture! Remove duplicates with a set:
|
||||||
results = set()
|
results = set()
|
||||||
|
|
||||||
|
# For each package, store the available architectures as
|
||||||
|
# a list.
|
||||||
archs = defaultdict(list)
|
archs = defaultdict(list)
|
||||||
for x in data['results']:
|
for pkgdata in data['results']:
|
||||||
s = "\x02{name}\x02 - {desc} \x02({version})\x02".format(
|
# Expand the package data dict into arguments for formatting
|
||||||
name=x['pkgname'], desc=x['pkgdesc'], version=x['pkgver'])
|
s = "\x02{pkgname}\x02 - {pkgdesc} \x02({pkgver})\x02".format(**pkgdata)
|
||||||
|
|
||||||
|
if self.registryValue("verbose"):
|
||||||
|
# In verbose mode, also show the repo the package is in.
|
||||||
|
s += " [\x02%s\x02]" % pkgdata['repo']
|
||||||
|
|
||||||
results.add(s)
|
results.add(s)
|
||||||
archs[s].append(x['arch'])
|
archs[s].append(pkgdata['arch'])
|
||||||
irc.reply(format('Found %n: %L; View more at %u', (len(results),
|
|
||||||
'result'),
|
irc.reply(format('Found %n: %L; View more at %u',
|
||||||
list(results), friendly_url))
|
(len(results), 'result'), sorted(results),
|
||||||
|
friendly_url))
|
||||||
else:
|
else:
|
||||||
irc.error("No results found.", Raise=True)
|
irc.error("No results found.", Raise=True)
|
||||||
archlinux = wrap(archlinux, ['somethingWithoutSpaces', getopts({'exact': ''})])
|
archlinux = wrap(archlinux, ['somethingWithoutSpaces', getopts({'exact': ''})])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user