diff options
-rw-r--r-- | plugins/sample1Plugin.py | 5 | ||||
-rw-r--r-- | plugins/sample2Plugin.py | 4 | ||||
-rw-r--r-- | plugins/sample3Plugin/sample3Plugin.py | 5 | ||||
-rw-r--r-- | tasker/__init__.py | 1 | ||||
-rw-r--r-- | tasker/plugins.py | 10 | ||||
-rw-r--r-- | tasker/reporting.py | 46 | ||||
-rw-r--r-- | tasker/tasker.py | 4 |
7 files changed, 65 insertions, 10 deletions
diff --git a/plugins/sample1Plugin.py b/plugins/sample1Plugin.py index fa0f954..085261e 100644 --- a/plugins/sample1Plugin.py +++ b/plugins/sample1Plugin.py @@ -23,8 +23,9 @@ class Sample1Plugin(Plugin): name = "Sample1Plugin" version = "0.0.1" author = "Joel Andres Granados" - def __init__(self, flow): - Plugin.__init__(self, flow) + def __init__(self, *args, **kwargs): + Plugin.__init__(self, *args, **kwargs) + def prepare(self): self._result=ReturnValueTrue diff --git a/plugins/sample2Plugin.py b/plugins/sample2Plugin.py index 415d9ad..e16541a 100644 --- a/plugins/sample2Plugin.py +++ b/plugins/sample2Plugin.py @@ -40,8 +40,8 @@ class Sample2Plugin(Plugin): version = "0.0.1" author = "Joel Andres Granados" - def __init__(self, flow): - Plugin.__init__(self, flow) + def __init__(self, *args, **kwargs): + Plugin.__init__(self, *args, **kwargs) def prepare(self): self._result=ReturnValueTrue diff --git a/plugins/sample3Plugin/sample3Plugin.py b/plugins/sample3Plugin/sample3Plugin.py index 319fde4..01f7e83 100644 --- a/plugins/sample3Plugin/sample3Plugin.py +++ b/plugins/sample3Plugin/sample3Plugin.py @@ -24,8 +24,9 @@ class Sample3Plugin(Plugin): name = "Sample3Plugin" version = "0.0.1" author = "Joel Andres Granados" - def __init__(self, flow): - Plugin.__init__(self, flow) + + def __init__(self, *args, **kwargs): + Plugin.__init__(self, *args, **kwargs) def prepare(self): # Prepare command line. diff --git a/tasker/__init__.py b/tasker/__init__.py index d24cd9a..9542dd5 100644 --- a/tasker/__init__.py +++ b/tasker/__init__.py @@ -17,4 +17,5 @@ from tasker import Tasker from configuration import Config +from log import Logger diff --git a/tasker/plugins.py b/tasker/plugins.py index 1a11a97..6551993 100644 --- a/tasker/plugins.py +++ b/tasker/plugins.py @@ -74,13 +74,16 @@ class Plugin(object): "clean" : {ReturnValueTrue: final} } - def __init__(self, flow): + def __init__(self, flow, reporting): """ Initialize the instance. flow -- Name of the flow to be used with this instance. + reporting -- object used to report information to the user The flow is defined in the __init__ so we don't have to worry about changing it. """ + self._reporting = reporting + # # state we are in. # @@ -237,8 +240,9 @@ class Plugin(object): class PluginSystem(object): """Encapsulate all plugin detection and import stuff""" - def __init__(self, config = Config): + def __init__(self, reporting, config = Config): self._path = Config.plugin.path + self._reporting = reporting self._plugins = {} #create list of potential modules in the path @@ -293,7 +297,7 @@ class PluginSystem(object): Logger.error("Flow %s does not exist in plugin %s", flowName, plugin) return - p = pklass(flowName) + p = pklass(flowName, reporting = self._reporting) for (step, rv) in p: #autorun all the needed steps Logger.info("Running step %s in plugin %s ...", step, plugin) Logger.info("%s is current step and %s is result of that step." % (step, rv)) diff --git a/tasker/reporting.py b/tasker/reporting.py new file mode 100644 index 0000000..b2286a9 --- /dev/null +++ b/tasker/reporting.py @@ -0,0 +1,46 @@ +# 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. + +import Queue +import logging + +class Reports(object): + """Instances of this class are used as reporting mechanism by which the + plugins can comminucate back to whatever frontend we are using. + + Message has four parts: + origin - who sent the message (name of the plugin, Pluginsystem, ...) + semantics - what level does the message describe (system, plugin, task, ..) + importance - how is that message important (debug, info, error, ...) + this must be number, possibly the same as in logging module + message - the message itself + """ + + def __init__(self, maxsize=-1): + self._queue = Queue.Queue(maxsize = maxsize) + + def put(self, message, origin, semantics, importance = logging.INFO): + return self._queue.put((origin, semantics, importance, message)) + + def get(self, *args, **kwargs): + return self._queue.get(*args, **kwargs) + + + #There will be helper methods inspired by logging module + def error(self, message, origin, semantics): + return self.put(message, origin, semantics, importance = logging.ERROR) + diff --git a/tasker/tasker.py b/tasker/tasker.py index d26a9a5..c946a75 100644 --- a/tasker/tasker.py +++ b/tasker/tasker.py @@ -17,15 +17,17 @@ from log import Logger from plugins import PluginSystem +from reporting import Reports class Tasker: """The main interpret of tasks described in Config object""" def __init__(self, cfg): self._config = cfg + self._reporting = Reports() def run(self): - pluginSystem = PluginSystem() + pluginSystem = PluginSystem(reporting = self._reporting) if self._config.operation.mode == "auto": for plugin in pluginSystem.list(): |