From 7c110d15b872cfdd3ac5cdd4342f1f60a833bc57 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Wed, 25 Aug 2010 13:30:59 +0000 Subject: [PATCH] Added plugin.depends_on = ['plugin_id', ...] for plugin.load_on_reg plugins svn: r15816 --- src/gen/plug/_manager.py | 31 +++++++++++++++++++++++++++++++ src/gen/plug/_pluginreg.py | 10 ++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/gen/plug/_manager.py b/src/gen/plug/_manager.py index 949304888..85465d30a 100644 --- a/src/gen/plug/_manager.py +++ b/src/gen/plug/_manager.py @@ -129,9 +129,40 @@ class BasePluginManager(object): if load_on_reg: # Run plugins that request to be loaded on startup and # have a load_on_reg callable. + # first, remove hidden + plugins_to_load = [] for plugin in self.__pgr.filter_load_on_reg(): if plugin.id in config.get("plugin.hiddenplugins"): continue + plugins_to_load.append(plugin) + # next, sort on dependencies + # Probably a more effecient method to get dependency graph: + plugins_sorted = [] + count = 0 + max_count = len(plugins_to_load) + while plugins_to_load: + for plugin in plugins_to_load[:]: # copy of list + delay = False + for depend in plugin.depends_on: + if depend not in [p.id for p in plugins_sorted]: + delay = True + break + if delay: + pass # wait till next loop + else: + if plugin not in plugins_sorted: + plugins_sorted.append(plugin) + if plugin in plugins_to_load: + plugins_to_load.remove(plugin) + count += 1 + if count > max_count: + print "Cannot resolve the following plugin dependencies:" + for plugin in plugins_to_load: + print " Plugin '%s' requires: %s" % ( + plugin.id, plugin.depends_on) + break + # now load them: + for plugin in plugins_sorted: mod = self.load_plugin(plugin) if hasattr(mod, "load_on_reg"): try: diff --git a/src/gen/plug/_pluginreg.py b/src/gen/plug/_pluginreg.py index 2d5e4daf6..f0def694e 100644 --- a/src/gen/plug/_pluginreg.py +++ b/src/gen/plug/_pluginreg.py @@ -351,6 +351,7 @@ class PluginData(object): self._load_on_reg = False self._icons = [] self._icondir = None + self._depends_on = [] #derived var self.mod_name = None #RELCALC attr @@ -527,6 +528,14 @@ class PluginData(object): def _set_icondir(self, icondir): self._icondir = icondir + def _get_depends_on(self): + return self._depends_on + + def _set_depends_on(self, depends): + if not isinstance(depends, list): + raise ValueError, 'Plugin must have depends_on as a list' + self._depends_on = depends + id = property(_get_id, _set_id) name = property(_get_name, _set_name) name_accell = property(_get_name_accell, _set_name_accell) @@ -544,6 +553,7 @@ class PluginData(object): load_on_reg = property(_get_load_on_reg, _set_load_on_reg) icons = property(_get_icons, _set_icons) icondir = property(_get_icondir, _set_icondir) + depends_on = property(_get_depends_on, _set_depends_on) def statustext(self): return STATUSTEXT[self.status]