Python pluginbase.PluginBase() Examples
The following are 11
code examples of pluginbase.PluginBase().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pluginbase
, or try the search function
.
Example #1
Source File: manager.py From wafw00f with BSD 3-Clause "New" or "Revised" License | 6 votes |
def load_plugins(): here = os.path.abspath(os.path.dirname(__file__)) get_path = partial(os.path.join, here) plugin_dir = get_path('plugins') plugin_base = PluginBase( package='wafw00f.plugins', searchpath=[plugin_dir] ) plugin_source = plugin_base.make_plugin_source( searchpath=[plugin_dir], persist=True ) plugin_dict = {} for plugin_name in plugin_source.list_plugins(): plugin_dict[plugin_name] = plugin_source.load_plugin(plugin_name) return plugin_dict
Example #2
Source File: setup_pluginbase.py From lavatory with Apache License 2.0 | 6 votes |
def get_policy(plugin_source, repository, default=True): """Gets policy from plugin_source. Args: plugin_source (PluginBase): the plugin source from loading plugin_base. repository (string): Name of repository. default (bool): If to load the default policy. Returns: policy (func): The policy python module. """ policy_name = repository.replace("-", "_") try: policy = plugin_source.load_plugin(policy_name) except ImportError: if default: LOG.info("No policy found for %s. Applying Default", repository) policy = plugin_source.load_plugin('default') else: LOG.info("No policy found for %s. Skipping Default", repository) policy = None return policy
Example #3
Source File: plugins.py From king-phisher with BSD 3-Clause "New" or "Revised" License | 6 votes |
def disable(self, name): """ Disable a plugin by it's name. This call the plugins :py:meth:`.PluginBase.finalize` method to allow it to perform any clean up operations. :param str name: The name of the plugin to disable. """ self._lock.acquire() inst = self.enabled_plugins[name] inst.finalize() inst._cleanup() del self.enabled_plugins[name] self._lock.release() self.logger.info("plugin '{0}' has been disabled".format(name)) # methods to deal with plugin load operations
Example #4
Source File: Global.py From SecRss with GNU General Public License v3.0 | 6 votes |
def load_platform(): """ 载入信息发布平台 :return: """ platform_dir = BASE_PATH + 'platforms' platform_base = PluginBase( package=str('platforms').replace('/', '.'), searchpath=[platform_dir] ) platform_source = platform_base.make_plugin_source( searchpath=[platform_dir], persist=True ) platform_dict = {} for platform_name in platform_source.list_plugins(): __tmp = platform_source.load_plugin(platform_name) if hasattr(__tmp, 'Platform') and hasattr(__tmp, 'Base'): if platform_source.load_plugin(platform_name).Platform([]).info['status']: platform_dict[platform_name] = platform_source.load_plugin(platform_name) return platform_dict
Example #5
Source File: plugin.py From aws_ir with MIT License | 6 votes |
def __init__(self): self.here = os.path.abspath(os.path.dirname(__file__)) self.plugin_base = PluginBase( package='aws_ir.plugins', searchpath=[ os.path.dirname(aws_ir_plugins.__file__), (os.getenv("HOME") + '/.awsir/plugins') ] ) self.source = self.plugin_base.make_plugin_source( searchpath=[ os.path.dirname(aws_ir_plugins.__file__), (os.getenv("HOME") + '/.awsir/plugins') ] ) self.list = self.source.list_plugins()
Example #6
Source File: setup_pluginbase.py From lavatory with Apache License 2.0 | 5 votes |
def setup_pluginbase(extra_policies_path=None): """Sets up plugin base with default path and provided path Args: extra_policies_path (str): Extra path to find plugins in Returns: PluginSource: PluginBase PluginSource for finding plugins """ here = pathlib.Path(__file__).parent.absolute() default_path_obj = here / "../policies" default_path = str(default_path_obj.resolve()) all_paths = [default_path] if extra_policies_path: extra_policies_obj = pathlib.Path(extra_policies_path) if extra_policies_obj.is_dir(): extra_policies = get_directory_path(extra_policies_obj) all_paths.insert(0, str(extra_policies)) else: raise InvalidPoliciesDirectory LOG.info("Searching for policies in %s", str(all_paths)) plugin_base = PluginBase(package='lavatory.policy_plugins') plugin_source = plugin_base.make_plugin_source(searchpath=all_paths) LOG.debug("Policies found: %s", str(plugin_source.list_plugins())) return plugin_source
Example #7
Source File: plugins.py From king-phisher with BSD 3-Clause "New" or "Revised" License | 5 votes |
def enable(self, name): """ Enable a plugin by it's name. This will create a new instance of the plugin modules "Plugin" class, passing it the arguments defined in :py:attr:`.plugin_init_args`. A reference to the plugin instance is kept in :py:attr:`.enabled_plugins`. After the instance is created, the plugins :py:meth:`~.PluginBase.initialize` method is called. :param str name: The name of the plugin to enable. :return: The newly created instance. :rtype: :py:class:`.PluginBase` """ self._lock.acquire() klass = self.loaded_plugins[name] if not klass.is_compatible: self._lock.release() raise errors.KingPhisherPluginError(name, 'the plugin is incompatible') inst = klass(*self.plugin_init_args) try: initialized = inst.initialize() except Exception: self.logger.error("failed to enable plugin '{0}', initialize threw an exception".format(name), exc_info=True) try: inst._cleanup() except Exception: self.logger.error("failed to clean up resources for plugin '{0}'".format(name), exc_info=True) self._lock.release() raise if not initialized: self.logger.warning("failed to enable plugin '{0}', initialize check failed".format(name)) self._lock.release() return self.enabled_plugins[name] = inst self._lock.release() self.logger.info("plugin '{0}' has been enabled".format(name)) return inst
Example #8
Source File: plugins.py From burp-ui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _init_manager(self): if self.init: return self.plugin_base = PluginBase(package='burpui.plugins.ext') self.plugin_source = self.plugin_base.make_plugin_source( searchpath=self.searchpath ) self.init = True
Example #9
Source File: checkers.py From gatorgrader with GNU General Public License v3.0 | 5 votes |
def get_source(checker_paths=[]): """Load all of the checkers using pluginbase.""" # define the "package" in which the checks reside # the term "package" corresponds to "module.sub-module" checker_base = PluginBase(package=constants.packages.Checks) # remove any directories from the path listings that are Nothing (i.e., "") # this case occurs when the optional --checkerdir is not provided on command-line if constants.markers.Nothing in checker_paths: checker_paths.remove(constants.markers.Nothing) # Create the directory where the internal checkers live inside of GatorGrader. # Note that this directory includes the home for GatorGrader, which can be set # by an environment variable and otherwise defaults to the directory from which # GatorGrader was run and then the directory where internal checkers are stored. internal_checker_path = files.create_path( constants.checkers.Internal_Checkers_Dir, home=util.get_gatorgrader_home() ) # create the listing of the paths that could contain checkers, including # all of the provided paths for external checkers and the directory that # contains all of the internal checkers provided by GatorGrader all_checker_paths = checker_paths + [str(internal_checker_path)] # Create and return a source of checkers using PluginBase. # The documentation for this function advices that you # give an identifier to the source for the plugins # because this will support saving and transfer, if needed. # Only perform this operation if the checker source is None, # meaning that it has not already been initialized. # pylint: disable=global-statement global CHECKER_SOURCE if CHECKER_SOURCE is None: CHECKER_SOURCE = checker_base.make_plugin_source( identifier=constants.checkers.Plugin_Base_Identifier, searchpath=all_checker_paths, ) return CHECKER_SOURCE
Example #10
Source File: plugin.py From FACT_core with GNU General Public License v3.0 | 5 votes |
def import_plugins(plugin_mount, plugin_base_dir): plugin_base = PluginBase(package=plugin_mount) plugin_src_dirs = _get_plugin_src_dirs(plugin_base_dir) return plugin_base.make_plugin_source(searchpath=plugin_src_dirs)
Example #11
Source File: plugins.py From king-phisher with BSD 3-Clause "New" or "Revised" License | 4 votes |
def __init__(self, path, args=None, library_path=constants.AUTOMATIC): """ :param tuple path: A tuple of directories from which to load plugins. :param tuple args: Arguments which should be passed to plugins when their class is initialized. :param str library_path: A path to use for plugins library dependencies. This value will be added to :py:attr:`sys.path` if it is not already included. """ self._lock = threading.RLock() self.plugin_init_args = (args or ()) self.plugin_base = pluginbase.PluginBase(package='king_phisher.plugins.loaded') self.plugin_source = self.plugin_base.make_plugin_source(searchpath=path) self.loaded_plugins = {} """A dictionary of the loaded plugins and their respective modules.""" self.enabled_plugins = {} """A dictionary of the enabled plugins and their respective instances.""" self.logger = logging.getLogger('KingPhisher.Plugins.Manager') if library_path is not None: library_path = _resolve_lib_path(library_path) if library_path: if library_path not in sys.path: sys.path.append(library_path) library_path = os.path.abspath(library_path) self.logger.debug('using plugin-specific library path: ' + library_path) else: self.logger.debug('no plugin-specific library path has been specified') self.library_path = library_path """ The path to a directory which is included for additional libraries. This path must be writable by the current user. The default value is platform and Python-version (where X.Y is the major and minor versions of Python) dependant: :Linux: ``~/.local/lib/king-phisher/pythonX.Y/site-packages`` :Windows: ``%LOCALAPPDATA%\\king-phisher\\lib\\pythonX.Y\\site-packages`` """