Added plugin.depends_on = ['plugin_id', ...] for plugin.load_on_reg plugins
svn: r15816
This commit is contained in:
parent
69b845c388
commit
7c110d15b8
@ -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:
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user