PkgInfo: in pkgsearch, make <distro> optional

This commit is contained in:
James Lu 2015-01-28 01:50:51 -05:00
parent 8f78bb28c0
commit 3e1960a51e
2 changed files with 12 additions and 7 deletions

View File

@ -294,13 +294,17 @@ class PkgInfo(callbacks.Plugin):
irc.error("No results found.", Raise=True) irc.error("No results found.", Raise=True)
archaur = wrap(archaur, ['somethingWithoutSpaces']) archaur = wrap(archaur, ['somethingWithoutSpaces'])
def pkgsearch(self, irc, msg, args, distro, query): def pkgsearch(self, irc, msg, args, opts, query):
"""<distro> <query> """[--distro <distro>] <query>
Looks up <query> in <distro>'s website (for Debian/Ubuntu).""" Looks up <query> in <distro>'s website (for Debian/Ubuntu)."""
distro = distro.lower() opts = dict(opts)
if distro not in ("debian", "ubuntu"): if 'distro' not in opts:
distro = self._getDistro(distro) distro = 'debian'
else:
distro = opts['distro'].lower()
if distro not in ("debian", "ubuntu"):
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:
@ -332,7 +336,7 @@ class PkgInfo(callbacks.Plugin):
except AttributeError: except AttributeError:
e = "No results found." e = "No results found."
irc.error(e) irc.error(e)
pkgsearch = wrap(pkgsearch, ['somethingWithoutSpaces', pkgsearch = wrap(pkgsearch, [getopts({'distro': 'somethingWithoutSpaces'}),
'somethingWithoutSpaces']) 'somethingWithoutSpaces'])
def mintpkg(self, irc, msg, args, release, query, opts): def mintpkg(self, irc, msg, args, release, query, opts):

View File

@ -63,6 +63,7 @@ class PkgInfoTestCase(PluginTestCase):
self.assertNotError('mintpkg qiana cinnamon') self.assertNotError('mintpkg qiana cinnamon')
def testPkgsearch(self): def testPkgsearch(self):
self.assertNotError('pkgsearch debian python') self.assertNotError('pkgsearch --distro ubuntu python')
self.assertNotError('pkgsearch python')
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: