diff options
author | Martin Sivak <msivak@redhat.com> | 2008-02-28 16:08:09 +0100 |
---|---|---|
committer | Martin Sivak <msivak@redhat.com> | 2008-02-28 16:08:09 +0100 |
commit | b2c3417bb9704b8afab1a0053f100c252a4c8ed5 (patch) | |
tree | d62f0b964d488ac081e435f026ffce37ebd404fd | |
parent | 70efb5c67c477c8b9a801686878f158b0cbdb262 (diff) | |
download | firstaidkit-b2c3417bb9704b8afab1a0053f100c252a4c8ed5.tar.gz firstaidkit-b2c3417bb9704b8afab1a0053f100c252a4c8ed5.tar.xz firstaidkit-b2c3417bb9704b8afab1a0053f100c252a4c8ed5.zip |
Modify the plugins, tasker and cli launcher to provide means to split the flows into diagnostics and fixes.
So when the user launches ./firstaidkit -a it runs only diagnostics. For fixing use ./firstaidkit -a fix
-rwxr-xr-x | firstaidkit | 4 | ||||
-rw-r--r-- | plugins/plugin_examples/sample2Plugin.py | 5 | ||||
-rw-r--r-- | pyfirstaidkit/interpret.py | 11 | ||||
-rw-r--r-- | pyfirstaidkit/plugins.py | 44 |
4 files changed, 42 insertions, 22 deletions
diff --git a/firstaidkit b/firstaidkit index bcfca32..32f6d6f 100755 --- a/firstaidkit +++ b/firstaidkit @@ -121,6 +121,10 @@ if __name__=="__main__": Config.operation.mode = "plugin" else: Config.operation.flow = rest[1] + elif Config.operation.mode == "auto": + if len(rest)>0: + Config.operation.mode = "auto-flow" + Config.operation.flow = rest[0] elif Config.operation.mode == "task": Config.operation.plugin = rest[0] Config.operation.task = rest[1] diff --git a/plugins/plugin_examples/sample2Plugin.py b/plugins/plugin_examples/sample2Plugin.py index 5b471e0..e48389a 100644 --- a/plugins/plugin_examples/sample2Plugin.py +++ b/plugins/plugin_examples/sample2Plugin.py @@ -19,12 +19,12 @@ from pyfirstaidkit.plugins import Plugin,Flow from pyfirstaidkit.returns import * class Sample2Plugin(Plugin): - """This plugin will defin one more function and use it in a newly defined flow.""" + """This plugin will defin one more function and use it in a newly defined fix flow.""" # # Additional flow defprepareion. # flows = Flow.init(Plugin) - flows["extra"] = Flow({ + flows["fix"] = Flow({ Plugin.initial: {Return: "prepare"}, "prepare" : {ReturnSuccess: "diagnose"}, "diagnose" : {ReturnSuccess: "clean", ReturnFailure: "backup"}, @@ -34,7 +34,6 @@ class Sample2Plugin(Plugin): "extraStep" : {ReturnSuccess: "clean", ReturnFailure: "clean"}, "clean" : {ReturnSuccess: Plugin.final} }, description="Fixing sequence with one added extraStep") - default_flow = "extra" name = "Sample2Plugin" version = "0.0.1" diff --git a/pyfirstaidkit/interpret.py b/pyfirstaidkit/interpret.py index 216849d..f77e7e7 100644 --- a/pyfirstaidkit/interpret.py +++ b/pyfirstaidkit/interpret.py @@ -85,14 +85,21 @@ class Tasker: for flag in self._config.operation._list("flags"): self._provide.provide(flag) - if self._config.operation.mode == "auto": + if self._config.operation.mode == "auto" or "auto-flow": + flow = None + if self._config.operation.mode == "auto-flow": + flow = self._config.operation.flow oldlist = set() actlist = set(pluginSystem.list()) #iterate through plugins until there is no plugin left or no action performed during whole iteration while len(actlist)>0 and oldlist!=actlist: oldlist = copy.copy(actlist) for plugin in oldlist: - if pluginSystem.autorun(plugin): #False when dependencies are not met + #If plugin does not contain the automated flow or if it ran correctly, remove it from list + if flow and not flow in pluginSystem.getplugin(plugin).getFlows(): + self._reporting.info("Plugin %s does not contain flow %s" % (plugin, flow,), origin = TASKER) + actlist.remove(plugin) + elif pluginSystem.autorun(plugin, flow = flow): actlist.remove(plugin) for plugin in actlist: self._reporting.info("Plugin %s was not called because of unsatisfied dependencies" % (plugin,), origin = TASKER, importance = logging.WARNING) diff --git a/pyfirstaidkit/plugins.py b/pyfirstaidkit/plugins.py index 49386ae..d8fe14b 100644 --- a/pyfirstaidkit/plugins.py +++ b/pyfirstaidkit/plugins.py @@ -53,9 +53,9 @@ class Plugin(object): # Dictionary that holds all the flows. The keys for each flow is its # name. The flow will be addressed by this name. The plugin developer # Can add as many flows as he wants. The developer must use the instance. - # obj._flows["name"] = SomeFlow. Be aware that you can overwirhte - # previously added flows. This class attribute has to be overriden by - # each plugin. + # flows["name"] = SomeFlow. Be aware that you can overwirhte + # previously added flows. This class attribute has to be initialized by + # each plugin using flows = Flow.init(ParentClass) # flows = {} @@ -68,17 +68,21 @@ class Plugin(object): final = 1 # - # The flow to use with the automated repair mode - # - - default_flow = "defflow" - - # # This is the default flow that all classes deriving from plugin must # have. As the initial state has no return value it will be indexed # with the parent of all Return classes. # - flows["defflow"] = Flow({ + # The flow to use with the automated repair mode + # has to have name "fix". The flow for diagnose mode + # has to be named "diagnose" + # + flows["diagnose"] = Flow({ + initial : {Return: "prepare"}, + "prepare" : {ReturnSuccess: "diagnose"}, + "diagnose" : {ReturnSuccess: "clean", ReturnFailure: "clean"}, + "clean" : {ReturnSuccess: final, ReturnFailure: final} + }, description="The default, fully automated, diagnose sequence") + flows["fix"] = Flow({ initial : {Return: "prepare"}, "prepare" : {ReturnSuccess: "diagnose"}, "diagnose" : {ReturnSuccess: "clean", ReturnFailure: "backup"}, @@ -88,6 +92,12 @@ class Plugin(object): "clean" : {ReturnSuccess: final, ReturnFailure: final} }, description="The default, fully automated, fixing sequence") + # By default, when no other parameters are passed, we use the diagnose flow as + # the default flow to run. You can change this, BUT it MUST always be a non-changing + # non-destructive and safe flow, which does the diagnostics + + default_flow = "diagnose" + def __init__(self, flow, reporting, dependencies): """ Initialize the instance. @@ -299,21 +309,21 @@ class FlagTrackerPlugin(Plugin): return set([x+"?" for x in cls.flag_list]) # - # The flow to use with the automated repair mode - # - - default_flow = "deflogic" - - # # This is the default flow that all classes deriving from plugin must # have. As the initial state has no return value it will be indexed # with the parent of all Return classes. # + # The flow to use with the automated repair mode + # has to have name "fix". The flow for diagnose mode + # has to be named "diagnose" + # + flows = Flow.init(Plugin) - flows["deflogic"] = Flow({ + flows["diagnose"] = Flow({ Plugin.initial : {Return: "decide"}, "decide" : {Return: Plugin.final} }, description="The default, fully automated, deciding sequence") + flows["fix"] = flows["diagnose"] def decide(self): """Decide about state of higher level flags.""" |