PkgInfo: introduce 'mintpkg' properly

- Support multiple package versions (in different sections)
- Add --exact option, with glob searching used by default
- Update README to reflect this
This commit is contained in:
GLolol 2014-10-13 19:24:31 -07:00
parent 080dbc0e79
commit 09fda414d4
3 changed files with 26 additions and 14 deletions

View File

@ -1,5 +1,7 @@
Fetches package information from the repositories of Debian, Arch Linux, and Ubuntu.
Fetches package information from the repositories of Debian, Arch Linux, Linux Mint, and Ubuntu.
This plugin uses the following APIs:
- For Debian and Ubuntu, Debian's [madison.php](//qa.debian.org/madison.php) (for 'vlist')
- For Debian and Ubuntu, Debian's [madison.php](//qa.debian.org/madison.php) (used for 'vlist' command)
- For Arch Linux and its AUR, [AurJson](//wiki.archlinux.org/index.php/AurJson) and the [Arch Linux Repository Web Interface](//wiki.archlinux.org/index.php/Official_Repositories_Web_Interface)
Everything else is parsed as HTML using the Beautiful Soup 4 library.

View File

@ -209,8 +209,8 @@ class PkgInfo(callbacks.Plugin):
irc.reply(s)
pkgsearch = wrap(pkgsearch, ['somethingWithoutSpaces', 'somethingWithoutSpaces'])
def mintpkg(self, irc, msg, args, release, query):
"""<release> <package>
def mintpkg(self, irc, msg, args, release, query, opts):
"""<release> <package> [--exact]
Looks up <package> in Linux Mint's repositories."""
if not bs4Present:
@ -223,15 +223,24 @@ class PkgInfo(callbacks.Plugin):
except Exception as e:
irc.error(str(e), Raise=True)
soup = BeautifulSoup(fd)
# Linux Mint puts their package lists in tables
results = soup.find_all("td")
found = {}
found = OrderedDict()
query = query.lower()
exact = 'exact' in dict(opts)
for result in results:
name = result.contents[0].string
if query == name:
self.log.info(str(result.contents))
version, pkg = result.next_sibling.next_sibling.string, name
found[pkg] = version
self.log.info(str(found))
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
found['%s [\x02%s\x02]' % (name, section)] = version
if found:
s = 'Found %s results: ' % len(found)
for x in found:
@ -240,7 +249,8 @@ class PkgInfo(callbacks.Plugin):
irc.reply(s)
else:
irc.error('No results found.')
mintpkg = wrap(mintpkg, ['somethingWithoutSpaces', 'somethingWithoutSpaces'])
mintpkg = wrap(mintpkg, ['somethingWithoutSpaces', 'somethingWithoutSpaces',
getopts({'exact':''})])
Class = PkgInfo

View File

@ -31,7 +31,7 @@ Any specific plugin dependencies *should* also be listed.
- Generates random passwords on the fly!
##### PkgInfo
- Fetches package information from the websites of Debian, Ubuntu, and Arch Linux's repositories.
- Fetches package information from Debian, Ubuntu, Arch Linux, and Linux Mint's repositories.
* ***Requires:*** [Beautiful Soup 4](http://www.crummy.com/software/BeautifulSoup/bs4/doc/) - install it via `pip install beautifulsoup4` or `apt-get install python-bs4`/`python3-bs4` (Debian/Ubuntu)
##### Randomness