mirror of
https://github.com/jlu5/SupyPlugins.git
synced 2025-05-04 01:10:59 -05:00
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:
parent
080dbc0e79
commit
09fda414d4
@ -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)
|
||||
- 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.
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user