mirror of
https://github.com/jlu5/SupyPlugins.git
synced 2025-05-02 16:31:11 -05:00
PkgInfo: remove old distro-specific functions, update tests (#64)
This commit is contained in:
parent
fb5be74e35
commit
7f2110ee24
@ -579,87 +579,6 @@ class PkgInfo(callbacks.Plugin):
|
|||||||
vlist = wrap(vlist, ['somethingWithoutSpaces', 'somethingWithoutSpaces',
|
vlist = wrap(vlist, ['somethingWithoutSpaces', 'somethingWithoutSpaces',
|
||||||
getopts({'reverse': ''})])
|
getopts({'reverse': ''})])
|
||||||
|
|
||||||
def archlinux(self, irc, msg, args, pkg, opts):
|
|
||||||
"""<package> [--exact]
|
|
||||||
|
|
||||||
Looks up <package> in the Arch Linux package repositories.
|
|
||||||
If --exact is given, will output only exact matches.
|
|
||||||
"""
|
|
||||||
pkg = pkg.lower()
|
|
||||||
|
|
||||||
if 'exact' in dict(opts):
|
|
||||||
encoded = urlencode({'name': pkg})
|
|
||||||
else:
|
|
||||||
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)
|
|
||||||
|
|
||||||
fd = utils.web.getUrl(url)
|
|
||||||
data = json.loads(fd.decode("utf-8"))
|
|
||||||
|
|
||||||
if data['valid'] and data['results']:
|
|
||||||
# We want one entry per package, but the API gives one
|
|
||||||
# entry per architecture! Remove duplicates with a set:
|
|
||||||
results = set()
|
|
||||||
|
|
||||||
# For each package, store the available architectures as
|
|
||||||
# a list.
|
|
||||||
archs = defaultdict(list)
|
|
||||||
for pkgdata in data['results']:
|
|
||||||
# Expand the package data dict into arguments for formatting
|
|
||||||
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)
|
|
||||||
archs[s].append(pkgdata['arch'])
|
|
||||||
|
|
||||||
irc.reply(format('Found %n: %L; View more at %u',
|
|
||||||
(len(results), 'result'), sorted(results),
|
|
||||||
friendly_url))
|
|
||||||
else:
|
|
||||||
irc.error("No results found.", Raise=True)
|
|
||||||
archlinux = wrap(archlinux, ['somethingWithoutSpaces', getopts({'exact': ''})])
|
|
||||||
|
|
||||||
def archaur(self, irc, msg, args, pkg):
|
|
||||||
"""<package>
|
|
||||||
|
|
||||||
Looks up <package> in the Arch Linux AUR."""
|
|
||||||
pkg = pkg.lower()
|
|
||||||
baseurl = 'https://aur.archlinux.org/rpc.php?type=search&'
|
|
||||||
url = baseurl + urlencode({'arg': pkg})
|
|
||||||
self.log.debug("PkgInfo: using url %s for 'archaur' command", url)
|
|
||||||
fd = utils.web.getUrl(url)
|
|
||||||
data = json.loads(fd.decode("utf-8"))
|
|
||||||
if data["type"] == "error":
|
|
||||||
irc.error(data["results"], Raise=True)
|
|
||||||
count = data["resultcount"]
|
|
||||||
if count:
|
|
||||||
# We want this to be limited to prevent overflow warnings
|
|
||||||
# in the bot.
|
|
||||||
if count > 150:
|
|
||||||
count = '150+'
|
|
||||||
s = format("Found %n: ", (data["resultcount"], 'result'))
|
|
||||||
for x in data['results'][:150]:
|
|
||||||
verboseInfo = ''
|
|
||||||
if self.registryValue("verbose"):
|
|
||||||
verboseInfo = format("[ID: %s Votes: %s]", x['ID'],
|
|
||||||
x['NumVotes'])
|
|
||||||
s += "{name} - {desc} \x02({version} {verbose})\x02, " \
|
|
||||||
.format(name=x['Name'], desc=x['Description'],
|
|
||||||
version=x['Version'], verbose=verboseInfo)
|
|
||||||
friendly_url = 'https://aur.archlinux.org/packages/?' + \
|
|
||||||
urlencode({'K': pkg})
|
|
||||||
irc.reply(s + format('View more at: %u', friendly_url))
|
|
||||||
else:
|
|
||||||
irc.error("No results found.", Raise=True)
|
|
||||||
archaur = wrap(archaur, ['somethingWithoutSpaces'])
|
|
||||||
|
|
||||||
@wrap(['somethingWithoutSpaces', 'somethingWithoutSpaces'])
|
@wrap(['somethingWithoutSpaces', 'somethingWithoutSpaces'])
|
||||||
def filesearch(self, irc, msg, args, release, query):
|
def filesearch(self, irc, msg, args, release, query):
|
||||||
"""<release> <file query>
|
"""<release> <file query>
|
||||||
@ -703,107 +622,6 @@ class PkgInfo(callbacks.Plugin):
|
|||||||
e = "No results found."
|
e = "No results found."
|
||||||
irc.error(e)
|
irc.error(e)
|
||||||
|
|
||||||
@wrap(['somethingWithoutSpaces',
|
|
||||||
'somethingWithoutSpaces',
|
|
||||||
getopts({'exact': ''})])
|
|
||||||
def linuxmint(self, irc, msg, args, release, query, opts):
|
|
||||||
"""<release> <package> [--exact]
|
|
||||||
|
|
||||||
Looks up <package> in Linux Mint's repositories. If --exact is given,
|
|
||||||
look up packages by the exact package name. Otherwise, look it up
|
|
||||||
as a simple glob pattern."""
|
|
||||||
|
|
||||||
addr = 'http://packages.linuxmint.com/list.php?release=' + \
|
|
||||||
quote(release)
|
|
||||||
|
|
||||||
try:
|
|
||||||
fd = utils.web.getUrl(addr).decode("utf-8")
|
|
||||||
except utils.web.Error as e:
|
|
||||||
irc.error(str(e), Raise=True)
|
|
||||||
|
|
||||||
soup = BeautifulSoup(fd)
|
|
||||||
# Linux Mint puts their package lists in tables
|
|
||||||
results = soup.find_all("td")
|
|
||||||
|
|
||||||
packages = []
|
|
||||||
query = query.lower()
|
|
||||||
exact = 'exact' in dict(opts)
|
|
||||||
|
|
||||||
for result in results:
|
|
||||||
name = result.contents[0].string # Package name
|
|
||||||
|
|
||||||
if query == name or (query in name and not exact):
|
|
||||||
# This feels like really messy code, but we have to find tags
|
|
||||||
# relative to our results.
|
|
||||||
# Ascend to find the section name (in <h2>):
|
|
||||||
section = result.parent.parent.parent.previous_sibling.\
|
|
||||||
previous_sibling.string
|
|
||||||
|
|
||||||
# Find the package version in the next <td>; for some reason we
|
|
||||||
# have to go two siblings further, as the first .next_sibling
|
|
||||||
# returns '\n'. This is mentioned briefly in Beautiful Soup 4's
|
|
||||||
# documentation...
|
|
||||||
version = result.next_sibling.next_sibling.string
|
|
||||||
|
|
||||||
# We format our found dictionary this way because the same
|
|
||||||
# package can exist multiple times in different sections of
|
|
||||||
# the repository (e.g. one in Main, one in Backports, etc.)
|
|
||||||
packages.append('%s \x02(%s)\x02 [\x02%s\x02]' % (name, version, section))
|
|
||||||
|
|
||||||
if packages: # If we have results
|
|
||||||
s = format('Found %n: %L, %s %u', (len(packages), 'result'), packages,
|
|
||||||
_('View more at: '), addr)
|
|
||||||
irc.reply(s)
|
|
||||||
else:
|
|
||||||
irc.error('No results found.')
|
|
||||||
|
|
||||||
|
|
||||||
@wrap([getopts({'release': 'somethingWithoutSpaces'}), additional('somethingWithoutSpaces')])
|
|
||||||
def fedora(self, irc, msg, args, opts, query):
|
|
||||||
"""[--release <release>] [<package name>]
|
|
||||||
|
|
||||||
Looks up <package> in Fedora's repositories. Globs (*, ?) are supported here. <release> is
|
|
||||||
the release version: e.g. 'f25' or 'master' (for rawhide). If no package is given, a list
|
|
||||||
of available releases will be shown."""
|
|
||||||
opts = dict(opts)
|
|
||||||
if query is None:
|
|
||||||
# No package given; show available releases.
|
|
||||||
url = 'https://admin.fedoraproject.org/pkgdb/api/collections?format=json'
|
|
||||||
else:
|
|
||||||
url = 'https://admin.fedoraproject.org/pkgdb/api/packages/%s?format=json' % quote(query)
|
|
||||||
if 'release' in opts:
|
|
||||||
url += '&branches=%s' % quote(opts['release'])
|
|
||||||
|
|
||||||
self.log.debug("PkgInfo: using url %s for 'fedora' command", url)
|
|
||||||
try:
|
|
||||||
fd = utils.web.getUrl(url).decode("utf-8")
|
|
||||||
except utils.web.Error as e:
|
|
||||||
if '404' in str(e):
|
|
||||||
e = 'No results found.'
|
|
||||||
if '*' not in query:
|
|
||||||
e += " Try wrapping your query with *'s: '*%s*'" % query
|
|
||||||
irc.error(e, Raise=True)
|
|
||||||
data = json.loads(fd)
|
|
||||||
|
|
||||||
if query is None:
|
|
||||||
data = data['collections']
|
|
||||||
collections = ['%s (%s %s, %s)' % (ircutils.bold(c['branchname']), c['name'], c['version'], c['status']) for c in data]
|
|
||||||
s = format('Available releases to look up: %L', sorted(collections))
|
|
||||||
else:
|
|
||||||
def formatdesc(s):
|
|
||||||
# Fedora's package descriptions have newlines inserted in them at strange positions,
|
|
||||||
# sometimes even inside sentences. We'll break at the first sentence here:
|
|
||||||
s = s.split('.')[0].strip()
|
|
||||||
s = re.sub('\n+', ' ', s)
|
|
||||||
return s
|
|
||||||
|
|
||||||
results = ['%s: %s' % (ircutils.bold(pkg['name']), formatdesc(pkg['description']))
|
|
||||||
for pkg in data["packages"]]
|
|
||||||
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', additional('somethingWithoutSpaces'), additional('somethingWithoutSpaces'),
|
@wrap(['positiveInt', additional('somethingWithoutSpaces'), additional('somethingWithoutSpaces'),
|
||||||
getopts({'arch': 'somethingWithoutSpaces', 'exact': '', 'startswith': ''})])
|
getopts({'arch': 'somethingWithoutSpaces', 'exact': '', 'startswith': ''})])
|
||||||
def centos(self, irc, msg, args, release, repo, query, opts):
|
def centos(self, irc, msg, args, release, repo, query, opts):
|
||||||
@ -888,34 +706,6 @@ class PkgInfo(callbacks.Plugin):
|
|||||||
else:
|
else:
|
||||||
irc.error('No results found.')
|
irc.error('No results found.')
|
||||||
|
|
||||||
@wrap(['something', getopts({'exact': ''})])
|
|
||||||
def freebsd(self, irc, msg, args, search, optlist):
|
|
||||||
"""<query> [--exact]
|
|
||||||
|
|
||||||
Searches for <query> in FreeBSD's Ports database (case sensitive).
|
|
||||||
If --exact is given, only exact port name matches will be shown."""
|
|
||||||
search
|
|
||||||
url = 'https://www.freebsd.org/cgi/ports.cgi?' + urlencode({'query': search})
|
|
||||||
data = utils.web.getUrl(url)
|
|
||||||
soup = BeautifulSoup(data)
|
|
||||||
res = {}
|
|
||||||
exact = 'exact' in dict(optlist)
|
|
||||||
for dt in soup.find_all('dt'):
|
|
||||||
pkgname = dt.text
|
|
||||||
if exact and pkgname.rsplit('-', 1)[0] != search:
|
|
||||||
continue
|
|
||||||
# In this case, we only want the first line of the description, in order
|
|
||||||
# to keep things short.
|
|
||||||
desc = dt.next_sibling.next_sibling.text.split('\n')[0]
|
|
||||||
res[pkgname] = desc
|
|
||||||
if res:
|
|
||||||
# Output results in the form "pkg1: description; pkg2: description; ..."
|
|
||||||
s = ["%s: %s" % (ircutils.bold(pkg), desc) for pkg, desc in res.items()]
|
|
||||||
s = format('Found %n: %s; View more at %u', (len(res), 'result'), '; '.join(s), url)
|
|
||||||
irc.reply(s)
|
|
||||||
else:
|
|
||||||
irc.error('No results found.')
|
|
||||||
|
|
||||||
Class = PkgInfo
|
Class = PkgInfo
|
||||||
|
|
||||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||||
|
@ -37,59 +37,63 @@ class PkgInfoTestCase(PluginTestCase):
|
|||||||
|
|
||||||
timeout = 12
|
timeout = 12
|
||||||
|
|
||||||
def testPkg(self):
|
def test_pkg_debian(self):
|
||||||
self.assertRegexp('pkg sid bash', 'Package: .*?bash .*?')
|
self.assertNotError('pkg sid bash')
|
||||||
self.assertRegexp('pkg trusty apt', 'Package: .*?apt .*?')
|
|
||||||
self.assertNotError('pkg sid bash --depends')
|
self.assertNotError('pkg sid bash --depends')
|
||||||
|
self.assertNotError('pkg sid ffmpeg --source')
|
||||||
self.assertNotError('pkg sid vlc --source --depends')
|
self.assertNotError('pkg sid vlc --source --depends')
|
||||||
self.assertError('pkg afdsfsadf asfasfasf')
|
self.assertError('pkg unittestinvaliddistignore unittestinvalidpackageignore')
|
||||||
self.assertError('pkg sid afsadfasfsa')
|
self.assertError('pkg sid unittestinvalidpackageignore')
|
||||||
|
self.assertNotError('pkgsearch debian python')
|
||||||
|
|
||||||
def testVlist(self):
|
def test_pkg_ubuntu(self):
|
||||||
self.assertError('vlist all afdsafas')
|
self.assertNotError('pkg xenial apt')
|
||||||
|
self.assertNotError('pkg xenial python3 --depends')
|
||||||
|
self.assertNotError('pkg xenial ubuntu-meta --source')
|
||||||
|
self.assertNotError('pkg xenial ubuntu-meta --source --depends')
|
||||||
|
self.assertNotError('pkgsearch ubuntu gtk')
|
||||||
|
|
||||||
|
def test_vlist(self):
|
||||||
|
self.assertNotError('vlist debian bash')
|
||||||
|
self.assertNotError('vlist ubuntu variety')
|
||||||
|
self.assertError('vlist all unittestinvalidpackageignore')
|
||||||
self.assertError('vlist invalid-distro firefox')
|
self.assertError('vlist invalid-distro firefox')
|
||||||
self.assertRegexp('vlist debian bash', 'Found [1-9][0-9]* '
|
|
||||||
'results: (.*?\(.*?\))+')
|
|
||||||
|
|
||||||
@unittest.skip("Remote server is too unreliable (2017-02-23)")
|
#@unittest.skip("Remote server is too unreliable (2017-02-23)")
|
||||||
def testArchLinux(self):
|
def test_pkg_arch(self):
|
||||||
self.assertError('archlinux afdsfbjeiog')
|
self.assertNotError('pkg arch audacity')
|
||||||
self.assertNotError('archlinux bash')
|
self.assertNotError('pkgsearch arch ffmpeg')
|
||||||
self.assertRegexp('archlinux pacman --exact',
|
self.assertError('pkg arch unittestinvalidpackageignore')
|
||||||
'Found 1.*?pacman')
|
self.assertError('pkgsearch arch unittestinvalidpackageignore')
|
||||||
|
|
||||||
@unittest.skip("Remote server is too unreliable (2017-02-23)")
|
#@unittest.skip("Remote server is too unreliable (2017-02-23)")
|
||||||
def testArchAUR(self):
|
def test_pkg_archaur(self):
|
||||||
self.assertRegexp('archaur yaourt', 'Found [1-9][0-9]* results:'
|
self.assertNotError('pkg archaur yaourt')
|
||||||
'.*?yaourt.*?')
|
self.assertNotError('pkgsearch archaur yaourt')
|
||||||
|
self.assertError('pkg archaur unittestinvalidpackageignore')
|
||||||
|
self.assertError('pkgsearch archaur unittestinvalidpackageignore')
|
||||||
|
|
||||||
def testMintPkg(self):
|
def test_pkg_mint(self):
|
||||||
self.assertRegexp('linuxmint rebecca cinnamon', 'session')
|
self.assertNotError('pkgsearch sonya cinnamon')
|
||||||
|
self.assertNotError('pkg sonya cinnamon')
|
||||||
|
self.assertError('pkg mint unittestinvalidpackageignore')
|
||||||
|
self.assertError('pkgsearch mint unittestinvalidpackageignore')
|
||||||
|
|
||||||
def testPkgsearch(self):
|
def test_pkg_freebsd(self):
|
||||||
self.assertRegexp('pkgsearch debian python', 'python')
|
self.assertNotError('pkg freebsd lxterminal')
|
||||||
|
self.assertNotError('pkgsearch freebsd gnome')
|
||||||
|
self.assertRegexp('pkg freebsd python3 --depends', 'python3.*?requires')
|
||||||
|
self.assertError('pkg freebsd unittestinvalidpackageignore')
|
||||||
|
self.assertError('pkgsearch freebsd unittestinvalidpackageignore')
|
||||||
|
|
||||||
def testFilesearch(self):
|
def test_filesearch(self):
|
||||||
self.assertRegexp('filesearch sid supybot', 'limnoria')
|
self.assertRegexp('filesearch sid supybot', 'limnoria')
|
||||||
|
|
||||||
def testFedora(self):
|
def test_centos(self):
|
||||||
self.assertRegexp('fedora --release master bash*', 'bash')
|
|
||||||
self.assertRegexp('fedora gnome-terminal', 'GNOME')
|
|
||||||
# Not found queries that don't have any wildcards in them
|
|
||||||
# should tell the user to try wrapping the search with *'s, since
|
|
||||||
# Fedora's API always uses glob matches.
|
|
||||||
self.assertRegexp('fedora sfasdfadsfasdfas', 'Try wrapping your query with \*')
|
|
||||||
|
|
||||||
def testCentOS(self):
|
|
||||||
self.assertRegexp('centos 7 os git-', 'git-all')
|
self.assertRegexp('centos 7 os git-', 'git-all')
|
||||||
self.assertRegexp('centos 6 os bash --arch i386', 'i686.rpm')
|
self.assertRegexp('centos 6 os bash --arch i386', 'i686.rpm')
|
||||||
self.assertNotError('centos 7 extras python')
|
self.assertNotError('centos 7 extras python')
|
||||||
# This should be stripped.
|
# This should be stripped.
|
||||||
self.assertNotRegexp('centos 7 extras "a"', 'Parent Directory')
|
self.assertNotRegexp('centos 7 extras "a"', 'Parent Directory')
|
||||||
|
|
||||||
def testFreeBSD(self):
|
|
||||||
self.assertRegexp('freebsd lxterminal --exact', 'Found 1 result:.*?LXDE')
|
|
||||||
self.assertNotError('freebsd bash')
|
|
||||||
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