def wrapper(self, *args, **kwargs): if not getattr(self, '_loaded', False): # This block is executed on the first call to the function. # The return value of the call (or exception raised) is saved # as attributes on the wrapper for future invocations. self._loaded = True self._return = None try: result = func(self, *args, **kwargs) except Exception: self._loaded = False # If any errors occur in loading the plugin, log the information, and # store failure information that can be queried through the api. logprint.exception('Failed to load plugin %s' % self.name) self._pluginFailureInfo = sys.exc_info() raise _pluginLoadOrder.append(self.name) self._return = result self._success = True logprint.success('Loaded plugin "%s"' % self.name) return self._return
def loadPlugins(plugins, root, appconf, apiRoot=None, curConfig=None, buildDag=True): """ Loads a set of plugins into the application. :param plugins: The set of plugins to load, by directory name. :type plugins: list :param root: The root node of the server tree. :type root: object :param appconf: The server's cherrypy configuration object. :type appconf: dict :param apiRoot: The cherrypy api root object. :type apiRoot: object or None :param curConfig: A girder config object to use. :type curConfig: dict or None :param buildDag: If the ``plugins`` parameter is already a topo-sorted list with all dependencies resolved, set this to False and it will skip rebuilding the DAG. Otherwise the dependency resolution and sorting will occur within this method. :type buildDag: bool :returns: A 3-tuple containing the modified root, config, and apiRoot objects. :rtype tuple: """ # Register a pseudo-package for the root of all plugins. This must be # present in the system module list in order to avoid import warnings. if curConfig is None: curConfig = _config.getConfig() if 'plugins' in curConfig and 'plugin_directory' in curConfig['plugins']: logprint.warning( 'Warning: the plugin_directory setting is deprecated. Please use ' 'the `girder-install plugin` command and remove this setting from ' 'your config file.') if ROOT_PLUGINS_PACKAGE not in sys.modules: module = imp.new_module(ROOT_PLUGINS_PACKAGE) girder.plugins = module sys.modules[ROOT_PLUGINS_PACKAGE] = module logprint.info('Resolving plugin dependencies...') if buildDag: plugins = getToposortedPlugins(plugins, curConfig, ignoreMissing=True) for plugin in plugins: try: root, appconf, apiRoot = loadPlugin( plugin, root, appconf, apiRoot, curConfig=curConfig) logprint.success('Loaded plugin "%s"' % plugin) except Exception: logprint.exception( 'ERROR: Failed to load plugin "%s":' % plugin) return root, appconf, apiRoot
def wrapper(self, *args, **kwargs): if not getattr(self, '_loaded', False): # This block is executed on the first call to the function. # The return value of the call is saved an attribute on the wrapper # for future invocations. self._return = func(self, *args, **kwargs) self._loaded = True _pluginLoadOrder.append(self.name) logprint.success('Loaded plugin "%s"' % self.name) return self._return
def loadPlugins(plugins, root, appconf, apiRoot=None, buildDag=True): """ Loads a set of plugins into the application. :param plugins: The set of plugins to load, by directory name. :type plugins: list :param root: The root node of the server tree. :type root: object :param appconf: The server's cherrypy configuration object. :type appconf: dict :param apiRoot: The cherrypy api root object. :type apiRoot: object or None :param buildDag: If the ``plugins`` parameter is already a topo-sorted list with all dependencies resolved, set this to False and it will skip rebuilding the DAG. Otherwise the dependency resolution and sorting will occur within this method. :type buildDag: bool :returns: A 3-tuple containing the modified root, config, and apiRoot objects. :rtype tuple: """ # Register a pseudo-package for the root of all plugins. This must be # present in the system module list in order to avoid import warnings. if ROOT_PLUGINS_PACKAGE not in sys.modules: module = imp.new_module(ROOT_PLUGINS_PACKAGE) girder.plugins = module sys.modules[ROOT_PLUGINS_PACKAGE] = module logprint.info('Resolving plugin dependencies...') if buildDag: plugins = getToposortedPlugins(plugins, ignoreMissing=True) for plugin in plugins: try: root, appconf, apiRoot = loadPlugin(plugin, root, appconf, apiRoot) _clearPluginFailureInfo(plugin=plugin) logprint.success('Loaded plugin "%s"' % plugin) except Exception: _recordPluginFailureInfo(plugin=plugin, traceback=traceback.format_exc()) logprint.exception('ERROR: Failed to load plugin "%s":' % plugin) return root, appconf, apiRoot