X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fprojects%2Fbackupninja.git;a=blobdiff_plain;f=src%2Flib%2Fbackupninja%2Faction.py;h=b4245f4c236b6a2961ecc6dc8932dd96f4956712;hp=bb54d0a168f8b6985505ca658903b0c705a60baa;hb=d64d30066c2cbcf02e1c4d05198ca430584b5cbd;hpb=409a50cb7b0b6ebbf02405e3055e6e5a1865d416 diff --git a/src/lib/backupninja/action.py b/src/lib/backupninja/action.py index bb54d0a..b4245f4 100644 --- a/src/lib/backupninja/action.py +++ b/src/lib/backupninja/action.py @@ -21,6 +21,7 @@ """ Running backup actions """ +import os import logging as log from backupninja import config @@ -33,35 +34,41 @@ 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) - actions.sort() + log.info('Running all actions') + try: + action_configs = config.list_actions(opts) + except OSError, e: + log.critical('Unable to list actions: %s', e) + return + + action_configs.sort() - for action in actions: - run_action(action, opts, global_config) + for action_config in action_configs: + run_action(action_config, opts, global_config) -def run_action(action, opts, global_config): +def run_action(action_config, opts, global_config): """ - Run a single action. opts are the parsed commandline options, + Run a single action. action_config is the full path to its + configuration file. opts are the parsed commandline options, global_config is the parsed global configuration. """ # 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 = os.path.basename(action_config).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_config) return (action_name, action_ty) = parts + log.info('Running action "%s.%s"', action_name, action_ty) - # 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) - - # Silently skip invalid handlers, create_handler will have - # logged an error - if handler: - try: - # Run the handler - handler.run() - handler.finish() - except Exception, e: - log.error('Running action "%s" failed: %s', action, e) + try: + # Create a handler for this action + handler = handlers.create_handler(action_ty) + # Let the handler load its configuration file + handler.load_config(action_config) + # Run it + handler.run(test=opts.test) + handler.finish(test=opts.test) + except Exception, e: + log.error('Running action "%s.%s" failed: %s', action_name, action_ty, e) + import traceback + log.debug(traceback.format_exc())