mirror of
https://github.com/jlu5/SupyPlugins.git
synced 2025-05-03 08:51:13 -05:00
PkgInfo: more consistency in pluralization and "View more at" URLs
This commit is contained in:
parent
14a5e4382d
commit
48d900b6f5
@ -97,7 +97,7 @@ class MadisonParser():
|
|||||||
|
|
||||||
class PkgInfo(callbacks.Plugin):
|
class PkgInfo(callbacks.Plugin):
|
||||||
"""Fetches package information from the repositories of
|
"""Fetches package information from the repositories of
|
||||||
Debian, Arch Linux, Linux Mint, Fedora, CentOS, and Ubuntu."""
|
Arch Linux, CentOS, Debian, Fedora, FreeBSD, Linux Mint, and Ubuntu."""
|
||||||
threaded = True
|
threaded = True
|
||||||
|
|
||||||
def __init__(self, irc):
|
def __init__(self, irc):
|
||||||
@ -108,7 +108,7 @@ class PkgInfo(callbacks.Plugin):
|
|||||||
# This site is very, VERY slow, but it still works..
|
# This site is very, VERY slow, but it still works..
|
||||||
'debian-archive': 'http://archive.debian.net/'}
|
'debian-archive': 'http://archive.debian.net/'}
|
||||||
self.unknowndist = _("Unknown distribution. This command only supports "
|
self.unknowndist = _("Unknown distribution. This command only supports "
|
||||||
"package lookup for Debian and Ubuntu. For "
|
"package lookup for Debian and Ubuntu. For a list of"
|
||||||
"commands for other distros' packages, use "
|
"commands for other distros' packages, use "
|
||||||
"'list PkgInfo'.")
|
"'list PkgInfo'.")
|
||||||
|
|
||||||
@ -240,7 +240,7 @@ class PkgInfo(callbacks.Plugin):
|
|||||||
irc.error("No results found.", Raise=True)
|
irc.error("No results found.", Raise=True)
|
||||||
try:
|
try:
|
||||||
url = "{}search?keywords={}".format(self.addrs[distro], pkg)
|
url = "{}search?keywords={}".format(self.addrs[distro], pkg)
|
||||||
d += format(" View more at: %u", url)
|
d += format("; View more at: %u", url)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
irc.reply(d)
|
irc.reply(d)
|
||||||
@ -254,11 +254,12 @@ 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()
|
||||||
baseurl = 'https://www.archlinux.org/packages/search/json/?'
|
|
||||||
if 'exact' in dict(opts):
|
if 'exact' in dict(opts):
|
||||||
url = baseurl + urlencode({'name': pkg})
|
encoded = urlencode({'name': pkg})
|
||||||
else:
|
else:
|
||||||
url = baseurl + urlencode({'q': pkg})
|
encoded = urlencode({'q': pkg})
|
||||||
|
url = 'https://www.archlinux.org/packages/search/json/?' + 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"))
|
||||||
@ -275,8 +276,9 @@ class PkgInfo(callbacks.Plugin):
|
|||||||
count = len(results)
|
count = len(results)
|
||||||
items = [format("%s \x02[%s]\x02", s, ', '.join(archs[s])) for s
|
items = [format("%s \x02[%s]\x02", s, ', '.join(archs[s])) for s
|
||||||
in results]
|
in results]
|
||||||
irc.reply(format('Found %n: %L', (len(results), 'result'),
|
irc.reply(format('Found %n: %L; View more at %u', (len(results),
|
||||||
list(results)))
|
'result'),
|
||||||
|
list(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': ''})])
|
||||||
@ -308,7 +310,9 @@ class PkgInfo(callbacks.Plugin):
|
|||||||
s += "{name} - {desc} \x02({version} {verbose})\x02, " \
|
s += "{name} - {desc} \x02({version} {verbose})\x02, " \
|
||||||
.format(name=x['Name'], desc=x['Description'],
|
.format(name=x['Name'], desc=x['Description'],
|
||||||
version=x['Version'], verbose=verboseInfo)
|
version=x['Version'], verbose=verboseInfo)
|
||||||
irc.reply(s[:-2]) # cut off the ", " at the end
|
friendly_url = 'https://aur.archlinux.org/packages/?' + \
|
||||||
|
urlencode({'K': pkg})
|
||||||
|
irc.reply(s + format('View more at: %u', friendly_url))
|
||||||
else:
|
else:
|
||||||
irc.error("No results found.", Raise=True)
|
irc.error("No results found.", Raise=True)
|
||||||
archaur = wrap(archaur, ['somethingWithoutSpaces'])
|
archaur = wrap(archaur, ['somethingWithoutSpaces'])
|
||||||
@ -429,7 +433,10 @@ class PkgInfo(callbacks.Plugin):
|
|||||||
return s
|
return s
|
||||||
results = ['%s: %s' % (ircutils.bold(pkg['name']), formatdesc(pkg['description']))
|
results = ['%s: %s' % (ircutils.bold(pkg['name']), formatdesc(pkg['description']))
|
||||||
for pkg in data["packages"]]
|
for pkg in data["packages"]]
|
||||||
irc.reply('; '.join(results))
|
friendly_url = 'https://apps.fedoraproject.org/packages/s/%s' % query
|
||||||
|
s = format('Found %n: %s; View more at %u', (len(results), 'result'), '; '.join(results),
|
||||||
|
friendly_url)
|
||||||
|
irc.reply(s)
|
||||||
|
|
||||||
@wrap(['positiveInt', 'somethingWithoutSpaces', 'somethingWithoutSpaces',
|
@wrap(['positiveInt', 'somethingWithoutSpaces', 'somethingWithoutSpaces',
|
||||||
getopts({'arch': 'somethingWithoutSpaces'})])
|
getopts({'arch': 'somethingWithoutSpaces'})])
|
||||||
@ -481,7 +488,7 @@ class PkgInfo(callbacks.Plugin):
|
|||||||
if query in package.lower():
|
if query in package.lower():
|
||||||
res.append(package)
|
res.append(package)
|
||||||
if res:
|
if res:
|
||||||
irc.reply(format('Available RPMs: %L', res))
|
irc.reply(format('Found %n: %L; View more at: %u', (len(res), 'result'), res, url))
|
||||||
else:
|
else:
|
||||||
irc.error('No results found.')
|
irc.error('No results found.')
|
||||||
|
|
||||||
@ -508,7 +515,7 @@ class PkgInfo(callbacks.Plugin):
|
|||||||
if res:
|
if res:
|
||||||
# Output results in the form "pkg1: description; pkg2: description; ..."
|
# Output results in the form "pkg1: description; pkg2: description; ..."
|
||||||
s = ["%s: %s" % (ircutils.bold(pkg), desc) for pkg, desc in res.items()]
|
s = ["%s: %s" % (ircutils.bold(pkg), desc) for pkg, desc in res.items()]
|
||||||
s = format('Found %i results: %s; View more at %u', len(res), '; '.join(s), url)
|
s = format('Found %n: %s; View more at %u', (len(res), 'result'), '; '.join(s), url)
|
||||||
irc.reply(s)
|
irc.reply(s)
|
||||||
else:
|
else:
|
||||||
irc.error('No results found.')
|
irc.error('No results found.')
|
||||||
|
@ -59,10 +59,10 @@ class PkgInfoTestCase(PluginTestCase):
|
|||||||
'.*?yaourt.*?')
|
'.*?yaourt.*?')
|
||||||
|
|
||||||
def testMintPkg(self):
|
def testMintPkg(self):
|
||||||
self.assertNotError('linuxmint rebecca cinnamon')
|
self.assertRegexp('linuxmint rebecca cinnamon', 'session')
|
||||||
|
|
||||||
def testPkgsearch(self):
|
def testPkgsearch(self):
|
||||||
self.assertNotError('pkgsearch debian python')
|
self.assertRegexp('pkgsearch debian python', 'python')
|
||||||
|
|
||||||
def testFedora(self):
|
def testFedora(self):
|
||||||
self.assertRegexp('fedora 22 bash*', 'bash')
|
self.assertRegexp('fedora 22 bash*', 'bash')
|
||||||
@ -79,7 +79,7 @@ class PkgInfoTestCase(PluginTestCase):
|
|||||||
self.assertNotRegexp('centos 7 extras "a"', 'Parent Directory')
|
self.assertNotRegexp('centos 7 extras "a"', 'Parent Directory')
|
||||||
|
|
||||||
def testFreeBSD(self):
|
def testFreeBSD(self):
|
||||||
self.assertRegexp('freebsd lxterminal --exact', 'Found 1 result.*?LXDE')
|
self.assertRegexp('freebsd lxterminal --exact', 'Found 1 result:.*?LXDE')
|
||||||
self.assertNotError('freebsd bash')
|
self.assertNotError('freebsd bash')
|
||||||
self.assertError('freebsd asdfasjkfalewrghaekglae')
|
self.assertError('freebsd asdfasjkfalewrghaekglae')
|
||||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user