Exemple #1
0
def activate_plugin_with_version_check(name, config):
    pta_item = simplePluginManager.getPluginByName(name, 'bots')
    if pta_item is None:
        logging.warning('Could not activate %s')
        return None

    obj = pta_item.plugin_object
    min_version, max_version = obj.min_err_version, obj.max_err_version
    logging.info(
        'Activating %s with min_err_version = %s and max_version = %s' %
        (name, min_version, max_version))
    current_version = version2array(VERSION)
    if min_version and version2array(min_version) > current_version:
        raise IncompatiblePluginException(
            'The plugin %s asks for err with a minimal version of %s and err is %s'
            % (name, min_version, VERSION))

    if max_version and version2array(max_version) < current_version:
        raise IncompatiblePluginException(
            'The plugin %s asks for err with a maximal version of %s and err is %s'
            % (name, min_version, VERSION))

    try:
        if obj.get_configuration_template() is not None and config is not None:
            logging.debug('Checking configuration for %s...' % name)
            obj.check_configuration(config)
            logging.debug('Configuration for %s checked OK.' % name)
        obj.configure(config)  # even if it is None we pass it on
    except Exception, e:
        logging.exception(
            'Something is wrong with the configuration of the plugin %s' %
            name)
        obj.config = None
        raise PluginConfigurationException(str(e))
Exemple #2
0
def activate_plugin_with_version_check(name, config):
    pta_item = simplePluginManager.getPluginByName(name, 'bots')
    if pta_item is None:
        logging.warning('Could not active %s')
        return None

    obj = pta_item.plugin_object
    min_version, max_version = obj.min_err_version, obj.max_err_version
    logging.info('Activating %s with min_err_version = %s and max_version = %s' % (name, min_version, max_version))
    current_version = version2array(VERSION)
    if min_version and version2array(min_version) > current_version:
        raise IncompatiblePluginException('The plugin %s asks for err with a minimal version of %s and err is %s' % (name, min_version, VERSION))

    if max_version and version2array(max_version) < current_version:
        raise IncompatiblePluginException('The plugin %s asks for err with a maximal version of %s and err is %s' % (name, min_version, VERSION))

    try:
        if obj.get_configuration_template() is not None and config is not None:
            logging.debug('Checking configuration for %s...' % name)
            obj.check_configuration(config)
            logging.debug('Configuration for %s checked OK.' % name)
        obj.configure(config) # even if it is None we pass it on
    except Exception, e:
        logging.exception('Something is wrong with the configuration of the plugin %s' % name)
        obj.config = None
        raise PluginConfigurationException(str(e))
Exemple #3
0
def activate_plugin_with_version_check(name, config):
    pta_item = simplePluginManager.getPluginByName(name, 'bots')
    if pta_item is None:
        logging.warning('Could not activate %s' % name)
        return None

    try:
        python_version = pta_item.details.get("Python", "Version")
    except NoSectionError:
        logging.warning('Plugin %s has no section [Python]. Assuming this plugin is runnning only under python 2.' % name)
        python_version = '2'

    if python_version not in ('2', '2+', '3'):
        logging.warning('Plugin %s has an invalid Version specified in section [Python]. The Version can only be 2, 2+ and 3' % name)
        return None

    if python_version == '2' and PY3:
        logging.error('\nPlugin %s is made for python 2 only and you are running err under python 3.\n\n'
                      'If the plugin can be run on python 2 and 3 please add this section to its .plug descriptor :\n[Python]\nVersion=2+\n\n'
                      'Or if the plugin is Python 3 only:\n[Python]\nVersion=3\n\n' % name)
        return None

    if python_version == '3' and PY2:
        logging.error('\nPlugin %s is made for python 3 and you are running err under python 2.')
        return None

    obj = pta_item.plugin_object
    min_version, max_version = obj.min_err_version, obj.max_err_version
    logging.info('Activating %s with min_err_version = %s and max_version = %s' % (name, min_version, max_version))
    current_version = version2array(VERSION)
    if min_version and version2array(min_version) > current_version:
        raise IncompatiblePluginException('The plugin %s asks for err with a minimal version of %s while err is version %s' % (name, min_version, VERSION))

    if max_version and version2array(max_version) < current_version:
        raise IncompatiblePluginException('The plugin %s asks for err with a maximal version of %s while err is version %s' % (name, max_version, VERSION))

    try:
        if obj.get_configuration_template() is not None and config is not None:
            logging.debug('Checking configuration for %s...' % name)
            obj.check_configuration(config)
            logging.debug('Configuration for %s checked OK.' % name)
        obj.configure(config)  # even if it is None we pass it on
    except Exception as e:
        logging.exception('Something is wrong with the configuration of the plugin %s' % name)
        obj.config = None
        raise PluginConfigurationException(str(e))
    add_plugin_templates_path(pta_item.path)
    populate_doc(pta_item)
    try:
        return simplePluginManager.activatePluginByName(name, "bots")
    except Exception as _:
        pta_item.activated = False  # Yapsy doesn't revert this in case of error
        remove_plugin_templates_path(pta_item.path)
        logging.error("Plugin %s failed at activation stage, deactivating it..." % name)
        simplePluginManager.deactivatePluginByName(name, "bots")
        raise
Exemple #4
0
def activate_plugin_with_version_check(name, config):
    pta_item = simplePluginManager.getPluginByName(name, 'bots')
    if pta_item is None:
        logging.warning('Could not activate %s')
        return None

    obj = pta_item.plugin_object
    min_version, max_version = obj.min_err_version, obj.max_err_version
    logging.info(
        'Activating %s with min_err_version = %s and max_version = %s' %
        (name, min_version, max_version))
    current_version = version2array(VERSION)
    if min_version and version2array(min_version) > current_version:
        raise IncompatiblePluginException(
            'The plugin %s asks for err with a minimal version of %s while err is version %s'
            % (name, min_version, VERSION))

    if max_version and version2array(max_version) < current_version:
        raise IncompatiblePluginException(
            'The plugin %s asks for err with a maximal version of %s while err is version %s'
            % (name, max_version, VERSION))

    try:
        if obj.get_configuration_template() is not None and config is not None:
            logging.debug('Checking configuration for %s...' % name)
            obj.check_configuration(config)
            logging.debug('Configuration for %s checked OK.' % name)
        obj.configure(config)  # even if it is None we pass it on
    except Exception as e:
        logging.exception(
            'Something is wrong with the configuration of the plugin %s' %
            name)
        obj.config = None
        raise PluginConfigurationException(str(e))
    add_plugin_templates_path(pta_item.path)
    populate_doc(pta_item)
    try:
        return simplePluginManager.activatePluginByName(name, "bots")
    except Exception as _:
        pta_item.activated = False  # Yapsy doesn't revert this in case of error
        remove_plugin_templates_path(pta_item.path)
        logging.error(
            "Plugin %s failed at activation stage, deactivating it..." % name)
        simplePluginManager.deactivatePluginByName(name, "bots")
        raise
Exemple #5
0
def activate_plugin_with_version_check(name, config):
    pta_item = simplePluginManager.getPluginByName(name, 'bots')
    if pta_item is None:
        logging.warning('Could not active %s')
        return None

    obj = pta_item.plugin_object
    min_version, max_version = obj.min_err_version, obj.max_err_version
    logging.info('Activating %s with min_err_version = %s and max_version = %s' % (name, min_version, max_version))
    current_version = version2array(VERSION)
    if min_version and version2array(min_version) > current_version:
        raise IncompatiblePluginException('The plugin %s asks for err with a minimal version of %s and err is %s' % (name, min_version, VERSION))

    if max_version and version2array(max_version) < current_version:
        raise IncompatiblePluginException('The plugin %s asks for err with a maximal version of %s and err is %s' % (name, min_version, VERSION))

    obj.configure(config) # even if it is None we pass it on

    return simplePluginManager.activatePluginByName(name, "bots")
Exemple #6
0
def activate_plugin_with_version_check(name, config):
    pta_item = simplePluginManager.getPluginByName(name, "bots")
    if pta_item is None:
        logging.warning("Could not activate %s")
        return None

    obj = pta_item.plugin_object
    min_version, max_version = obj.min_err_version, obj.max_err_version
    logging.info("Activating %s with min_err_version = %s and max_version = %s" % (name, min_version, max_version))
    current_version = version2array(VERSION)
    if min_version and version2array(min_version) > current_version:
        raise IncompatiblePluginException(
            "The plugin %s asks for err with a minimal version of %s while err is version %s"
            % (name, min_version, VERSION)
        )

    if max_version and version2array(max_version) < current_version:
        raise IncompatiblePluginException(
            "The plugin %s asks for err with a maximal version of %s while err is version %s"
            % (name, max_version, VERSION)
        )

    try:
        if obj.get_configuration_template() is not None and config is not None:
            logging.debug("Checking configuration for %s..." % name)
            obj.check_configuration(config)
            logging.debug("Configuration for %s checked OK." % name)
        obj.configure(config)  # even if it is None we pass it on
    except Exception as e:
        logging.exception("Something is wrong with the configuration of the plugin %s" % name)
        obj.config = None
        raise PluginConfigurationException(str(e))
    add_plugin_templates_path(pta_item.path)
    populate_doc(pta_item)
    try:
        return simplePluginManager.activatePluginByName(name, "bots")
    except Exception as _:
        pta_item.activated = False  # Yapsy doesn't revert this in case of error
        remove_plugin_templates_path(pta_item.path)
        logging.error("Plugin %s failed at activation stage, deactivating it..." % name)
        simplePluginManager.deactivatePluginByName(name, "bots")
        raise
Exemple #7
0
 def version_check(self):
     if not self.actived:
         logging.debug('Version check disabled')
         return
     logging.debug('Checking version')
     try:
         current_version_txt = urllib2.urlopen(HOME).read().strip()
         current_version = version2array(current_version_txt)
         if installed_version < current_version:
             logging.debug('A new version %s has been found, notify the admins !' % current_version)
             self.warn_admins('Version %s of err is available. http://pypi.python.org/pypi/err/%s. You can disable this check by doing !unload VersionChecker' % (current_version_txt, current_version_txt))
     except Exception as e:
         logging.exception('Could not version check')
Exemple #8
0
 def _async_vcheck(self):
     # noinspection PyBroadException
     try:
         current_version_txt = requests.get(HOME, params={'errbot': VERSION, 'python': PY_VERSION}).text.strip()
         self.log.debug("Tested current Errbot version and it is " + current_version_txt)
         current_version = version2array(current_version_txt)
         if installed_version < current_version:
             self.log.debug('A new version %s has been found, notify the admins !' % current_version)
             self.warn_admins(
                 'Version {0} of Errbot is available. http://pypi.python.org/pypi/errbot/{0}.'
                 ' You can disable this check '
                 'by doing {1}plugin blacklist VersionChecker'.format(current_version_txt, self._bot.prefix)
             )
     except (HTTPError, URLError):
         self.log.info('Could not establish connection to retrieve latest version.')
Exemple #9
0
 def _async_vcheck(self):
     # noinspection PyBroadException
     try:
         current_version_txt = urlopen(url=HOME + '?' + VERSION,
                                       timeout=10).read().decode("utf-8").strip()
         self.log.debug("Tested current Errbot version and it is " + current_version_txt)
         current_version = version2array(current_version_txt)
         if installed_version < current_version:
             self.log.debug('A new version %s has been found, notify the admins !' % current_version)
             self.warn_admins(
                 'Version {0} of Errbot is available. http://pypi.python.org/pypi/errbot/{0}.'
                 ' You can disable this check '
                 'by doing {1}plugin blacklist VersionChecker'.format(current_version_txt, self._bot.prefix)
             )
     except (HTTPError, URLError):
         self.log.info('Could not establish connection to retrieve latest version.')
Exemple #10
0
 def _async_vcheck(self):
     # noinspection PyBroadException
     try:
         current_version_txt = urlopen(url=HOME + '?' + VERSION,
                                       timeout=10).read().decode("utf-8").strip()
         self.log.debug("Tested current Errbot version and it is " + current_version_txt)
         current_version = version2array(current_version_txt)
         if installed_version < current_version:
             self.log.debug('A new version %s has been found, notify the admins !' % current_version)
             self.warn_admins(
                 'Version {0} of err is available. http://pypi.python.org/pypi/errbot/{0}.'
                 ' You can disable this check '
                 'by doing !plugin blacklist VersionChecker'.format(current_version_txt)
             )
     except (HTTPError, URLError):
         self.log.info('Could not establish connection to retrieve latest version.')
Exemple #11
0
 def version_check(self):
     if not self.actived:
         log.debug('Version check disabled')
         return
     log.debug('Checking version')
     # noinspection PyBroadException
     try:
         current_version_txt = urlopen(url=HOME, timeout=10).read().decode("utf-8").strip()
         current_version = version2array(current_version_txt)
         if installed_version < current_version:
             log.debug('A new version %s has been found, notify the admins !' % current_version)
             self.warn_admins(
                 'Version {0} of err is available. http://pypi.python.org/pypi/err/{0}. You can disable this check '
                 'by doing !unload VersionChecker followed by !blacklist VersionChecker'.format(current_version_txt)
             )
     except (HTTPError, URLError):
         log.info('Could not establish connection to retrieve latest version.')
Exemple #12
0
 def version_check(self):
     if not self.actived:
         logging.debug('Version check disabled')
         return
     logging.debug('Checking version')
     # noinspection PyBroadException
     try:
         current_version_txt = urlopen(HOME).read().decode("utf-8").strip()
         current_version = version2array(current_version_txt)
         if installed_version < current_version:
             logging.debug('A new version %s has been found, notify the admins !' % current_version)
             self.warn_admins(
                 'Version {0} of err is available. http://pypi.python.org/pypi/err/{0}. You can disable this check '
                 'by doing !unload VersionChecker followed by !blacklist VersionChecker'.format(current_version_txt)
             )
     except Exception as e:
         logging.exception('Could not version check')
Exemple #13
0
 def version_check(self):
     if not self.actived:
         self.log.debug('Version check disabled')
         return
     self.log.debug('Checking version')
     # noinspection PyBroadException
     try:
         current_version_txt = urlopen(url=HOME, timeout=10).read().decode("utf-8").strip()
         current_version = version2array(current_version_txt)
         if installed_version < current_version:
             self.log.debug('A new version %s has been found, notify the admins !' % current_version)
             self.warn_admins(
                 'Version {0} of err is available. http://pypi.python.org/pypi/err/{0}. You can disable this check '
                 'by doing !unload VersionChecker followed by !blacklist VersionChecker'.format(current_version_txt)
             )
     except (HTTPError, URLError):
         self.log.info('Could not establish connection to retrieve latest version.')
Exemple #14
0
from urllib.error import HTTPError, URLError
import threading
import sys

import requests

from errbot import BotPlugin
from errbot.utils import version2array
from errbot.version import VERSION

HOME = 'http://version.errbot.io/'

installed_version = version2array(VERSION)

PY_VERSION = '.'.join(str(e) for e in sys.version_info[:3])


class VersionChecker(BotPlugin):

    connected = False
    activated = False

    def activate(self):
        if self.mode not in ('null', 'test', 'Dummy', 'text'):  # skip in all test confs.
            self.activated = True
            self.version_check()  # once at startup anyway
            self.start_poller(3600 * 24, self.version_check)  # once every 24H
            super().activate()
        else:
            self.log.info('Skip version checking under %s mode' % self.mode)
Exemple #15
0
# Backward compatibility
from errbot.version import VERSION
from errbot.utils import version2array
if version2array(VERSION) >= [1,6,0]:
    from errbot import botcmd, BotPlugin
else:
    from errbot.botplugin import BotPlugin
    from errbot.jabberbot import botcmd

import urllib
from pyquery import PyQuery as pq

__author__ = 'xnaveira'

class InsultBot(BotPlugin):

    @botcmd
    def insult(self, mess, args):
        """ Insults someone for you
        Example: !insult my_enemy_name
        """
        if not args:
            return 'Am I supposed to insult myself?...'
        args = args.strip()
        d = pq(url='http://www.randominsults.net/')
        p = d("i")
        return str(args) + ', ' + p.html()

Exemple #16
0
# Backward compatibility
from errbot.version import VERSION
from errbot.utils import version2array
if version2array(VERSION) >= [1, 6, 0]:
    from errbot import botcmd, BotPlugin
else:
    from errbot.botplugin import BotPlugin
    from errbot.jabberbot import botcmd

from BeautifulSoup import BeautifulSoup
import urllib
import re


class Music(BotPlugin):
    @botcmd
    def lyrics(self, mess, args):
        """Fetches lyrics from the given artist and song.
        !lyrics Rick Astley : Never Gonna Give You Up"""
        try:
            artist, title = args.split(':')
        except ValueError:
            return 'usage: !lyrics artist : title'

        artist = artist.strip().replace(' ', '_').title()
        title = title.strip().replace(' ', '_').title()

        artist = urllib.quote(artist)
        title = urllib.quote(title)

        lyrics = urllib.urlopen('http://lyricwiki.org/%s:%s' % (artist, title))
Exemple #17
0
def activate_plugin_with_version_check(name, config):
    pta_item = simplePluginManager.getPluginByName(name, 'bots')
    if pta_item is None:
        logging.warning('Could not activate %s' % name)
        return None

    try:
        python_version = pta_item.details.get("Python", "Version")
    except NoSectionError:
        logging.warning(
            'Plugin %s has no section [Python]. Assuming this plugin is runnning only under python 2.'
            % name)
        python_version = '2'

    if python_version not in ('2', '2+', '3'):
        logging.warning(
            'Plugin %s has an invalid Version specified in section [Python]. The Version can only be 2, 2+ and 3'
            % name)
        return None

    if python_version == '2' and PY3:
        logging.error(
            '\nPlugin %s is made for python 2 only and you are running err under python 3.\n\n'
            'If the plugin can be run on python 2 and 3 please add this section to its .plug descriptor :\n[Python]\nVersion=2+\n\n'
            'Or if the plugin is Python 3 only:\n[Python]\nVersion=3\n\n' %
            name)
        return None

    if python_version == '3' and PY2:
        logging.error(
            '\nPlugin %s is made for python 3 and you are running err under python 2.'
        )
        return None

    obj = pta_item.plugin_object
    min_version, max_version = obj.min_err_version, obj.max_err_version
    logging.info(
        'Activating %s with min_err_version = %s and max_version = %s' %
        (name, min_version, max_version))
    current_version = version2array(VERSION)
    if min_version and version2array(min_version) > current_version:
        raise IncompatiblePluginException(
            'The plugin %s asks for err with a minimal version of %s while err is version %s'
            % (name, min_version, VERSION))

    if max_version and version2array(max_version) < current_version:
        raise IncompatiblePluginException(
            'The plugin %s asks for err with a maximal version of %s while err is version %s'
            % (name, max_version, VERSION))

    try:
        if obj.get_configuration_template() is not None and config is not None:
            logging.debug('Checking configuration for %s...' % name)
            obj.check_configuration(config)
            logging.debug('Configuration for %s checked OK.' % name)
        obj.configure(config)  # even if it is None we pass it on
    except Exception as e:
        logging.exception(
            'Something is wrong with the configuration of the plugin %s' %
            name)
        obj.config = None
        raise PluginConfigurationException(str(e))
    add_plugin_templates_path(pta_item.path)
    populate_doc(pta_item)
    try:
        return simplePluginManager.activatePluginByName(name, "bots")
    except Exception as _:
        pta_item.activated = False  # Yapsy doesn't revert this in case of error
        remove_plugin_templates_path(pta_item.path)
        logging.error(
            "Plugin %s failed at activation stage, deactivating it..." % name)
        simplePluginManager.deactivatePluginByName(name, "bots")
        raise