summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main.py42
-rw-r--r--plugins/sample1Plugin.py2
-rw-r--r--plugins/sample2Plugin.py6
-rw-r--r--plugins/sample3Plugin/sample3Plugin.py2
-rw-r--r--tasker/configuration.py1
-rw-r--r--tasker/interpret.py13
-rw-r--r--tasker/plugins.py17
-rw-r--r--tasker/reporting.py4
8 files changed, 74 insertions, 13 deletions
diff --git a/main.py b/main.py
index 37bdfca..3484acd 100644
--- a/main.py
+++ b/main.py
@@ -17,11 +17,28 @@
import sys
import getopt
+from threading import Thread
from tasker import Tasker
from tasker import Config
+from tasker import reporting
class Flags:
print_config = False
+ main_help = False
+
+class Output(Thread):
+ def __init__(self, queue, *args, **kwargs):
+ self._running = True
+ self._queue = queue
+ Thread.__init__(self, *args, **kwargs)
+
+ def run(self):
+ while self._running:
+ message = self._queue.get()
+ if message[2]==reporting.END:
+ self._running = False
+ continue
+ print message
def usage(name):
print """Usage:
@@ -36,7 +53,7 @@ def usage(name):
-l <method> - select different log method
-x <plugin> - exclude plugin from run
-g <gui> - frontend to show results
- -h - this help
+ -h - help
--print-config - print resulting config file
""" % (name, name, name)
@@ -45,8 +62,10 @@ if __name__=="__main__":
for key,val in params:
if key in ("-t", "--task"):
Config.operation.mode = "task"
- if key in ("-f", "--flow"):
+ Flags.main_help = False
+ elif key in ("-f", "--flow"):
Config.operation.mode = "flow"
+ Flags.main_help = False
elif key in ("-c", "--config"):
Config.read(val)
elif key in ("-v", "--verbose"):
@@ -65,8 +84,8 @@ if __name__=="__main__":
elif key in ("--print-config"):
Flags.print_config = True
elif key in ("-h", "--help"):
- usage(sys.argv[0])
- sys.exit(1)
+ Config.operation.help = "True"
+ Flags.main_help = True
if Config.operation.mode == "flow":
Config.operation.plugin = rest[0]
if len(rest)<=1:
@@ -77,6 +96,9 @@ if __name__=="__main__":
Config.operation.plugin = rest[0]
Config.operation.task = rest[1]
+ if Flags.main_help:
+ usage(sys.argv[0])
+ sys.exit(1)
if Flags.print_config:
print 76*"-"
@@ -85,7 +107,17 @@ if __name__=="__main__":
Config.lock()
+
singlerun = Tasker(Config)
- singlerun.run()
+
+ outputThread = Output(singlerun.reporting())
+ outputThread.start()
+
+ try:
+ singlerun.run()
+ finally:
+ singlerun.end()
+
+ outputThread.join()
diff --git a/plugins/sample1Plugin.py b/plugins/sample1Plugin.py
index 085261e..2c4ff52 100644
--- a/plugins/sample1Plugin.py
+++ b/plugins/sample1Plugin.py
@@ -15,7 +15,7 @@
# 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
+from tasker.plugins import Plugin,Flow
from tasker.returns import *
class Sample1Plugin(Plugin):
diff --git a/plugins/sample2Plugin.py b/plugins/sample2Plugin.py
index e16541a..362e02c 100644
--- a/plugins/sample2Plugin.py
+++ b/plugins/sample2Plugin.py
@@ -15,7 +15,7 @@
# 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
+from tasker.plugins import Plugin,Flow
from tasker.returns import *
class Sample2Plugin(Plugin):
@@ -24,7 +24,7 @@ class Sample2Plugin(Plugin):
# Additional flow defprepareion.
#
flows = {}
- flows["extra"] = {
+ flows["extra"] = Flow({
Plugin.initial: {ReturnValue: "prepare"},
"prepare" : {ReturnValueTrue: "diagnose"},
"diagnose" : {ReturnValueTrue: "clean", ReturnValueFalse: "backup"},
@@ -33,7 +33,7 @@ class Sample2Plugin(Plugin):
"fix" : {ReturnValueTrue: "extraStep", ReturnValueFalse: "restore"},
"extraStep" : {ReturnValueTrue: "clean", ReturnValueFalse: "clean"},
"clean" : {ReturnValueTrue: Plugin.final}
- }
+ }, description="Fixing sequence with one added extraStep")
default_flow = "extra"
name = "Sample2Plugin"
diff --git a/plugins/sample3Plugin/sample3Plugin.py b/plugins/sample3Plugin/sample3Plugin.py
index 01f7e83..d03823b 100644
--- a/plugins/sample3Plugin/sample3Plugin.py
+++ b/plugins/sample3Plugin/sample3Plugin.py
@@ -16,7 +16,7 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
from tasker.returns import *
-from tasker.plugins import Plugin
+from tasker.plugins import Plugin,Flow
import subprocess
class Sample3Plugin(Plugin):
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)