diff options
author | Martin Sivak <msivak@redhat.com> | 2008-01-02 12:42:47 +0100 |
---|---|---|
committer | Martin Sivak <msivak@redhat.com> | 2008-01-02 12:42:47 +0100 |
commit | d2b141ccdc210dd1f69e4585e9f21c2b0cc1b33a (patch) | |
tree | 20c38bb1d7299002cbd0e34391dca1da6dd1a259 | |
parent | cb8ce9563d58ea6619fe5c5b7a0baf4e4abeb611 (diff) | |
download | firstaidkit-d2b141ccdc210dd1f69e4585e9f21c2b0cc1b33a.tar.gz firstaidkit-d2b141ccdc210dd1f69e4585e9f21c2b0cc1b33a.tar.xz firstaidkit-d2b141ccdc210dd1f69e4585e9f21c2b0cc1b33a.zip |
Sample plugins with dependencies and some dependency system improvements and bugfixes (one typo..)
-rw-r--r-- | plugins/dep1.py | 54 | ||||
-rw-r--r-- | plugins/dep2.py | 53 | ||||
-rw-r--r-- | plugins/dep3.py | 50 | ||||
-rw-r--r-- | tasker/interpret.py | 3 | ||||
-rw-r--r-- | tasker/plugins.py | 19 |
5 files changed, 173 insertions, 6 deletions
diff --git a/plugins/dep1.py b/plugins/dep1.py new file mode 100644 index 0000000..5196208 --- /dev/null +++ b/plugins/dep1.py @@ -0,0 +1,54 @@ +# First Aid Kit - diagnostic and repair tool for Linux +# Copyright (C) 2007 Martin Sivak <msivak@redhat.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +from tasker.plugins import Plugin,Flow +from tasker.returns import * + +class Sample1Plugin(Plugin): + """This plugin uses the predefined flow in the Plugin abstract class.""" + name = "SampleDepends 1 -> 2" + version = "0.0.1" + author = "Joel Andres Granados" + def __init__(self, *args, **kwargs): + Plugin.__init__(self, *args, **kwargs) + + @classmethod + def getDeps(cls): + return set(["sample_dependency"]).union(Plugin.getDeps()) + + def prepare(self): + self._result=ReturnValueTrue + + def backup(self): + self._result=ReturnValueTrue + + def restore(self): + self._result=ReturnValueTrue + + def diagnose(self): + self._result=ReturnValueTrue + self.provide("sample_dependency2") + + def fix(self): + self._result=ReturnValueFalse + + def clean(self): + self._result=ReturnValueTrue + +def get_plugin(): + return Sample1Plugin + diff --git a/plugins/dep2.py b/plugins/dep2.py new file mode 100644 index 0000000..cbd93a0 --- /dev/null +++ b/plugins/dep2.py @@ -0,0 +1,53 @@ +# First Aid Kit - diagnostic and repair tool for Linux +# Copyright (C) 2007 Martin Sivak <msivak@redhat.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +from tasker.plugins import Plugin,Flow +from tasker.returns import * + +class Sample1Plugin(Plugin): + """This plugin uses the predefined flow in the Plugin abstract class.""" + name = "SampleDepends 1,2 > None" + version = "0.0.1" + author = "Joel Andres Granados" + def __init__(self, *args, **kwargs): + Plugin.__init__(self, *args, **kwargs) + + @classmethod + def getDeps(cls): + return set(["sample_dependency", "sample_dependency2"]).union(Plugin.getDeps()) + + def prepare(self): + self._result=ReturnValueTrue + + def backup(self): + self._result=ReturnValueTrue + + def restore(self): + self._result=ReturnValueTrue + + def diagnose(self): + self._result=ReturnValueTrue + + def fix(self): + self._result=ReturnValueFalse + + def clean(self): + self._result=ReturnValueTrue + +def get_plugin(): + return Sample1Plugin + diff --git a/plugins/dep3.py b/plugins/dep3.py new file mode 100644 index 0000000..768cf3a --- /dev/null +++ b/plugins/dep3.py @@ -0,0 +1,50 @@ +# First Aid Kit - diagnostic and repair tool for Linux +# Copyright (C) 2007 Martin Sivak <msivak@redhat.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +from tasker.plugins import Plugin,Flow +from tasker.returns import * + +class Sample1Plugin(Plugin): + """This plugin uses the predefined flow in the Plugin abstract class.""" + name = "SampleDepends None > 2" + version = "0.0.1" + author = "Joel Andres Granados" + def __init__(self, *args, **kwargs): + Plugin.__init__(self, *args, **kwargs) + + def prepare(self): + self._result=ReturnValueTrue + + def backup(self): + self._result=ReturnValueTrue + + def restore(self): + self._result=ReturnValueTrue + + def diagnose(self): + self._result=ReturnValueTrue + self.provide("sample_dependency") + + def fix(self): + self._result=ReturnValueFalse + + def clean(self): + self._result=ReturnValueTrue + +def get_plugin(): + return Sample1Plugin + diff --git a/tasker/interpret.py b/tasker/interpret.py index 7bd0061..da5671a 100644 --- a/tasker/interpret.py +++ b/tasker/interpret.py @@ -28,6 +28,7 @@ class RunDependencies(object): def provide(self, id): """Add flag""" + Logger.info("Setting dependency flag %s", id) self._provide.add(id) def require(self, id): @@ -65,7 +66,7 @@ class Tasker: for plugin in oldlist: if pluginSystem.autorun(plugin): #False when dependencies are not met actlist.remove(plugin) - for plugin in aclist: + for plugin in actlist: self._reporting.info("Plugin %s was not called because of unsatisfied dependencies" % (plugin,), origin = TASKER, importance = logging.WARNING) elif self._config.operation.mode == "flow": try: diff --git a/tasker/plugins.py b/tasker/plugins.py index 53d8c79..8d892c8 100644 --- a/tasker/plugins.py +++ b/tasker/plugins.py @@ -89,6 +89,10 @@ class Plugin(object): The flow is defined in the __init__ so we don't have to worry about changing it. """ self._reporting = reporting + self._dependencies = dependencies + + self.provide = dependencies.provide + self.require = dependencies.require # # state we are in. @@ -138,11 +142,6 @@ class Plugin(object): raise InvalidFlowNameException(flow) @classmethod - def getDeps(cls): - """Return list of conditions required to be set before automated run can be done""" - return set() - - @classmethod def getFlows(cls): """Return a set with the names of all possible flows.""" fatherf = Plugin._defflows.keys() @@ -157,6 +156,16 @@ class Plugin(object): else: return Plugin._defflows[name] + #dependency stuff + @classmethod + def getDeps(cls): + """Return list of conditions required to be set before automated run can be done""" + return set() + + #methods available only for instance, see interpreter.py and dependency stuff there + #def require(self, id) + #def provide(self, id) + #list of all actions provided def actions(self): """Returns list of available actions""" |