import sys
import logging as log
+from backupninja import config
+
class Handler(object):
- def __init__(self, conf):
- self.conf = conf
+ def __init__(self):
+ # Subclasses should overwrite this with their default config
+ # See backupninja.config.load_config for the structure of this
+ # value.
+ self.default_config = {}
- def run(self):
+ def run(self, **kwargs):
"""
Run this handler for a single target. Override this method
in a subclass
"""
pass
- def finish(self):
+ def finish(self, **kwargs):
"""
Called when all targets have been processed. Can be overridden
in a subclass.
"""
pass
-def create_handler(ty, conf):
+ def load_config(self, filename):
+ """
+ Load the configuration for this action from the given filename.
+ """
+ self.conf = config.load_config(filename, self.default_config)
+
+
+
+def create_handler(ty):
"""
Create a new (subclass of) Handler object for an action with the
- given type. conf is the configuration to pass to the handler.
+ given type.
If the handler cannot be loaded, an exception is thrown.
"""
% (module.__file__))
# Call the "handler" function to create the actual handler
- handler = module.handler(conf)
+ handler = module.handler()
# Check if the handler returned is really a subclass of Handler
if not isinstance(handler, Handler):