def _load(self): """lazy load""" self._cache_clean = True self._cache_plugins = {} self._cache_plugins_disabled = {} self._backend.collect_plugins() for plugin in self._backend.get_plugins(): is_valid = self._plugin_validate(plugin) if is_valid is True: self._load_plugin_handle_alias(plugin) else: if is_valid is not False: self._cache_plugins_disabled[plugin.get_name()] = is_valid # ignore "disabled" plugin if plugin with same name is "enabled" # e.g. screen off has different implementations for Linux and Mac # => don't show "screen off" as "disabled" because it isn't enabled_names = [] for plugin in self._cache_plugins.values(): plugin_name = plugin.get_name() if plugin.complete() is None: enabled_names.append(plugin_name) else: for complete in plugin.complete(): enabled_names.append("{} {}".format(plugin_name, complete)) cache_disabled_copy = self._cache_plugins_disabled self._cache_plugins_disabled = {} for name, message in cache_disabled_copy.items(): if name not in enabled_names: self._cache_plugins_disabled[name] = message
def _plugin_validate(self, plugin): # I really don't know why that check is necessary... if not isinstance(plugin, pluginmanager.IPlugin): return False if plugin.get_name() == "plugin": return False # has doc, run, alias, require and complete? if not self._plugin_has_method(plugin, "run", 2): print( "Warning! Plugin \"{}\" has no method \"run\"! Will be disabled!" .format(plugin.get_name())) return False if not self._plugin_has_method(plugin, "alias", 0): print("Warning! Plugin \"{}\" has no method \"alias\"!".format( plugin.get_name())) plugin.alias = lambda: None if not self._plugin_has_method(plugin, "require", 0): print("Warning! Plugin \"{}\" has no method \"require\"!".format( plugin.get_name())) plugin.require = lambda: None if not self._plugin_has_method(plugin, "complete", 0): print("Warning! Plugin \"{}\" has no method \"complete\"!".format( plugin.get_name())) plugin.complete = lambda: None # dependency check if not self._plugin_dependency.check(plugin): return False return True
def _load_plugin_handle_alias(self, plugin): self._load_add_plugin(plugin.get_name(), plugin) alias = plugin.alias() if alias is not None: for name in alias: self._load_add_plugin(name.lower(), plugin)
def _check_native(self, values, plugin): missing = "" for native in values: if not executable_exists(native): missing += native missing += " " if len(missing) == 0: return True else: warning("Disabeling {} - missing native executables {}".format(plugin.get_name(), missing))
def _check_native(self, values, plugin): missing = "" for native in values: if distutils.spawn.find_executable(native) is None: missing += native missing += " " if len(missing) == 0: return True else: warning("Disabeling {} - missing native executables {}".format( plugin.get_name(), missing))
def _plugin_has_method(self, plugin, method, param_len): if not hasattr(plugin.__class__, method) or not callable(getattr(plugin.__class__, method)): return False params = signature(getattr(plugin, method)).parameters params = [param for param in params if param != 'args'] if param_len != len(params): print("Warning! Wrong parameter number: \"{}\" of \"{}\" ({}, epxected: {})". format(method, plugin.get_name(), len(params), param_len)) return False return True
def _load(self): """lazy load""" self._cache_clean = True self._cache_plugins = {} self._backend.collect_plugins() for plugin in self._backend.get_plugins(): # I really don't know why that check is necessary... if not isinstance(plugin, pluginmanager.IPlugin): continue if plugin.get_name() != "plugin" and self._plugin_dependency.check( plugin): self._load_plugin_handle_alias(plugin)