diff options
| author | Martin Sivak <msivak@redhat.com> | 2008-06-30 14:08:05 +0200 |
|---|---|---|
| committer | Martin Sivak <msivak@redhat.com> | 2008-06-30 14:08:05 +0200 |
| commit | faf2cc5a133e915bd69b679a66907e14955cefa8 (patch) | |
| tree | bd73143e82b1bd4b2ea3af383311772668151c21 | |
| parent | 98e5fd8c027efb61070f3b255dc15a32d0dc758e (diff) | |
Add the Info object and make it possible to override lock for single section
| -rw-r--r-- | pyfirstaidkit/configuration.py | 16 | ||||
| -rw-r--r-- | pyfirstaidkit/interpret.py | 7 | ||||
| -rw-r--r-- | pyfirstaidkit/plugins.py | 9 |
3 files changed, 28 insertions, 4 deletions
diff --git a/pyfirstaidkit/configuration.py b/pyfirstaidkit/configuration.py index 55b180c..bf337a3 100644 --- a/pyfirstaidkit/configuration.py +++ b/pyfirstaidkit/configuration.py @@ -36,6 +36,7 @@ def createDefaultConfig(config): config.operation.verbose = "False" config.operation.dependencies = "True" config.operation.interactive = "False" + config.operation.printinfo = "False" config.log.method = "file" config.log.filename = "/var/log/firstaidkit.log" config.plugin.disabled = "" @@ -74,6 +75,13 @@ class FAKConfigSection(object): def __init__(self, cfg, name): self.__dict__["__section_name"] = name self.__dict__["__configuration"] = cfg + self.__dict__["__use_lock"] = True + + def lock(self): + self.__dict__["__use_lock"] = True + + def unlock(self): + self.__dict__["__use_lock"] = False def __getattr__(self, key): if not self.__dict__["__configuration"].has_section(self.__dict__["__section_name"]) and self.__dict__["__section_name"]!="DEFAULT": @@ -85,7 +93,7 @@ class FAKConfigSection(object): return self.__dict__["__configuration"].get(self.__dict__["__section_name"], key) def __setattr__(self, key, value): - if self.__dict__["__configuration"].__dict__.has_key("_lock") and self.__dict__["__configuration"].__dict__["_lock"]: + if self.__dict__["__configuration"].__dict__.has_key("_lock") and self.__dict__["__configuration"].__dict__["_lock"] and self.__dict__["__use_lock"]: raise LockedError(key) if not self.__dict__["__configuration"].has_section(self.__dict__["__section_name"]) and self.__dict__["__section_name"]!="DEFAULT": @@ -142,3 +150,9 @@ def getConfigBits(name, cfg = Config): c.lock() return c +class FAKInfo(ConfigParser.SafeConfigParser, FAKConfigMixIn): + pass + +Info = FAKInfo() +Info.lock() + diff --git a/pyfirstaidkit/interpret.py b/pyfirstaidkit/interpret.py index c81cdaf..e140e4e 100644 --- a/pyfirstaidkit/interpret.py +++ b/pyfirstaidkit/interpret.py @@ -16,6 +16,7 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. import os +import sys from plugins import PluginSystem from reporting import Reports, TASKER, PLUGINSYSTEM import logging @@ -23,6 +24,7 @@ import copy from errors import * from utils import FileBackupStore from dependency import Dependencies +from configuration import Info Logger=logging.getLogger("firstaidkit") @@ -157,5 +159,10 @@ class Tasker: self._reporting.stop(level = TASKER, origin = self) return False + if self._config.operation.printinfo: + print "--- Info section ---" + Info.write(sys.stdout) + print "--------------------" + self._reporting.stop(level = TASKER, origin = self) return True diff --git a/pyfirstaidkit/plugins.py b/pyfirstaidkit/plugins.py index ecf1444..28b2221 100644 --- a/pyfirstaidkit/plugins.py +++ b/pyfirstaidkit/plugins.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 configuration import Config +from configuration import Config, Info from returns import * from errors import * from reporting import * @@ -100,7 +100,7 @@ class Plugin(object): default_flow = "diagnose" - def __init__(self, flow, reporting, dependencies, path = None, backups = None): + def __init__(self, flow, reporting, dependencies, path = None, backups = None, info = None): """ Initialize the instance. flow -- Name of the flow to be used with this instance. @@ -114,6 +114,7 @@ class Plugin(object): self._dependencies = dependencies self._path = path self._backups = backups + self._info = info self.provide = dependencies.provide self.unprovide = dependencies.unprovide @@ -542,7 +543,9 @@ class PluginSystem(object): self._reporting.stop(level = PLUGIN, origin = self, message = plugin) return False - p = pklass(flowName, reporting = self._reporting, dependencies = self._deps, backups = self._backups, path = plugindir) + infosection = getattr(Info, plugin) + infosection.unlock() + p = pklass(flowName, reporting = self._reporting, dependencies = self._deps, backups = self._backups, path = plugindir, info = infosection) 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)) |
