summaryrefslogtreecommitdiffstats
path: root/tasker
diff options
context:
space:
mode:
authorMartin Sivak <msivak@redhat.com>2007-12-19 13:28:18 +0100
committerMartin Sivak <msivak@redhat.com>2007-12-19 13:28:18 +0100
commita9d245e9ddf98c84825ee5accfffa43a23575c16 (patch)
tree61c67a63d0e0e4b98f376188b2622b35ffd51823 /tasker
parent9ab7cc7593030654a67f992ee7775243741baa58 (diff)
downloadfirstaidkit-a9d245e9ddf98c84825ee5accfffa43a23575c16.tar.gz
firstaidkit-a9d245e9ddf98c84825ee5accfffa43a23575c16.tar.xz
firstaidkit-a9d245e9ddf98c84825ee5accfffa43a23575c16.zip
- Make simple reporting thread in main
- Update reporting to support End-Of-Operations message - Update main and interpret to send the End-Of-Operations message - Subclass dict in plugins as Flow and add support for description - Update example plugins to use Flow instead of pure dictionary
Diffstat (limited to 'tasker')
-rw-r--r--tasker/configuration.py1
-rw-r--r--tasker/interpret.py13
-rw-r--r--tasker/plugins.py17
-rw-r--r--tasker/reporting.py4
4 files changed, 32 insertions, 3 deletions
diff --git a/tasker/configuration.py b/tasker/configuration.py
index a84bb2e..70a626e 100644
--- a/tasker/configuration.py
+++ b/tasker/configuration.py
@@ -35,6 +35,7 @@ disabled =
[operation]
mode = auto
+help = False
verbose = False
gui = console
diff --git a/tasker/interpret.py b/tasker/interpret.py
index c946a75..b7a2339 100644
--- a/tasker/interpret.py
+++ b/tasker/interpret.py
@@ -25,9 +25,20 @@ class Tasker:
def __init__(self, cfg):
self._config = cfg
self._reporting = Reports()
+ self.pluginSystem = PluginSystem(reporting = self._reporting)
+
+ def reporting(self):
+ return self._reporting
+
+ def pluginsystem(self):
+ return self.pluginSystem
+
+ def end(self):
+ """Signalize end of operations to all necessary places"""
+ self._reporting.end()
def run(self):
- pluginSystem = PluginSystem(reporting = self._reporting)
+ pluginSystem = self.pluginSystem
if self._config.operation.mode == "auto":
for plugin in pluginSystem.list():
diff --git a/tasker/plugins.py b/tasker/plugins.py
index 36b5a09..251cc43 100644
--- a/tasker/plugins.py
+++ b/tasker/plugins.py
@@ -27,6 +27,11 @@ import os
import subprocess
from cStringIO import StringIO
+class Flow(dict):
+ def __init__(self, rules, description="", *args, **kwargs):
+ self.description = description
+ dict.__init__(self, rules, *args, **kwargs)
+
class Plugin(object):
#
# Some information vars.
@@ -64,7 +69,7 @@ class Plugin(object):
# with the parent of all ReturnValue classes.
#
_defflows = {}
- _defflows["defflow"] = {
+ _defflows["defflow"] = Flow({
initial : {ReturnValue: "prepare"},
"prepare" : {ReturnValueTrue: "diagnose"},
"diagnose" : {ReturnValueTrue: "clean", ReturnValueFalse: "backup"},
@@ -72,7 +77,7 @@ class Plugin(object):
"fix" : {ReturnValueTrue: "clean", ReturnValueFalse: "restore"},
"restore" : {ReturnValueTrue: "clean", ReturnValueFalse: "clean"},
"clean" : {ReturnValueTrue: final}
- }
+ }, description="The default, fully automated, fixing sequence")
def __init__(self, flow, reporting):
""" Initialize the instance.
@@ -137,6 +142,14 @@ class Plugin(object):
fatherf = Plugin._defflows.keys()
pluginf = cls.flows.keys()
return set(fatherf+pluginf)
+
+ @classmethod
+ def getFlow(cls, name):
+ """Return a Flow object associated with provided name"""
+ if cls.flows.has_key(name):
+ return cls.flows[name]
+ else:
+ return Plugin._defflows[name]
#list of all actions provided
def actions(self):
diff --git a/tasker/reporting.py b/tasker/reporting.py
index 38f84b4..1fa60f2 100644
--- a/tasker/reporting.py
+++ b/tasker/reporting.py
@@ -34,6 +34,7 @@ PROGRESS = 2
INFO = 3
ALERT = 4
EXCEPTION = 5
+END = 1000 #End of operations, final message
class Reports(object):
"""Instances of this class are used as reporting mechanism by which the
@@ -64,6 +65,9 @@ class Reports(object):
#There will be helper methods inspired by logging module
+ def end(self):
+ return self.put(None, None, END, importance = 1000)
+
def error(self, message, origin, semantics):
return self.put(message, origin, semantics, importance = logging.ERROR)