X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Flib%2Fbackupninja%2Faction.py;h=de36c4ba713fb7a5198d5abdc9d0792fdbfe6427;hb=1f0203fd6f3b7833a619f4206c118056c4b469d9;hp=3f57a188f7b9b6a2f171bbb7f4a34442110b2a6b;hpb=c9514724e6fad55405d92f3931056d5f69cfa4f4;p=matthijs%2Fprojects%2Fbackupninja.git diff --git a/src/lib/backupninja/action.py b/src/lib/backupninja/action.py index 3f57a18..de36c4b 100644 --- a/src/lib/backupninja/action.py +++ b/src/lib/backupninja/action.py @@ -21,6 +21,8 @@ """ Running backup actions """ +import logging as log + from backupninja import config from backupninja import handlers @@ -31,7 +33,14 @@ def run_all_actions(opts, global_config): opts are the parsed commandline options, global_config is the parsed global configuration. """ - actions = config.list_actions(opts) + log.info('Running all actions') + 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) @@ -41,21 +50,24 @@ def run_action(action, opts, global_config): Run a single action. opts are the parsed commandline options, global_config is the parsed global configuration. """ + log.info('Running action "%s"', action) # Split the action filename - parts = action.split('.', 2) - if (len(parts) < 2): - log.error('Invalid action filename: "%s". Should be in the form name.type, where type is a valid handler.') + parts = action.split('.') + if (len(parts) != 2): + log.error('Invalid action filename: "%s". Should be in the form name.type, where type is a valid handler.' % action) return (action_name, action_ty) = parts # 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 - handler.run() - handler.finish() - # Silently skip invalid handlers, create_handler will have - # logged an error + + try: + # Create a handler for this action + handler = handlers.create_handler(action_ty, action_config) + # Run it + handler.run(test=opts.test) + handler.finish(test=opts.test) + except Exception, e: + log.error('Running action "%s" failed: %s', action, e) + import traceback + log.debug(traceback.format_exc())