コード例 #1
0
ファイル: hierarchy.py プロジェクト: Byron/bcore
 def load_plugins(self, recurse=False, subdirectory="plug-ins"):
     """Call this method explicitly once this instance was pushed onto the top of the context stack.
     This assures that new instances are properly registered with this Context, and not the previous one
     on the stack
     @param recurse if True, plugins will be searched recursively, otherwise they will just be found in the
     plugin directory
     @param subdirectory an optional name of the subdirectory within each configuration directory which 
     is supposed to contain plugin files. If None, the configuration directory itself is used.
     @note plugins should be loaded only AFTER this environment was pushed onto the stack. Otherwise
     loaded plugins will end up in the previous environment, not in this one"""
     for path in self._filter_trees(self.config_trees()):
         if subdirectory is not None:
             path /= subdirectory
         # end amend plugin dir
         load_files(path, recurse=recurse)
コード例 #2
0
ファイル: test_engine.py プロジェクト: Byron/shotgun-events
    def test_plugins(self, rw_dir):
        """load all known plugins and dispatch some events"""
        def raiser(py_file, mod_name):
            raise AssertionError("loading of plugin '%s' failed")
        # end 

        prev_dir = os.getcwd()
        bapp.main().context().push('example plugins')

        plugin_path = Path(__file__).dirname().dirname() / 'plugins'
        examples_path = plugin_path.dirname().dirname().dirname() / 'examples'

        for path in (plugin_path, examples_path):
            assert path.isdir()
            assert load_files(path, on_error=raiser)
        # end for each path to load plugins from

        try:
            os.chdir(rw_dir)
            sg = EventsReadOnlyTestSQLProxyShotgunConnection()
            engine = EventEngine(sg)

            for eid in range(1, 1000, 100):
                sg.next_event_id = sg.first_event_id + eid
                engine._process_events()
            # end 
        finally:
            os.chdir(prev_dir)
コード例 #3
0
ファイル: utility.py プロジェクト: Byron/bcore
    def import_modules(self, store=None, package_name=None):
        """Imports all additional modules as specified in the configuration of our loaded packages
        @param store a kvstore with package settings (and more), usually Application.context().
        If set, we need a package_name as well
        @param package_name needs to be set if a store is given. Useful if no wrapper is involved
        @return a list of import-paths to modules that were loaded successfully.
        @note import errors will be logged, but ignored. We do not reload !
        @note only works if this process is wrapped
        @note this is a way to load plug-ins"""
        if not (store and package_name):
            assert ControlledProcessInformation.has_data()
            info = ControlledProcessInformation()
            store = info.as_kvstore()
            package_name = info.process_data().id
        # end get information

        imported_modules = list()
        if store is None:
            return imported_modules
        # end handle no wrapped process

        for pdata, pname in self._iter_package_data_by_schema(store, package_name, python_package_schema):
            for module in getattr(pdata.python, 'import'):
                imp_module = self.import_module(module, force_reimport=True)
                if imp_module:
                    log.info("Imported module '%s' for package '%s'", module, pname)
                    imported_modules.append(module)
                # end ignore exceptions
            # end for each module to laod
            plugin_paths = pdata.python.plugin_paths
            if plugin_paths:
                package = self._to_package(pname, pdata)
                for plugin_path in plugin_paths:
                    try:
                        if not plugin_path.isabs():
                            plugin_path = package.to_abs_path(plugin_path)
                        # end make plugin path absolute
                        load_files(plugin_path.expand_or_raise())
                    except Exception as err:
                        # plugin's shouldn't be essential, and make a program fail to startup (at least until
                        # we make it a configuration flag)
                        log.error("Failed to load plugin(s) at '%s' with error: %s", plugin_path, err)
                    # end don't quit on failures to load plugins
                # end for each plugin path
            # end handle plugin paths
        # end for each package
        return imported_modules