From: Matthijs Kooijman <matthijs@stdin.nl>
Date: Sat, 7 Aug 2010 18:38:25 +0000 (+0200)
Subject: action: Let each action track a status and log it.
X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=db3987f515ca9f9e9d9437f7a7454e050e1ec273;p=matthijs%2Fprojects%2Fbackupninja.git

action: Let each action track a status and log it.

This allows (in the future) for a nice summary after each run and allows
actions to fail without breaking out with an exception right away.
---

diff --git a/src/lib/backupninja/action.py b/src/lib/backupninja/action.py
index 83afc95..7707f3b 100644
--- a/src/lib/backupninja/action.py
+++ b/src/lib/backupninja/action.py
@@ -68,7 +68,15 @@ def run_action(action_config, opts, global_config):
         # Run it
         action.run(test=opts.test)
         action.finish(test=opts.test)
+        # Ask the action if there where any failures
+        success = not action.failed
     except Exception, e:
-        log.error('Running action "%s.%s" failed: %s', action_name, action_ty, e)
+        log.error('Unexpected exception: %s', e)
         import traceback
         log.debug(traceback.format_exc())
+        success = False
+
+    if success:
+        log.info('Running action "%s.%s" succeeded', action_name, action_ty)
+    else:
+        log.info('Running action "%s.%s" failed', action_name, action_ty)
diff --git a/src/lib/backupninja/handlers/__init__.py b/src/lib/backupninja/handlers/__init__.py
index f6559f9..dbc403e 100644
--- a/src/lib/backupninja/handlers/__init__.py
+++ b/src/lib/backupninja/handlers/__init__.py
@@ -38,6 +38,9 @@ class Action(object):
         # See backupninja.config.load_config for the structure of this
         # value.
         self.default_config = {}
+        # Assume we'll run succesfully. If anything fails in the
+        # meanwhile, set this to True.
+        self.failed = False
 
     def run(self, **kwargs):
         """