X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fprojects%2Fbackupninja.git;a=blobdiff_plain;f=src%2Flib%2Fbackupninja%2Faction.py;h=7707f3b5548a4772ee992ee0bfef1be2c894de36;hp=7c80148d9c24f15f86e1c49892449e81c62d7e2b;hb=db3987f515ca9f9e9d9437f7a7454e050e1ec273;hpb=ac66ee385bda4a477e5501880ff945be6abc5f06 diff --git a/src/lib/backupninja/action.py b/src/lib/backupninja/action.py index 7c80148..7707f3b 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 @@ -35,37 +36,47 @@ def run_all_actions(opts, global_config): """ log.info('Running all actions') try: - actions = config.list_actions(opts) + action_configs = config.list_actions(opts) except OSError, e: log.critical('Unable to list actions: %s', e) return - actions.sort() + 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. """ - log.info('Running action "%s"', action) # Split the action filename - parts = action.split('.') + 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) + 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 - - # Get the config for this action - action_config = config.get_action_config(opts, action) + log.info('Running action "%s.%s"', action_name, action_ty) try: # Create a handler for this action - handler = handlers.create_handler(action_ty, action_config) + action = handlers.create_action(action_ty) + # Let the handler load its configuration file + action.load_config(action_config) # Run it - handler.run(test=opts.test) - handler.finish(test=opts.test) + 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" failed: %s', action, 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)