X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fprojects%2Fbackupninja.git;a=blobdiff_plain;f=src%2Flib%2Fbackupninja%2Fhandlers%2F__init__.py;h=ccb5c8c142ec1b8b9fd0dca30df8d71ed7d8b311;hp=fb57bf43f01622000622a0c21f71056919bf9c70;hb=d64d30066c2cbcf02e1c4d05198ca430584b5cbd;hpb=a2f36355bac67e7369ad224e2f4276a1768e4f50 diff --git a/src/lib/backupninja/handlers/__init__.py b/src/lib/backupninja/handlers/__init__.py index fb57bf4..ccb5c8c 100644 --- a/src/lib/backupninja/handlers/__init__.py +++ b/src/lib/backupninja/handlers/__init__.py @@ -22,9 +22,14 @@ 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, **kwargs): """ @@ -40,10 +45,18 @@ class Handler(object): """ 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. """ @@ -69,7 +82,7 @@ def create_handler(ty, conf): % (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):