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

View File

@ -31,7 +31,7 @@ Any specific plugin dependencies *should* also be listed.
- Generates random passwords on the fly! - Generates random passwords on the fly!
##### PkgInfo ##### 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) * ***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 ##### Randomness