summaryrefslogtreecommitdiffstats
path: root/pyfirstaidkit/plugins.py
diff options
context:
space:
mode:
authorMartin Sivak <msivak@redhat.com>2008-02-13 15:13:50 +0100
committerMartin Sivak <msivak@redhat.com>2008-02-13 15:13:50 +0100
commitf0b8b6a42b08134fc648fba8f58854e702e82782 (patch)
tree215e530d81c60ba70d0388c5cbde861a93005178 /pyfirstaidkit/plugins.py
parent49f29e326aa4d8db72a36858c539de764b93c1e8 (diff)
downloadfirstaidkit-f0b8b6a42b08134fc648fba8f58854e702e82782.tar.gz
firstaidkit-f0b8b6a42b08134fc648fba8f58854e702e82782.tar.xz
firstaidkit-f0b8b6a42b08134fc648fba8f58854e702e82782.zip
Add FlagTrackerPlugin base class
Diffstat (limited to 'pyfirstaidkit/plugins.py')
-rw-r--r--pyfirstaidkit/plugins.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/pyfirstaidkit/plugins.py b/pyfirstaidkit/plugins.py
index 2eba8d5..bf54c9f 100644
--- a/pyfirstaidkit/plugins.py
+++ b/pyfirstaidkit/plugins.py
@@ -275,6 +275,62 @@ class Plugin(object):
if self.__class__ is Plugin:
Logger.warning("Clean is an abstract method, it should be used as such.")
+class FlagTrackerPlugin(Plugin):
+ """This kind of plugin monitores all the flags in the system and when certain flags
+ are set, provides some kind of higher level flag.
+
+ Example:
+ monitor flags 'filesystem_drive', 'filesystem_lvm' and 'filesystem_ext3' and if
+ everything is ok set the master flag 'filesystem'"""
+
+ # Higher level master flag to set
+ #flag_decide = "x_decide"
+ flag_decide = None
+
+ # List of flags which have to be set for the higher level flag to be set
+ #flag_list = ["x_decide_1", "x_decide_2"]
+ flag_list = []
+
+ # Wait before we have acquired results from all needed flags
+ @classmethod
+ def getDeps(cls):
+ 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 ReturnValue classes.
+ #
+ flows = Flow.init(Plugin)
+ flows["deflogic"] = Flow({
+ Plugin.initial : {ReturnValue: "decide"},
+ "decide" : {ReturnValue: Plugin.final}
+ }, description="The default, fully automated, deciding sequence")
+
+ def decide(self):
+ """Decide about state of higher level flags."""
+ #We want these functions to be overridden by the plugin developer.
+ if self.__class__ is FlagTrackerPlugin:
+ Logger.warning("Decide is an abstract method, it should be used as such.")
+
+ if self.flag_decide is None:
+ Logger.warning("You have to specify flag to set when everything is ok.")
+ return ReturnValue
+
+ for flag in self.flag_list:
+ if not self._dependencies.require(flag):
+ return ReturnValue
+
+ self._dependencies.provide(self.flag_decide)
+ return ReturnValue
+
+
class PluginSystem(object):
"""Encapsulate all plugin detection and import stuff"""