예제 #1
0
def reload_plugins():
    global __db_sources, __loaded_plugins, source, builtins_source
    __db_sources = []
    __loaded_plugins = {}

    base = PluginBase(package='metgem_app.plugins')
    if source is not None:
        source = None
    source = base.make_plugin_source(searchpath=[PLUGINS_PATH],
                                     identifier="MetGem")
    if builtins_source is None:
        builtins_source = base.make_plugin_source(searchpath=[os.path.join(APP_PATH,
                                                                           'metgem_app',
                                                                           'plugins')],
                                                  identifier="MetGem_builtins")

    for plugin_name in builtins_source.list_plugins():
        plugin = load_plugin(builtins_source, plugin_name)
        if plugin is not None:
            __loaded_plugins[plugin_name] = plugin

    for plugin_name in source.list_plugins():
        plugin = load_plugin(source, plugin_name)
        if plugin_name in __loaded_plugins:
            if plugin.__version__ >= __loaded_plugins[plugin_name].__version__:
                __loaded_plugins[plugin_name] = plugin

    for plugin in __loaded_plugins.values():
        for name, obj in inspect.getmembers(plugin, inspect.isclass):
            if issubclass(obj, DbSource):
                register_db_source(obj())
예제 #2
0
def run_plugins(configuration, section, output, test_id, func):
    result = []
    plugin_list = configuration[section]["enabled_plugins"].split()
    plugin_base = PluginBase(package='plugins')
    plugin_source = plugin_base.make_plugin_source(searchpath=['./plugins'])

    for plugin_name in plugin_list:
        logging.debug(f"Executing {func} of plugin {plugin_name}.")
        plugin = plugin_source.load_plugin(plugin_name)
        try:
            function_to_call = getattr(plugin, func, None)
            if function_to_call != None:
                plugin_state = ", ".join(global_plugin_state.keys())
                logging.debug(
                    f"Current plugin state contains [{plugin_state}]")

                call_result = function_to_call(global_plugin_state,
                                               configuration[section], output,
                                               test_id)
                result.append(call_result)

        except Exception as e:
            logging.critical(f"Cannot invoke plugin {plugin_name}: {e}")

    return result
예제 #3
0
 def __init__(self):
     if Hoster.plugin_source is not None:
         return
     plugin_base = PluginBase(package='hoster.plugins')
     Hoster.plugin_source = plugin_base.make_plugin_source(
         searchpath=['./hoster'])
     with Hoster.plugin_source:
         for p in Hoster.plugin_source.list_plugins():
             h = Hoster.plugin_source.load_plugin(p)
             if not hasattr(h, p):
                 log.debug("Plugin " + p + " is invalid (No class named " + p + "in module)")
                 continue
             if not Config.get("hoster/" + p + "/active", True):
                 continue
             h = getattr(h, p)
             if not configured(h):
                 log.error("Plugin " + h.__name__ + " is activated but not configured. Deactivating.")
                 continue
             h = h()
             h.plugin_name = p
             if not isinstance(h, BasePlugin):
                 log.error("Plugin " + p + " is invalid (Not extending BasePlugin)")
                 continue
             log.debug("Loaded plugin " + p)
             Hoster.hoster.append(h)
             for n in h.config_values:
                 if not Config.get("hoster/" + p + "/" + n):
                     print "Hoster", p, \
                         "needs a", n + ". You need to add a", n, "for", p, "to config.json " \
                                                                            "to use the plugin."
예제 #4
0
def run(cu_xml: str, dep_file: str, loop_counter_file: str, reduction_file: str, plugins: List[str]) \
        -> DetectionResult:
    cu_dict, dependencies, loop_data, reduction_vars = parse_inputs(
        cu_xml, dep_file, loop_counter_file, reduction_file)

    pet = PETGraphX(cu_dict, dependencies, loop_data, reduction_vars)
    # TODO add visualization
    # pet.show()

    plugin_base = PluginBase(package='plugins')

    plugin_source = plugin_base.make_plugin_source(
        searchpath=[Path(__file__).parent / 'plugins'])

    for plugin_name in plugins:
        p = plugin_source.load_plugin(plugin_name)
        print("executing plugin before: " + plugin_name)
        pet = p.run_before(pet)

    pattern_detector = PatternDetectorX(pet)

    res: DetectionResult = pattern_detector.detect_patterns()

    for plugin_name in plugins:
        p = plugin_source.load_plugin(plugin_name)
        print("executing plugin after: " + plugin_name)
        pet = p.run_after(pet)

    return res
예제 #5
0
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
예제 #6
0
    def __init__(self,
                 filter_file: str = "filters.py",
                 mapping_path: str = "mapping.json",
                 feed_source: str = None):
        self.feed_source: str = feed_source
        self.filters_file: str = os.path.abspath(filter_file)
        self.mapping_path: str = os.path.abspath(mapping_path)
        self.mapping_json: dict = self._load_json(self.mapping_path)
        self._plugin = None
        self._filter_module = os.path.splitext(
            os.path.basename(self.filters_file)
        )[0]

        #
        # Load filter file as a Python plugin
        #
        if self.filters_file:
            #
            # Load dynamically the source code
            #
            plugin_base = PluginBase(package='feed_to_exporter.plugins')
            self._plugin = plugin_base.make_plugin_source(
                searchpath=[
                    os.path.dirname(self.filters_file)])

        self._target_url_fixed = None
        self._token: dict = None
        self._mapping_obj: SimpleNamespace = None
        self._wordpress_api: str = None
예제 #7
0
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
예제 #8
0
def run(cu_xml: str,
        dep_file: str,
        loop_counter_file: str,
        reduction_file: str,
        plugins: List[str],
        file_mapping: Optional[str] = None,
        cu_inst_result_file: Optional[str] = None,
        llvm_cxxfilt_path: Optional[str] = None) -> DetectionResult:
    pet = PETGraphX.from_parsed_input(
        *parse_inputs(cu_xml, dep_file, loop_counter_file, reduction_file))
    # TODO add visualization
    # pet.show()

    plugin_base = PluginBase(package='plugins')

    plugin_source = plugin_base.make_plugin_source(
        searchpath=[Path(__file__).parent / 'plugins'])

    for plugin_name in plugins:
        p = plugin_source.load_plugin(plugin_name)
        print("executing plugin before: " + plugin_name)
        pet = p.run_before(pet)

    pattern_detector = PatternDetectorX(pet)

    res: DetectionResult = pattern_detector.detect_patterns(
        cu_xml, dep_file, loop_counter_file, reduction_file, file_mapping,
        cu_inst_result_file, llvm_cxxfilt_path)

    for plugin_name in plugins:
        p = plugin_source.load_plugin(plugin_name)
        print("executing plugin after: " + plugin_name)
        pet = p.run_after(pet)

    return res
예제 #9
0
    def GetConfig(self):
        services = self.GetServices()
        config = ""
        # Use PluginBase to find the plugins
        here = os.path.abspath(os.path.dirname(__file__))
        get_path = partial(os.path.join, here)
        plugin_base = PluginBase(package='plugins')
        plugin_source = plugin_base.make_plugin_source(
            searchpath=[get_path('plugins')])

        # Call each plugin and pass in the list of services
        for plugin_name in plugin_source.list_plugins():
            plugin = plugin_source.load_plugin(plugin_name)
            # Add each plugin output to the config string we're building
            section = plugin.invoke(services)
            if (section is not None):
                config = (config + str(section))

        defaultSection = self.GenerateDefaultInputConfig(config)
        if (defaultSection is not None):
            print(
                "No data sources configured or detected. Enabling default: device temperature."
            )
            config = (config + str(defaultSection))

        return config
예제 #10
0
class Manager(object):
    """Manager class for BotManager
    """
    def __init__(self, config):
        self.config = config

    def load_plugins(self):

        self.plugins = {}

        # Setup a plugin base for "example.modules" and make sure to load
        # all the default built-in plugins from the builtin_plugins folder.
        self.plugin_base = PluginBase(package='test.plugins')

        # and a source which loads the plugins from the "app_name/plugins"
        # folder.  We also pass the application name as identifier.  This
        # is optional but by doing this out plugins have consistent
        # internal module names which allows pickle to work.
        self.source = self.plugin_base.make_plugin_source(
            searchpath=[get_path('./plugins')])

        # Here we list all the plugins the source knows about, load them
        # and the use the "setup" function provided by the plugin to
        # initialize the plugin.
        for plugin_name in self.source.list_plugins():
            plugin = self.source.load_plugin(plugin_name)
            #self.plugins.add (plugin.get_instance())
            obj = plugin.get_instance(self.config)
            commands = obj.process_command('')

    def hola(self):
        print('Filename: ', self.config_name)
예제 #11
0
    def __init__(self, loop: AbstractEventLoop):
        # init event loop and dispatcher
        self._loop = loop
        self._ch = Channel(self._loop)
        logging.basicConfig(
            format=
            '%(asctime)s [%(levelname)s] (%(pathname)s:%(lineno)d): %(message)s',
            datefmt='%Y-%m-%d %H:%M:%S')
        self._loger = logging.getLogger()
        self._loger.setLevel("DEBUG")

        # load plugins
        plugin_base = PluginBase("my_plugin")
        self._plugin_source = plugin_base.make_plugin_source(
            searchpath=["./plugins"])
        self._plugins = dict()
        for name in self._plugin_source.list_plugins():
            self._loger.debug("loading: " + name)
            plugin = self._plugin_source.load_plugin(name)
            if hasattr(plugin, "setup"):
                self._plugins[name] = plugin.setup(self._loop, self._ch,
                                                   self._loger)

        # after setup
        self._loop.run_until_complete(self.on_setup_done())
예제 #12
0
    def _initialize_plugin_source(self):
        plugin_base = PluginBase(package='cis.plugins.validation')
        plugin_source = plugin_base.make_plugin_source(searchpath=[
            os.path.join(os.path.abspath(os.path.dirname(__file__)),
                         '../plugins/validation/')
        ])

        return plugin_source
예제 #13
0
class PluginManager(object):
    """The :class:`burpui.plugins.PluginManager` class is a plugin manager.

    :param app: Instance of the app we are running in
    :type app: :class:`burpui.server.BUIServer`

    :param searchpath: The places to look for plugins
    :type searchpath: list
    """
    def __init__(self, app, searchpath):
        self.app = app
        self.searchpath = searchpath
        self.init = False
        self.plugins = {}

    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)

    def load_all(self):
        self._init_manager()
        for plugin_name in self.plugin_source.list_plugins():
            if plugin_name not in self.plugins:
                try:
                    plugin = self.plugin_source.load_plugin(plugin_name)
                    current_type = getattr(plugin, '__type__', None)
                    if not current_type:
                        self.app.logger.warning(
                            'No __type__ for {}. Ignoring it'.format(
                                repr(plugin_name)))
                        continue
                    self.app.logger.info('Loading plugin {} ({})'.format(
                        repr(plugin_name), current_type))
                    self.plugins[plugin_name] = plugin
                except Exception as exp:
                    self.app.logger.error(
                        'Unable to load plugin {}: {}'.format(
                            repr(plugin_name), str(exp)))

    def get_plugins_by_type(self, plugin_type):
        ret = {}
        for name, plugin in iteritems(self.plugins):
            current_type = getattr(plugin, '__type__', None)
            if not current_type:
                self.app.logger.warning(
                    'No __type__ for {}. Ignoring it'.format(repr(name)))
                continue
            if current_type == plugin_type:
                ret[name] = plugin

        return ret

    def get_plugin_by_name(self, name):
        return self.plugins.get(name, None)
예제 #14
0
def get_plugin_source():
    """Creates and returns a 'plugin_source' object as defined by PluginBase,
       which provides access plugins.
    """
    here = os.path.abspath(os.path.dirname(__file__))
    get_path = partial(os.path.join, here)
    plugin_base = PluginBase(package='plugins')
    plugin_source = plugin_base.make_plugin_source(searchpath=[get_path('plugins')])

    return plugin_source
예제 #15
0
    def _load_notifier(self, name, params={}):

        plugin_base = PluginBase(package="check_certs.plugins")
        plugin_source = plugin_base.make_plugin_source(
            searchpath=[os.path.join(os.path.dirname(__file__), "./plugins")])
        # keep a reference to the plugin
        self.plugin_source.add(plugin_source)
        plugin = plugin_source.load_plugin(name + "_notifier")

        plugin.setup(self, params)
예제 #16
0
def load_plugins():
    """Load plugins."""
    plugin_base = PluginBase(package="dontforget.plugins")
    plugin_source = plugin_base.make_plugin_source(
        identifier=DEFAULT_PIPES_DIR_NAME,
        searchpath=[str(Path(__file__).parent / DEFAULT_PIPES_DIR_NAME)],
        persist=True,
    )
    for plugin_module in plugin_source.list_plugins():
        plugin_source.load_plugin(plugin_module)
예제 #17
0
def import_plugins(plugin_mount, plugin_base_dir):
    '''
    Imports all plugins in plugin_base_dir with packagename plugin_mount

    :param plugin_mount: The packagename that the plugins will reside in
    :param plugin_base_dir: The directory that contains the plugins
    :return: A pluginbase.PluginSource containing all plugins from 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)
예제 #18
0
def load_plugins():
    current_dir = os.path.abspath(
        os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
    plugin_dir = os.path.join(current_dir, 'plugin')
    plugin_base = PluginBase(package='plugin', 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
예제 #19
0
    def __init__(self, resource, provider):
        path = pathlib.Path(__file__).parent.resolve()
        path = path / resource

        all_paths = [str(path)]

        self.paths = all_paths
        self.provider = provider

        plugin_base = PluginBase(package='foremast.plugins')
        self.plugin_source = plugin_base.make_plugin_source(
            searchpath=self.paths, persist=True)
예제 #20
0
def main():
    plugin_base = PluginBase(package='plugins')
    plugin_source = plugin_base.make_plugin_source(searchpath=['plugins'])
    for plugin in plugin_source.list_plugins():
        p = plugin_source.load_plugin(plugin)
        p.do_something()
        for k, v in p.__dict__.items():
            if not inspect.isclass(v):
                continue
            print(type(v))
            if issubclass(v.__class__, BaseClass.__class__):
                print(k)
예제 #21
0
def load_authentication_plugin(server_folder, plugin_name):
    try:
        from pluginbase import PluginBase
        plugin_base = PluginBase(package="plugins/authenticator")
        plugins_dir = os.path.join(server_folder, "plugins", "authenticator")
        plugin_source = plugin_base.make_plugin_source(
            searchpath=[plugins_dir])
        auth = plugin_source.load_plugin(plugin_name).get_class()
        return auth
    except:
        print("Error loading authenticator plugin '%s'" % plugin_name)
        raise
예제 #22
0
def loadplugins(pluginbasepath, verbose=False, silent=False):
    plugin_base = PluginBase(package='gtool.plugins')
    plugin_source = plugin_base.make_plugin_source(searchpath=__enumerateplugins(pluginbasepath), identifier='gtool', persist=True)

    _plugins = plugin_source.list_plugins()
    for plugin_name in _plugins:  #plugin_source.list_plugins():
        if verbose:
            print('[VERBOSE] loading plug-in:', plugin_name)
        _plugin = plugin_source.load_plugin(plugin_name)
        registerPlugin(plugin_name.upper(), _plugin.load())
    if not verbose and not silent:
            print('Loaded %s plugins (use verbose mode to list them)' % len(_plugins))
예제 #23
0
class Core(object):
    """Enumerates core plugins that are part of the AWS_IR offering."""
    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()

    def key_plugins(self):
        """Return list of only the plugins that relate to the access key."""
        plugins = ""
        for p in self.list:
            if "_key" in p:
                if plugins == "":
                    plugins = p
                else:
                    plugins = plugins + ',' + p
        return plugins

    def instance_plugins(self):
        """Return list of only the plugins that relate to the instance compromise."""
        plugins = ""
        for p in self.list:
            if "_host" in p:
                if plugins == "":
                    plugins = p
                else:
                    plugins = plugins + ',' + p
        plugins = plugins + ',' + 'get_memory'
        return plugins

    def lambda_plugins(self):
        """Return list of only the plugins that relate to the lambda compromise."""
        plugins = ""
        for p in self.list:
            if "_lambda" in p:
                if plugins == "":
                    plugins = p
                else:
                    plugins = plugins + ',' + p
        return plugins
예제 #24
0
파일: mole.py 프로젝트: 5l1v3r1/mole-1
def load_plugins(servers, payloads):
    plugin_base = PluginBase(package='mole.plugins')
    plugin_source = plugin_base.make_plugin_source(searchpath=get_plugin_dirs(
        path='payloads'))

    log.debug('Plugin dirs: ' + ", ".join(get_plugin_dirs()))
    for p in plugin_source.list_plugins():
        log.debug('Loading plugin: ' + p)
        plugin = plugin_source.load_plugin(p)
        bp = plugin.setup(servers, payloads)
        if bp:
            app.register_blueprint(bp)

    return servers, payloads
예제 #25
0
    def __init__(self, resource, search_path=None):
        all_paths = []
        path = pathlib.Path(__file__).parent.resolve()
        path = path / resource
        all_paths.append(str(path))

        if search_path:
            all_paths.extend(search_path)

        self.paths = all_paths

        plugin_base = PluginBase(package='python_template_flask.plugins')
        self.plugin_source = plugin_base.make_plugin_source(
            searchpath=self.paths, persist=True)
예제 #26
0
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='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
예제 #27
0
def load_plugins():
    """Load plugins."""
    plugin_base = PluginBase(package="dontforget.plugins")
    try:
        plugin_source = plugin_base.make_plugin_source(
            identifier=DEFAULT_PIPES_DIR_NAME,
            searchpath=[str(Path(__file__).parent / DEFAULT_PIPES_DIR_NAME)],
            persist=True,
        )
    except RuntimeError:
        # Ignore RuntimeError: This plugin source already exists
        return
    for plugin_module in plugin_source.list_plugins():
        plugin_source.load_plugin(plugin_module)
예제 #28
0
def load_authentication_plugin(server_folder, plugin_name):
    try:
        from pluginbase import PluginBase
        plugin_base = PluginBase(package="plugins/authenticator")
        plugins_dir = os.path.join(server_folder, "plugins", "authenticator")
        plugin_source = plugin_base.make_plugin_source(
                        searchpath=[plugins_dir])
        auth = plugin_source.load_plugin(plugin_name).get_class()
        # it is necessary to keep a reference to the plugin, otherwise it is removed
        # and some imports fail
        auth.plugin_source = plugin_source
        return auth
    except:
        print("Error loading authenticator plugin '%s'" % plugin_name)
        raise
예제 #29
0
def load_authentication_plugin(server_folder, plugin_name):
    try:
        from pluginbase import PluginBase
        plugin_base = PluginBase(package="plugins/authenticator")
        plugins_dir = os.path.join(server_folder, "plugins", "authenticator")
        plugin_source = plugin_base.make_plugin_source(
            searchpath=[plugins_dir])
        auth = plugin_source.load_plugin(plugin_name).get_class()
        # it is necessary to keep a reference to the plugin, otherwise it is removed
        # and some imports fail
        auth.plugin_source = plugin_source
        return auth
    except:
        print("Error loading authenticator plugin '%s'" % plugin_name)
        raise
예제 #30
0
    def load_plugins(self):
        session = db.Session()
        deactivate_all_plugins(session)
        session.commit()

        default_paths = self.get_all_plugin_paths()

        # Load plugins from directories
        plugin_base = PluginBase(package="deeptracy.plugins")
        plugin_manager = plugin_base.make_plugin_source(
            searchpath=default_paths)

        # Locate plugins
        plugins_found = {}

        for module in plugin_manager.list_plugins():

            if module == 'store':
                continue

            module_objects = plugin_manager.load_plugin(module)

            for plugin_name, plugin_obj in vars(module_objects).items():
                if plugin_name.startswith(
                        "_") or type(plugin_obj).__name__ != "function":
                    continue

                if hasattr(plugin_obj, "deeptracy_plugin_enable") and hasattr(
                        plugin_obj, "deeptracy_plugin_lang"):
                    for lang in plugin_obj.deeptracy_plugin_lang:
                        plugin = add_or_activate_plugin(
                            plugin_name, lang, session)
                        session.commit()
                        plugins_found[plugin.id] = {
                            'module': module,
                            'func_name': plugin_name
                        }

                    session.commit()

        session.close()

        log.info('[Plugins]')
        log.info(plugins_found)

        self._plugins = plugins_found
        self._manager = plugin_manager
예제 #31
0
파일: manager.py 프로젝트: BMaChina/wafw00f
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
예제 #32
0
def load_plugins(conf):
    plugin_path = [pkg_resources.resource_filename('wtf', 'plugins')]
    try:
        plugin_path += conf['common']['plugin_path']
    except (KeyError, TypeError):
        pass

    plugin_base = PluginBase('wtf.plugins')
    plugin_source = plugin_base.make_plugin_source(searchpath=plugin_path)

    plugins = []
    for plugin_name in plugin_source.list_plugins():
        plugin_module = plugin_source.load_plugin(plugin_name)
        _classes = inspect.getmembers(plugin_module, inspect.isclass)
        plugins += [_class for name, _class in _classes if issubclass(_class, Plugin) and not _class == Plugin]

    return plugins
예제 #33
0
    def load_plugins(self):
        try:
            here = os.path.abspath(os.path.dirname(__file__))
            get_path = partial(os.path.join, here)
            plugin_dir = get_path('cms')

            plugin_base = PluginBase(package='waf_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)
            self.plugin_dict = plugin_dict
        except Exception as e:
            logging.error('Load waf plugins failed ' + str(e))
        return None
예제 #34
0
def load_external_modules(module_path, base_type=object):

    if not module_path:
        logger.info('Skipping loading external modules')
        return list()

    logger.info('Loading external modules from %s' % (module_path))
    pluginbase = PluginBase(package='modules_ext')
    plugin_source = pluginbase.make_plugin_source(searchpath=[module_path],
                                                  persist=True,
                                                  identifier='tpymodules')
    modules = list()

    # Find the Plugins
    for plugin_module in plugin_source.list_plugins():

        # Try to load the plugin
        try:
            plugin = plugin_source.load_plugin(plugin_module)
            plugin_classes = inspect.getmembers(plugin, inspect.isclass)

            # Check the classes in the plugin
            for plugin_class in plugin_classes:

                # Only scan local classes
                if plugin_class[1].__module__ == plugin.__name__:

                    # Check base type
                    if issubclass(plugin_class[1], base_type):

                        module_name = plugin_class[0]
                        module = plugin_class[1]
                        module_file = os.path.basename(plugin.__file__)   
                        logger.info('Importing external module %s from %s' % (module_name, module_file))
                        module.__file__ = plugin.__file__
                        module.__plugin__ = True

                        # Add this module
                        modules.append(module)
        except Exception as e:
            logger.error('Unable to load external modules from %s, import failed' % plugin_module)
            # ToDo: Real parsing here
            logger.exception(e)
    return modules
예제 #35
0
class FilterSystem():

    FILTER_TYPE = None

    def __init__(self, selected_filters):
        self._init_plugins()
        if selected_filters == 'all':
            self._set_all_filters()
        else:
            self._set_filters_to_apply(selected_filters)
        self._setup_counters()

    def _init_plugins(self):
        self.plugin_base = PluginBase(
            package='filter_plugins.{}'.format(self.FILTER_TYPE))
        self.filter_plugins = dict()
        self.plugin_source = self.plugin_base.make_plugin_source(searchpath=[
            os.path.join(get_dir_of_file(__file__),
                         '../filter_plugins/{}'.format(self.FILTER_TYPE))
        ])
        plugin_list = self.plugin_source.list_plugins()
        for item in plugin_list:
            plugin = self.plugin_source.load_plugin(item)
            plugin.setup(self)

    def register_plugin(self, name, filter_function):
        self.filter_plugins[name] = filter_function

    def _set_all_filters(self):
        self.filters_to_apply = list(self.filter_plugins.keys())

    def _setup_counters(self):
        self.counter = dict()
        for item in self.filters_to_apply:
            self.counter[item] = 0

    def _set_filters_to_apply(self, filter_list):
        self.filters_to_apply = list()
        for item in filter_list:
            if item in self.filter_plugins:
                self.filters_to_apply.append(item)
            else:
                logging.error('Filter "{}" is not available!'.format(item))
예제 #36
0
import datetime
import os

import sqlalchemy.exc
from pluginbase import PluginBase

from footynews.aggregator.base import Article, InvalidArticle
from footynews.daily_report import DailyReport
from footynews.db.models import Articles, db_session

here = os.path.abspath(os.path.dirname(__file__))

plugin_base = PluginBase(package="web_scraping")
plugin_source = plugin_base.make_plugin_source(searchpath=[os.path.join(here, "web_scraping_plugins")])


def main():
    daily_report = DailyReport(datetime.date.today())
    for plugin in plugin_source.list_plugins():
        source = plugin_source.load_plugin(plugin).setup()
        for article in getattr(source, "extract")():
            if isinstance(article, Article):
                try:
                    db_session.add(Articles(article))
                    db_session.commit()
                except sqlalchemy.exc.IntegrityError as e:
                    if "duplicate key value violates unique constraint" in e.args[0]:
                        print(" Article url {0} already exists".format(article.url))
                        db_session.rollback()
            daily_report.update(article)
    if datetime.datetime.now().hour == 23:
예제 #37
0
파일: partyled.py 프로젝트: Q42/partyled
generators = []
generatorsByName = {}
generatorList = {}
currentTime = time.time()

print "==== PARTYLED ====\nSimulation: ", IsSimulated

class wrapper_Application(object):
    def register_generator(self, name, generator):
        global generatorList
        generatorList[name] = generator

wrapperApp = wrapper_Application()

generatorBase = PluginBase(package='partyled.generatorplugins')
generatorSource = generatorBase.make_plugin_source(searchpath=[get_path('./generators/')])

for plugin_name in generatorSource.list_plugins():
    plugin = generatorSource.load_plugin(plugin_name)
    plugin.setup(wrapperApp, STRIPCOUNT)

print "! Generator plugins: ", generatorList.items()

def setupPWM():
    pwm1 = PWM(0x40)  # PCA9685 board one
    pwm2 = PWM(0x41)  # PCA9685 board two
    pwm1.setPWMFreq(100)  # Not too low, to keep responsiveness to signals high
    pwm2.setPWMFreq(100)  # Also not too high, to prevent voltage rise to cut off and reduce brightness
    return (pwm1, pwm2)

예제 #38
0
my_path = NSBundle.bundleForClass_(objc.lookUpClass("CSShapeCapture").class__()).resourcePath() + "/Python"
sys.path.append(my_path)

from pluginbase import PluginBase
from Foundation import *
from CSShapePathWrapper import *

sys.dont_write_bytecode = True


plugin_base = PluginBase(package='shapeplugins')

library_dirs = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSAllDomainsMask - NSSystemDomainMask, YES)
plugin_dirs = map(lambda x: x + "/Application Support/CocoaSplit/Plugins/Paths", library_dirs)
plugin_dirs.append(NSBundle.bundleForClass_(objc.lookUpClass("CSShapeCapture").class__()).builtInPlugInsPath() + "/Paths")
plugin_source = plugin_base.make_plugin_source(searchpath=plugin_dirs)



class CSShapePathLoader(NSObject):
    
    def init(self):
        self = objc.super(CSShapePathLoader,self).init()
        return self
    
    @objc.signature('@@:@')
    def pathLoaderPath_(self, pluginName):
        plugin_module = plugin_source.load_plugin(pluginName)
        plugin_file = plugin_module.__file__
        real_path = os.path.realpath(plugin_file)
        return real_path
예제 #39
0
def _load_plugins(plugin_path, plugins, plugin_filter, filter_class, base_url,
                  internal_attributes=None, *args):
    """
    Loads endpoint plugins

    :type plugin_path: list[str]
    :type plugins: list[str]
    :type plugin_filter: (type | str) -> bool
    :type internal_attributes: dict[string, dict[str, str | list[str]]]
    :type args: Any
    :rtype list[satosa.plugin_base.endpoint.InterfaceModulePlugin]

    :param plugin_path: Path to the plugin directory
    :param plugins: A list with the name of the plugin files
    :param plugin_filter: Filter what to load from the module file
    :param args: Arguments to the plugin
    :return: A list with all the loaded plugins
    """
    plugin_base = PluginBase(package='satosa_plugins')
    plugin_source = plugin_base.make_plugin_source(searchpath=plugin_path)
    loaded_plugins = []
    loaded_plugin_names = []
    for module_file_name in plugins:
        try:
            module = plugin_source.load_plugin(module_file_name)
            for name, obj in inspect.getmembers(module, plugin_filter):
                loaded_plugins.append(obj(base_url, *args))
                loaded_plugin_names.append(module_file_name)
        except ImportError as error:
            LOGGER.debug("Not a py file or import error '%s': %s", module_file_name, error)
            dict_parsers = [_load_dict,
                            _load_json,
                            _load_yaml]
            _config = None
            for path in plugin_path:
                done = False
                for parser in dict_parsers:
                    _config = parser("%s/%s" % (path, module_file_name))
                    if _config and "plugin" in _config:
                        if _config["plugin"] == filter_class:
                            done = True
                            break
                        else:
                            _config = None
                if done:
                    break
            if _config is not None:
                try:

                    if "plugin" in _config and "MicroService" in _config["plugin"]:
                        # Load micro service
                        if all(k in _config for k in ("plugin", "module")):
                            module_class = locate(_config["module"])
                            instance = None
                            if "config" in _config:
                                instance = module_class(internal_attributes, _config["config"])
                            else:
                                instance = module_class(internal_attributes)
                            loaded_plugins.append(instance)
                        else:
                            LOGGER.warn("Missing mandatory configuration parameters in "
                                        "the micro service plugin %s ('plugin', 'module')."
                                        % module_file_name)
                    else:
                        if all(k in _config for k in ("name", "plugin", "module", "config")):

                            plugin_class = getattr(sys.modules[__name__], _config["plugin"])
                            module_class = locate(_config["module"])
                            if not module_class:
                                raise ValueError("Can't find module '%s'" % _config["module"])
                            name = _config["name"]
                            config = json.dumps(_config["config"])
                            replace = [
                                ("<base_url>", base_url),
                                ("<name>", _config["name"])
                            ]
                            for _replace in replace:
                                config = config.replace(_replace[0], _replace[1])
                            config = json.loads(config)
                            module = plugin_class(module_class, name, config)
                            loaded_plugins.append(module)
                            loaded_plugin_names.append(module_file_name)
                        else:

                            LOGGER.warn("Missing mandatory configuration parameters in "
                                        "the plugin %s (plugin, module, receiver and/or config)."
                                        % module_file_name)
                except Exception as e:
                    LOGGER.exception("Cannot create the module %s." % module_file_name)
        except Exception as error:
            LOGGER.exception("The configuration file %s is corrupt." % module_file_name)
            raise SATOSAConfigurationError(
                    "The configuration file %s is corrupt." % module_file_name) from error
    LOGGER.debug("Loaded plugins: {}".format(loaded_plugin_names))
    return loaded_plugins
예제 #40
0
파일: plugins.py 프로젝트: thijsmie/imp
#import application
#import models
#import response
#import security

from pluginbase import PluginBase


plugin_base = PluginBase(package='imp.plugins')
plugin_src  = plugin_base.make_plugin_source(searchpath=["./plugins"])

#plugin_src.appdata = {"app": application, "models": models, "response": response, "security": security}

plugins = []
for plugin in plugin_src.list_plugins():
    plugins.append(plugin_src.load_plugin(plugin))

예제 #41
0
class Pluggable(object):

    name = 'Pluggable'

    def setup(self, name=None, paths=None):
        paths = paths or ['./plugins']
        self.plugin_base = PluginBase(package='plugins')
        self.setup_source(name)

    def setup_source(self, name):
        # and a source which loads the plugins from the "app_name/plugins"
        # folder.  We also pass the application name as identifier.  This
        # is optional but by doing this out plugins have consistent
        # internal module names which allows pickle to work.
        self.source = self.plugin_base.make_plugin_source(
            searchpath=[get_path('./plugins')],
            identifier=name)

    def import_plugin(self, name):
        '''
        Import a plugin by name
        '''
        return self.source.load_plugin(name)

    def register_load(self):
        '''
        Load the plugins, registering classes, modules and functions outside
        the plugin loader. Returned is a list of registered plugins.
        '''
        plugins = [x for x in self.source.list_plugins()]
        _s = 's' if len(plugins) != 1 else ''
        print 'setting up from {0} plugin location{1}'.format(len(plugins), _s)
        return self.load_plugins()

    def load_plugins(self):
        # Here we list all the plugins the source knows about, load them
        # and the use the "setup" function provided by the plugin to
        # initialize the plugin.
        plugins = self.source.list_plugins()
        for plugin_name in plugins:
            self.source.load_plugin(plugin_name)
        return _registered_plugins

    def register_iter(self):
        for plugin in _registered_plugins:
            yield plugin

    def create(self, app):
        '''
        iterate the plugins, instansiating each and proving a pointer
        '''
        for plugin in _registered_plugins:
            if hasattr(plugin, 'instance') is False:
                inst = self.create_instance(plugin)
                inst.app = app
                ri = IPlugin(plugin.entity, inst)
                _registered_plugins[_registered_plugins.index(plugin)] = ri

    def create_instance(self, plugin):
        '''
        Return an instance of a pluggable object based upon the
        entity provided.
        If a class is provided, it's assumed this is correctly foratted.
        IF a method is passed an instance of Plugin is generated with the
        name of the function as the command.
        '''
        if hasattr(plugin, 'entity') is False:
            import pdb; pdb.set_trace()  # breakpoint 1703bfb0 //

        entity = plugin.entity
        # print plugin
        if isclass(entity):
            inst = entity()
        elif isfunction(entity):
            inst = Plugin(entity.__name__, entity)
        else:
            inst = entity
            # get name
            # create plugin
        return inst

    def register_reduce(self, name, init_value):
        '''
        reduce the value through each name on the register list.
        returned is the value passed through all register methods defined
        by the name argument
        '''
        v = init_value

        for rplugin in self.register_iter():
            _v = getattr(rplugin.instance, name)(v)
            v = _v if _v is not None else v
        return v

    def generate_commands(self, app):
        '''
        Iterate each command, producing the correct methods to
        be implemented on the core object.
        '''
        gdo = []
        ghelp = []
        gcmpl = []

        for rplugin in self.register_iter():
            inst = rplugin.instance
            name, perf = self.generate_do_commands(app, inst)
            gdo.append(name)
            name, perf = self.generate_help_commands(app, inst)
            ghelp.append(name)
            name, perf = self.generate_complete_commands(app, inst)
            gcmpl.append(name)

        self.do_commands = gdo
        self.help_commands = ghelp
        self.complete_commands = gcmpl

    def generate_do_commands(self, app, inst):
        if hasattr(inst, 'perform'):
            # build attr
            name = inst.get_command_name()
            perf = partial(self.run_command, inst.perform, app)
            setattr(app, name, perf)
        return (name, perf)

    def generate_help_commands(self, app, inst):
        if hasattr(inst, 'help'):
            # build attr
            name = inst.get_help_name()
            perf = partial(self.run_help, inst.help, app)
            setattr(app, name, perf)
        return (name, perf)

    def generate_complete_commands(self, app, inst):
        if hasattr(inst, 'complete'):
            # build attr
            name = inst.get_complete_name()
            perf = partial(self.run_complete, inst.complete, app)
            setattr(app, name, perf)
        return (name, perf)

    def run_help(self, perform_method, app, *args):
        '''
        Run a help command
        '''
        help_str = None

        if isinstance(perform_method, (str, unicode)):
            help_str = perform_method
        elif ismethod(perform_method):
            help_str = perform_method(app)
        app._out(help_str)
        return help_str

    def run_command(self, perform_method, app, *args, **kw):
        '''
        run a command as handled by the app called by partial()
        providing the app as the first arg.
        '''
        v = perform_method(app, *args, **kw)
        if v is not None:
            app._out(v)
        return v

    def run_complete(self, perform_method, app, *args):
        ''''''
        v = perform_method(app, *args)
        if v is not None:
            app._out(v)
        return v

    def __getattr__(self, name):
        '''
        delegate to a reduce value through the plugins
        '''
        if hasattr(Plugin, name):
            return partial(self.register_reduce, name)
        else:
            raise AttributeError('{0} is not defined on Plugin'.format(name))
예제 #42
0
from pluginbase import PluginBase

base = PluginBase(package='dummy.modules')
plugin_source = base.make_plugin_source(
    searchpath=['./plugins'])

# This dangles around.  This will be collected when the interpreter
# shuts down.
hello = plugin_source.load_plugin('hello')
예제 #43
0
def main(settings_file='~/.inprocess.json', opt_location=False):
    # Redefine Parser
    class MyParser(optparse.OptionParser):
        def format_epilog(self, formatter):
            return self.epilog

    # Parse Command Line options
    parser = MyParser(epilog=(
        '\n(c)2013 Adam Jackman ([email protected])\n')
    )
    parser.add_option("-s", "--settings", dest="settings_file",
                      help="set settings file", metavar="FILE")
    parser.add_option('-l', '--location', action="store_true", default=False,
                      help="Print storage locations")
    options, arguments = parser.parse_args()

    # Set Variables
    if options.settings_file is not None:
        settings_file = options.settings_file
    with open(expanduser(settings_file), 'rb') as f:
        settings = json.loads(f.read())
    Parseable.settings = settings  # Pass along settings to the Parseable Class

    if options.location or opt_location:
        print('Storage Locations:\n'
              'Settings:    %s\n'
              'Inbox:       %s\n'
              'inx files:   %s\n'
              'inx storage: %s') % (settings_file, settings['inbox_file'],
                                    settings['inbox_dir'],
                                    settings['storage_dir'])
        sys.exit(0)

    # Import all Parseable classes from parseables folder
    plugin_base = PluginBase(package='parseables')
    parsables_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'parseables/');
    plugin_source = plugin_base.make_plugin_source(searchpath=[parsables_dir])
    for plugin_name in plugin_source.list_plugins():
            plugin = plugin_source.load_plugin(plugin_name)

    # List parseable things
    parseables = Parseable.__subclasses__()  # list all direct subclasses of Parseable

    # Grab the list of inx files from the inbox directory, plus the inbox file
    files = os.listdir(settings['inbox_dir'])
    fp = re.compile(
        r"inx [0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}-[0-9]{2}-[0-9]{2}")
    files = filter(lambda file: fp.match(file), files)
    old_files = [settings['inbox_dir'] + file for file in files]
    new_files = [settings['storage_dir'] + file for file in files]
    now = get_now()
    if os.path.exists(settings['inbox_file']):
        inbox_store = settings['storage_dir'] + "inbox " + now.strftime('%Y-%m-%dT%H-%M-%S') + ".md"
        old_files = [settings['inbox_file']] + old_files
        new_files = [inbox_store] + new_files

    # Setup output
    inbox_header = ("# Inbox\n`inbox.md` created " +
                    now.strftime('%B %d, %Y %H:%M:%S') +
                    "\n\n*" + " *"*29 + "\n\n")
    inbox_contents = ''

    # Loop through the list of files
    for f_index, file in enumerate(old_files):
        with open(file, 'rb') as f:
            line = f.readline()
            while line != '':
                for ident in parseables:
                    if ident.identify(line):
                        if ident.multiline:
                            lines = []
                            record = True
                            while ident.identify_end(line) is None:
                                lines = lines + [line]
                                line = f.readline()
                                if line == '':
                                    inbox_contents = inbox_contents + ''.join(lines) + '\n'
                                    break
                            if record:
                                try:
                                    ident(lines).record()
                                except:
                                    inbox_contents = inbox_contents + ''.join(lines) + '\n'
                        else:
                            try:
                                ident(line).record()
                            except:
                                inbox_contents = inbox_contents + line
                        break
                else:  # Runs if we don't know how to parse the current line
                    inbox_contents = inbox_contents + line
                line = f.readline()
        # After File has been processed:
        # Add blank line to remaining contents
        inbox_contents = inbox_contents + '\n\n'
        # Move the file to storage
        shutil.move(file, new_files[f_index])

    # Log inProcess run
    try:
        with open(settings['data_dir'] + 'log_inProcess.csv', 'ab') as csvfile:
            spamwriter = csv.writer(csvfile, quoting=csv.QUOTE_MINIMAL)
            spamwriter.writerow([now])
    except IOError:
        raise RecordError('Problem writing to inProcess log')

    # Write inbox contents to file
    inbox_contents = re.sub(r'\n\s+\n', '\n\n', inbox_contents)  # Change inbox
    if re.sub('\n', '', inbox_contents) != '':
        inbox_contents = inbox_header + inbox_contents
        inbox_contents = re.sub(r"\s*\n\s*\n\s*\n+", r"\n\n", inbox_contents)
        with open(settings['inbox_file'], 'wb') as f:
            f.write(inbox_contents)
예제 #44
0
파일: server.py 프로젝트: Snaipe/git-gud
along with 'git gud'.  If not, see <http://www.gnu.org/licenses/>.
"""

import sys
import os
import spacy.en

from . import nlp

# plugins

from pluginbase import PluginBase

plugin_base = PluginBase(package='gitgud.plugins')

plugin_source = plugin_base.make_plugin_source(
    searchpath=['./plugins', '/usr/share/git/git-gud/plugins'])

for p in plugin_source.list_plugins():
    plugin_source.load_plugin(p)

from xmlrpc.server import SimpleXMLRPCServer

PORT = 4224

# Daemonization

def detach():
    os.chdir('/')
    os.setsid()
    os.umask(0)
예제 #45
0
def setup_module(module):
    global plugin_source
    plugin_base = PluginBase(package='hoster.plugins')
    plugin_source = plugin_base.make_plugin_source(
        searchpath=['../hoster'])
예제 #46
0
__author__ = 'avishai'

import pkg_resources
from pluginbase import PluginBase

plugins_path = pkg_resources.resource_filename('wtf', 'plugins')
plugin_base = PluginBase('wtf.plugins')
plugin_source = plugin_base.make_plugin_source(searchpath=[plugins_path])


def load_plugin(name):
    return plugin_source.load_plugin(name)
예제 #47
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import

import click

from .config import config


# Treat commands as plugins with the help of `pluginbase` library
from pluginbase import PluginBase
plugin_base = PluginBase(package='cmdr.commands')
plugin_source = plugin_base.make_plugin_source(searchpath=[config.COMMANDS_PATH])


class Commander(object):

    def get_command(self, command_name):
        for plugin_name in plugin_source.list_plugins():
            if plugin_name == command_name:
                command = plugin_source.load_plugin(plugin_name)
                return command
        else:
            raise RuntimeError(
                'Command `{0}` not found. Please ensure that a Python '
                'module (or package) named "{0}.py" (or "{0}/__init__.py") '
                'exists in "{1}"'.format(command_name, config.COMMANDS_PATH)
            )

    def get_command_list(self):