handlers: Rename Handler class to Action.
authorMatthijs Kooijman <matthijs@stdin.nl>
Mon, 26 Jul 2010 17:18:41 +0000 (19:18 +0200)
committerMatthijs Kooijman <matthijs@stdin.nl>
Tue, 27 Jul 2010 18:44:33 +0000 (20:44 +0200)
Since instances of this class are really actions, not handlers that can
handle multiple actions, the name Action seems more appropriate (note
that the class itself could be seen as a handler, just not its
instances).

src/lib/backupninja/action.py
src/lib/backupninja/handlers/__init__.py
src/lib/backupninja/handlers/test.py

index b4245f4c236b6a2961ecc6dc8932dd96f4956712..83afc954c8d782403d113b9e5dc3daa3eac65fb9 100644 (file)
@@ -62,12 +62,12 @@ def run_action(action_config, opts, global_config):
 
     try:
         # Create a handler for this action
 
     try:
         # Create a handler for this action
-        handler = handlers.create_handler(action_ty)
+        action = handlers.create_action(action_ty)
         # Let the handler load its configuration file
         # Let the handler load its configuration file
-        handler.load_config(action_config)
+        action.load_config(action_config)
         # Run it
         # Run it
-        handler.run(test=opts.test)
-        handler.finish(test=opts.test)
+        action.run(test=opts.test)
+        action.finish(test=opts.test)
     except Exception, e:
         log.error('Running action "%s.%s" failed: %s', action_name, action_ty, e)
         import traceback
     except Exception, e:
         log.error('Running action "%s.%s" failed: %s', action_name, action_ty, e)
         import traceback
index ccb5c8c142ec1b8b9fd0dca30df8d71ed7d8b311..72b30179a3a0017f9bfe3447b60d9e5d5365922a 100644 (file)
 #    with this program; if not, write to the Free Software Foundation, Inc.,
 #    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 #    with this program; if not, write to the Free Software Foundation, Inc.,
 #    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
-""" Handler superclass with common functionality """
+""" Action superclass with common functionality """
 
 import sys
 import logging as log
 
 from backupninja import config
 
 
 import sys
 import logging as log
 
 from backupninja import config
 
-class Handler(object):
+class Action(object):
+    """
+    Subclasses of Action represent handlers for various action types.
+    This class is called Action instead of Handler, since even though the
+    classes could be referred to as handlers, the instances of this
+    class are really actions (i.e., it represents a specific action,
+    which is a combination of a action type and a specific action
+    configuration).
+    """
     def __init__(self):
         # Subclasses should overwrite this with their default config
         # See backupninja.config.load_config for the structure of this
     def __init__(self):
         # Subclasses should overwrite this with their default config
         # See backupninja.config.load_config for the structure of this
@@ -33,7 +41,7 @@ class Handler(object):
 
     def run(self, **kwargs):
         """
 
     def run(self, **kwargs):
         """
-        Run this handler for a single target. Override this method
+        Run this action for a single target. Override this method
         in a subclass
         """
         pass
         in a subclass
         """
         pass
@@ -53,12 +61,13 @@ class Handler(object):
 
         
 
 
         
 
-def create_handler(ty):
+def create_action(ty):
     """
     """
-    Create a new (subclass of) Handler object for an action with the
+    Create a new (subclass of) Action object for an action with the
     given type.
 
     given type.
 
-    If the handler cannot be loaded, an exception is thrown.
+    If the handler class for this type cannot be loaded, an exception is
+    thrown.
     """
     modname = 'backupninja.handlers.%s' % ty
     # Load the handler if it is not loaded yet
     """
     modname = 'backupninja.handlers.%s' % ty
     # Load the handler if it is not loaded yet
@@ -75,18 +84,18 @@ def create_handler(ty):
     module = sys.modules[modname]
 
     # Check that the module has a "handler" top level function, which
     module = sys.modules[modname]
 
     # Check that the module has a "handler" top level function, which
-    # should create a new Handler object.
+    # should create a new Action object.
     if not hasattr(module, 'handler'):
         raise ImportError('%s is not valid: it '
                           'does not have a "handler" top level function.' 
                           % (module.__file__))
 
     if not hasattr(module, 'handler'):
         raise ImportError('%s is not valid: it '
                           'does not have a "handler" top level function.' 
                           % (module.__file__))
 
-    # Call the "handler" function to create the actual handler
-    handler = module.handler()
+    # Call the "handler" function to create the actual action
+    action = module.handler()
    
    
-    # Check if the handler returned is really a subclass of Handler
-    if not isinstance(handler, Handler):
+    # Check if the handler returned is really a subclass of Action
+    if not isinstance(action, Action):
         raise TypeError('%s is not valid, %s.handler did not return a '
                         'subclass of backupninja.handlers.Handler.'
                         % (module.__file__, modname))
         raise TypeError('%s is not valid, %s.handler did not return a '
                         'subclass of backupninja.handlers.Handler.'
                         % (module.__file__, modname))
-    return handler
+    return action
index ce32c893962be6ae70077c5c3d0b691df725c461..3b8c5d42640da0eca49bbe2aec59b2c474780afd 100644 (file)
 
 import logging as log
 
 
 import logging as log
 
-from backupninja.handlers import Handler
+from backupninja.handlers import Action
 
 
-class TestHandler(Handler):
+class TestAction(Action):
     def run(self, **kwargs):
         log.info(self.conf.get('main', 'message'))
         
     def run(self, **kwargs):
         log.info(self.conf.get('main', 'message'))
         
-handler = TestHandler
+handler = TestAction