actions: Handle OSErrors when listing action configs.
[matthijs/projects/backupninja.git] / src / lib / backupninja / action.py
index 3f57a188f7b9b6a2f171bbb7f4a34442110b2a6b..66fc5f364830f5b5221db05e44eab691a6115534 100644 (file)
@@ -21,6 +21,8 @@
 
 """ Running backup actions """
 
 
 """ Running backup actions """
 
+import logging as log
+
 from backupninja import config
 from backupninja import handlers
 
 from backupninja import config
 from backupninja import handlers
 
@@ -31,7 +33,13 @@ def run_all_actions(opts, global_config):
     opts are the parsed commandline options, global_config is the parsed
     global configuration.
     """
     opts are the parsed commandline options, global_config is the parsed
     global configuration.
     """
-    actions = config.list_actions(opts)
+    try:
+        actions = config.list_actions(opts)
+    except OSError, e:
+        log.critical('Unable to list actions: %s', e)
+        return
+
+    actions.sort()
 
     for action in actions:
         run_action(action, opts, global_config)
 
     for action in actions:
         run_action(action, opts, global_config)
@@ -50,12 +58,12 @@ def run_action(action, opts, global_config):
 
     # Get the config for this action
     action_config = config.get_action_config(opts, action)
 
     # Get the config for this action
     action_config = config.get_action_config(opts, action)
-    # Create a handler for this action
-    handler = handlers.create_handler(action_ty, action_config)
 
 
-    if handler:
-        # Run the handler
+    try:
+        # Create a handler for this action
+        handler = handlers.create_handler(action_ty, action_config)
+        # Run it
         handler.run()
         handler.finish()
         handler.run()
         handler.finish()
-    # Silently skip invalid handlers, create_handler will have
-    # logged an error
+    except Exception, e:
+        log.error('Running action "%s" failed: %s', action, e)