Ejemplo n.º 1
0
    def create_plugin(self, plugin_spec):
        """ Initialize a plugin, including vetting that it meets the correct
            protocol; not private so it can be used in testing. """
        if plugin_spec.find(':') < 0:
            logging.debug('Plugin spec not validly formed, %s.' % plugin_spec)
            raise PluginError(PLUGIN_ERRORS.invalid_plugin,
                              plugin_spec)  #@UndefinedVariable

        tokens = plugin_spec.split(':')
        module_name = tokens[0]
        plugin_name = tokens[1]

        try:
            __import__(module_name)
        except ImportError:
            logging.warn('Invalid module, %s' % plugin_name)
            raise PluginError(PLUGIN_ERRORS.unknown_plugin,
                              plugin_spec)  #@UndefinedVariable

        try:
            plugin_class = self.__forname(module_name, plugin_name)
            plugin = plugin_class(plugin_spec)
        except Exception, e:
            logging.debug(e)
            logging.debug('Couldn\'t load class %s' % plugin_spec)
            raise PluginError(PLUGIN_ERRORS.unknown_plugin,
                              plugin_spec)  #@UndefinedVariable
Ejemplo n.º 2
0
    def __checkattr(self, plugin_spec, plugin, name, expected_type):
        try:
            attrib = eval('plugin.%s' % name)
        except AttributeError:
            raise PluginError(PLUGIN_ERRORS.missing_attribute, plugin_spec, name) #@UndefinedVariable

        if not isinstance(attrib, expected_type):
            raise PluginError(PLUGIN_ERRORS.invalid_attribute, plugin_spec, name) #@UndefinedVariable
Ejemplo n.º 3
0
    def create_plugin(self, plugin_spec):
        """ Initialize a plugin, including vetting that it meets the correct
            protocol; not private so it can be used in testing. """
        if plugin_spec.find(':') < 0:
            logging.debug(
                'Plugin spec not validly formed, {}.'.format(plugin_spec))
            raise PluginError(PLUGIN_ERRORS.invalid_plugin,
                              plugin_spec)  #@UndefinedVariable

        tokens = plugin_spec.split(':')
        module_name = tokens[0]
        plugin_name = tokens[1]

        try:
            __import__(module_name)
        except ImportError:
            logging.warning('Invalid module, {}'.format(plugin_name))
            raise PluginError(PLUGIN_ERRORS.unknown_plugin,
                              plugin_spec)  #@UndefinedVariable

        try:
            plugin_class = self.__forname(module_name, plugin_name)
            plugin = plugin_class(plugin_spec)
        except Exception as e:
            logging.debug(e)
            logging.debug('Couldn\'t load class {}'.format(plugin_spec))
            raise PluginError(PLUGIN_ERRORS.unknown_plugin,
                              plugin_spec)  #@UndefinedVariable
        is_message_plugin = isinstance(plugin,
                                       flashbake.plugins.AbstractMessagePlugin)
        is_file_plugin = isinstance(plugin,
                                    flashbake.plugins.AbstractFilePlugin)
        is_notify_plugin = isinstance(plugin,
                                      flashbake.plugins.AbstractNotifyPlugin)
        if not is_message_plugin and not is_file_plugin and not is_notify_plugin:
            raise PluginError(PLUGIN_ERRORS.invalid_type,
                              plugin_spec)  #@UndefinedVariable
        if is_message_plugin:
            self.__checkattr(plugin_spec, plugin, 'connectable', bool)
            self.__checkattr(plugin_spec, plugin, 'addcontext', MethodType)
        if is_file_plugin:
            self.__checkattr(plugin_spec, plugin, 'pre_process', MethodType)
        if is_notify_plugin:
            self.__checkattr(plugin_spec, plugin, 'warn', MethodType)

        return plugin
Ejemplo n.º 4
0
    def _get_count_python(self, file, matches):
        count = 0
        for match in matches:
            for f in glob.glob(os.path.normpath(os.path.join(file, match))):
                if f.endswith('.rtfd'):
                    new_f = os.path.join(f, 'TXT.rtf')
                    if os.path.exists(new_f):
                        f = new_f

                if f.endswith('.txt'):
                    count += len(open(f).read().split(None))
                elif f.endswith('.rtf'):
                    words = self.RTF_RE.sub('', open(f).read()).split(None)
                    count += len(words)
                else:
                    raise PluginError(PLUGIN_ERRORS.ignorable_error,
                                      self.plugin_spec,
                                      'Unsupported file type: %s' % f)
        return count
Ejemplo n.º 5
0
 def init(self, config):
     if not flashbake.executable_available('textutil'):
         raise PluginError(
             PLUGIN_ERRORS.ignorable_error, self.plugin_spec,
             'Could not find command, textutil.')  #@UndefinedVariable
Ejemplo n.º 6
0
        try:
            plugin_class = self.__forname(module_name, plugin_name)
            plugin = plugin_class(plugin_spec)
        except Exception, e:
            logging.debug(e)
            logging.debug('Couldn\'t load class %s' % plugin_spec)
            raise PluginError(PLUGIN_ERRORS.unknown_plugin,
                              plugin_spec)  #@UndefinedVariable
        is_message_plugin = isinstance(plugin,
                                       flashbake.plugins.AbstractMessagePlugin)
        is_file_plugin = isinstance(plugin,
                                    flashbake.plugins.AbstractFilePlugin)
        is_notify_plugin = isinstance(plugin,
                                      flashbake.plugins.AbstractNotifyPlugin)
        if not is_message_plugin and not is_file_plugin and not is_notify_plugin:
            raise PluginError(PLUGIN_ERRORS.invalid_type,
                              plugin_spec)  #@UndefinedVariable
        if is_message_plugin:
            self.__checkattr(plugin_spec, plugin, 'connectable', bool)
            self.__checkattr(plugin_spec, plugin, 'addcontext', MethodType)
        if is_file_plugin:
            self.__checkattr(plugin_spec, plugin, 'pre_process', MethodType)
        if is_notify_plugin:
            self.__checkattr(plugin_spec, plugin, 'warn', MethodType)

        return plugin

    def __add_last(self, plugin_name):
        if plugin_name in self.plugin_names:
            self.plugin_names.remove(plugin_name)
        self.plugin_names.append(plugin_name)