From 09fda414d45b329b2db7d498f21bba24a2f24f73 Mon Sep 17 00:00:00 2001 From: GLolol Date: Mon, 13 Oct 2014 19:24:31 -0700 Subject: [PATCH] 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 --- PkgInfo/README.md | 8 +++++--- PkgInfo/plugin.py | 30 ++++++++++++++++++++---------- README.md | 2 +- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/PkgInfo/README.md b/PkgInfo/README.md index 084fe9c..191c619 100644 --- a/PkgInfo/README.md +++ b/PkgInfo/README.md @@ -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 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) \ No newline at end of file +- 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. diff --git a/PkgInfo/plugin.py b/PkgInfo/plugin.py index 1116d1c..11edd5b 100644 --- a/PkgInfo/plugin.py +++ b/PkgInfo/plugin.py @@ -209,8 +209,8 @@ class PkgInfo(callbacks.Plugin): irc.reply(s) pkgsearch = wrap(pkgsearch, ['somethingWithoutSpaces', 'somethingWithoutSpaces']) - def mintpkg(self, irc, msg, args, release, query): - """ + def mintpkg(self, irc, msg, args, release, query, opts): + """ [--exact] Looks up 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

): + section = result.parent.parent.parent.previous_sibling.\ + previous_sibling.string + # Find the package version in the next ; 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 diff --git a/README.md b/README.md index a02b192..16e11cc 100644 --- a/README.md +++ b/README.md @@ -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