PkgInfo: further tighten dependencies on bs4

This commit is contained in:
James Lu 2014-12-06 11:02:57 -08:00
parent 073c6669cb
commit 792a1a6d89

View File

@ -34,22 +34,19 @@ from supybot.commands import *
import supybot.plugins as plugins import supybot.plugins as plugins
import supybot.ircutils as ircutils import supybot.ircutils as ircutils
import supybot.callbacks as callbacks import supybot.callbacks as callbacks
from collections import OrderedDict, defaultdict from collections import OrderedDict, defaultdict
try: # Python 3 try: # Python 3
from urllib.parse import urlencode, quote from urllib.parse import urlencode, quote
except ImportError: # Python 2 except ImportError: # Python 2
from urllib import urlencode, quote from urllib import urlencode, quote
import json import json
# I don't want to be too dependant on BeautifulSoup at this time;
# not all commands use it, but it is required by some. -GLolol
global bs4Present
try: try:
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
except ImportError: except ImportError:
bs4Present = False raise ImportError("Beautiful Soup 4 is required for this plugin: get it"
else: " at http://www.crummy.com/software/BeautifulSoup/bs4/doc/"
bs4Present = True "#installing-beautiful-soup")
try: try:
from supybot.i18n import PluginInternationalization from supybot.i18n import PluginInternationalization
@ -61,7 +58,7 @@ except ImportError:
class PkgInfo(callbacks.Plugin): class PkgInfo(callbacks.Plugin):
"""Fetches package information from the repositories of """Fetches package information from the repositories of
Debian, Arch Linux, and Ubuntu.""" Debian, Arch Linux, Linux Mint, and Ubuntu."""
threaded = True threaded = True
def __init__(self, irc): def __init__(self, irc):
@ -125,10 +122,6 @@ class PkgInfo(callbacks.Plugin):
Fetches information for <package> from Debian or Ubuntu's repositories. Fetches information for <package> from Debian or Ubuntu's repositories.
<release> is the codename/release name (e.g. 'trusty', 'squeeze'). <release> is the codename/release name (e.g. 'trusty', 'squeeze').
For Arch Linux packages, please use 'archpkg' and 'archaur' instead.""" For Arch Linux packages, please use 'archpkg' and 'archaur' instead."""
if not bs4Present:
irc.error("This command requires the Beautiful Soup 4 library. See"
" https://github.com/GLolol/SupyPlugins/blob/master/README.md"
"#pkginfo for instructions on how to install it.", Raise=True)
pkg = pkg.lower() pkg = pkg.lower()
distro = self._getDistro(release) distro = self._getDistro(release)
try: try:
@ -254,10 +247,6 @@ class PkgInfo(callbacks.Plugin):
"""<distro> <query> """<distro> <query>
Looks up <query> in <distro>'s website (for Debian/Ubuntu).""" Looks up <query> in <distro>'s website (for Debian/Ubuntu)."""
if not bs4Present:
irc.error("This command requires the Beautiful Soup 4 library. See"
" https://github.com/GLolol/SupyPlugins/blob/master/README.md"
"#pkginfo for instructions on how to install it.", Raise=True)
distro = distro.lower() distro = distro.lower()
if distro not in ("debian", "ubuntu"): if distro not in ("debian", "ubuntu"):
distro = self._getDistro(distro) distro = self._getDistro(distro)
@ -296,10 +285,6 @@ class PkgInfo(callbacks.Plugin):
"""<release> <package> [--exact] """<release> <package> [--exact]
Looks up <package> in Linux Mint's repositories.""" Looks up <package> in Linux Mint's repositories."""
if not bs4Present:
irc.error("This command requires the Beautiful Soup 4 library. See"
" https://github.com/GLolol/SupyPlugins/blob/master/README.md"
"#pkginfo for instructions on how to install it.", Raise=True)
addr = 'http://packages.linuxmint.com/list.php?release=' + quote(release) addr = 'http://packages.linuxmint.com/list.php?release=' + quote(release)
try: try:
fd = utils.web.getUrl(addr).decode("utf-8") fd = utils.web.getUrl(addr).decode("utf-8")