summaryrefslogtreecommitdiffstats
path: root/pyfirstaidkit
diff options
context:
space:
mode:
authorJoel Andres Granados <jgranado@redhat.com>2008-11-19 13:46:14 +0100
committerJoel Andres Granados <jgranado@redhat.com>2008-11-19 18:44:24 +0100
commitb8d360b0142961972e4d7bfa67841542554725a3 (patch)
tree2b25cce5a9be006c17229dcb884bf9fd726d0b1b /pyfirstaidkit
parent1b32e6c8032db019a191d3fa37430371de1b9c34 (diff)
downloadfirstaidkit-b8d360b0142961972e4d7bfa67841542554725a3.tar.gz
firstaidkit-b8d360b0142961972e4d7bfa67841542554725a3.tar.xz
firstaidkit-b8d360b0142961972e4d7bfa67841542554725a3.zip
Various small fixes.
Makefile: 1. Cut counts from 1 not 0. 2. Create the "about" info in the makefile instead of spec file. 3. Put subdirs and about targets into one build target. firstaidkit.spec: 1. Erase the about creation from here. 2. Erase the fedora 7 specific stuff. 3. Call make build. 4. xserver plugin does not need rhpl nor rhpxl anymore. 5. Actually include the COPYING file where the about says it is. configuration.py: 1. Change the default backup dir from /tmp/fakbackup to /tmp. /tmp/fakbackup caused some file permission strangeness when a non root user executed fak after root had executed it. This can still occur, but it will be left like this as the user should not execute fak in non root anyway. logging: plugins.py,interpreter.py. __init__.py 1. Always use the reporting object when possible. 2. Add time stamp and level of message to log messages.
Diffstat (limited to 'pyfirstaidkit')
-rw-r--r--pyfirstaidkit/__init__.py13
-rw-r--r--pyfirstaidkit/configuration.py2
-rw-r--r--pyfirstaidkit/interpret.py10
-rw-r--r--pyfirstaidkit/plugins.py38
-rw-r--r--pyfirstaidkit/utils/backup.py7
5 files changed, 45 insertions, 25 deletions
diff --git a/pyfirstaidkit/__init__.py b/pyfirstaidkit/__init__.py
index 2468ddb..874f57c 100644
--- a/pyfirstaidkit/__init__.py
+++ b/pyfirstaidkit/__init__.py
@@ -24,11 +24,18 @@ def initLogger(config=None):
"""We want to initialize loger when we have the filename."""
Logger = logging.getLogger("firstaidkit")
Logger.setLevel(logging.DEBUG)
+
if config.log.method == "none":
- Logger.addHandler(logging.FileHandler("/dev/null"))
+ handler = logging.FileHandler("/dev/null")
+
elif config.log.method == "stdout" or config.log.method == None:
- Logger.addHandler(logging.StreamHandler(sys.stdout))
+ handler = logging.StreamHandler(sys.stdout)
+
else:
# if nothing else matches we just put it into the file.
- Logger.addHandler(logging.FileHandler(config.log.filename))
+ handler = logging.FileHandler(config.log.filename)
+
+ formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
+ handler.setFormatter(formatter)
+ Logger.addHandler(handler)
diff --git a/pyfirstaidkit/configuration.py b/pyfirstaidkit/configuration.py
index 01f4ac7..cb8c5ea 100644
--- a/pyfirstaidkit/configuration.py
+++ b/pyfirstaidkit/configuration.py
@@ -44,7 +44,7 @@ def createDefaultConfig(config):
config.log.fallbacks = "firstaidkit.log,/tmp/firstaidkit.log,/dev/null"
config.plugin.disabled = ""
config.backup.method = "file"
- config.backup.rootpath = "/tmp/fakbackup"
+ config.backup.rootpath = "/tmp"
config.backup.fullpath = ""
config.revert.all = "False"
config.revert.dir = ""
diff --git a/pyfirstaidkit/interpret.py b/pyfirstaidkit/interpret.py
index 54342eb..a55ab0e 100644
--- a/pyfirstaidkit/interpret.py
+++ b/pyfirstaidkit/interpret.py
@@ -26,8 +26,6 @@ from utils import FileBackupStore
from dependency import Dependencies
from configuration import Info
-Logger=logging.getLogger("firstaidkit")
-
class Tasker:
"""The main interpret of tasks described in Config object"""
@@ -180,8 +178,9 @@ class Tasker:
try:
p = pluginSystem.getplugin(self._config.operation.params)
except KeyError:
- Logger.error("No such plugin '%s'" %
- (self._config.operation.params,))
+ self._reporting.info(message = "No such plugin '%s'" % \
+ (self._config.operation.params,), level = TASKER, \
+ origin = self)
return False
flowinfo = [ (f, p.getFlow(f).description) for f in p.getFlows() ]
rep = {"id": self._config.operation.params, "name": p.name,
@@ -194,7 +193,8 @@ class Tasker:
# Any other case
else:
- Logger.error("Incorrect task specified")
+ self._reporting.info(message = "Incorrect task specified", \
+ level = TASKER, origin = self)
self._reporting.stop(level = TASKER, origin = self)
return False
diff --git a/pyfirstaidkit/plugins.py b/pyfirstaidkit/plugins.py
index 3c6d27d..ae73ae6 100644
--- a/pyfirstaidkit/plugins.py
+++ b/pyfirstaidkit/plugins.py
@@ -561,17 +561,21 @@ class PluginSystem(object):
raise InvalidPluginNameException(plugin)
plugindir = os.path.dirname(self._plugins[plugin].__file__)
- Logger.info("Plugin information...")
- Logger.info("name:%s , version:%s , author:%s " % pklass.info())
+ self._reporting.info(message = "Plugin information...", \
+ level = PLUGINSYSTEM, origin = self)
+ self._reporting.info(message = "name:%s , version:%s , author:%s " \
+ % pklass.info(), level = PLUGINSYSTEM, origin = self)
flows = pklass.getFlows()
- Logger.info("Provided flows : %s " % flows)
+ self._reporting.info(message = "Provided flows : %s " % flows, \
+ level = PLUGINSYSTEM, origin = self)
if flow==None:
flowName = pklass.default_flow
else:
flowName = flow
- Logger.info("Using %s flow" % flowName)
+ self._reporting.info(message = "Using %s flow" % flowName, \
+ level = PLUGINSYSTEM, origin = self)
if flowName not in flows:
self._reporting.exception(message = "Flow %s does not exist in "
"plugin %s" % (flowName, plugin), level = PLUGINSYSTEM,
@@ -582,22 +586,26 @@ class PluginSystem(object):
if dependencies:
deps = pklass.getDeps()
if len(deps)>0:
- Logger.info("depends on: %s" % (", ".join(deps),))
+ self._reporting.info(message = "depends on: %s" % \
+ (", ".join(deps),), level = PLUGINSYSTEM, \
+ origin = self)
for d in deps:
if not self._deps.require(d):
- Logger.info("depends on unsatisfied condition: %s" %
- (d,))
+ self._reporting.info(message = "depends on " \
+ "unsatisfied condition: %s" % (d,), \
+ level = PLUGINSYSTEM, origin = self)
self._reporting.stop(level = PLUGIN, origin = self,
message = plugin)
return False
deps = pklass.getConflicts()
if len(deps)>0:
- Logger.info("depends on flags to be unset: %s" %
- (", ".join(deps),))
+ self._reporting.info(message = "depends on flags to be unset: %s" % \
+ (", ".join(deps),), level = PLUGINSYSTEM, origin = self)
for d in deps:
if self._deps.require(d):
- Logger.info("depends on condition to be UNset: %s" %
- (d,))
+ self._reporting.info(message = "depends on condition to be " \
+ "UNset: %s" % (d,), level = PLUGINSYSTEM, \
+ origin = self)
self._reporting.stop(level = PLUGIN, origin = self,
message = plugin)
return False
@@ -620,9 +628,11 @@ class PluginSystem(object):
dependencies = self._deps, backups = self._backups,
path = plugindir, info = infosection, args = " ".join(args))
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))
+ self._reporting.info(message = "Running step %s in plugin %s ..."% \
+ (step, plugin), level = PLUGINSYSTEM, origin = self)
+ self._reporting.info(message = "%s is current step and %s is result " \
+ "of that step." % (step, rv), level = PLUGINSYSTEM, \
+ origin = self)
self._reporting.stop(level = PLUGIN, origin = self, message = plugin)
return True
diff --git a/pyfirstaidkit/utils/backup.py b/pyfirstaidkit/utils/backup.py
index 2a11283..7c4537f 100644
--- a/pyfirstaidkit/utils/backup.py
+++ b/pyfirstaidkit/utils/backup.py
@@ -78,12 +78,14 @@ class FileBackupStore(BackupStoreInterface):
self._metafile = "__meta.pickle"
self._data = {} # name -> (stored as, origin)
self._origin = {} # origin -> name
+ # Because the dir is suppose to be there when we are reverting.
if not reverting:
os.makedirs(self._path)
def saveMeta(self):
f = open(os.path.join(self._path, self._metafile), "wb")
- pickle.dump((self._id, self._data, self._origin), f, pickle.HIGHEST_PROTOCOL)
+ pickle.dump((self._id, self._data, self._origin), f, \
+ pickle.HIGHEST_PROTOCOL)
f.close()
return True
@@ -96,7 +98,8 @@ class FileBackupStore(BackupStoreInterface):
self._data = data
self._origin = origin
else:
- raise BackupException("Loading metadata for different Backup (ID mismatch: '%s' and '%s')" % (self._id, id))
+ raise BackupException("Loading metadata for different Backup " \
+ "(ID mismatch: '%s' and '%s')" % (self._id, id))
return True