Back to index

obnam  1.1
Public Member Functions | Public Attributes | Static Public Attributes
obnamlib.hooks.Hook Class Reference
Inheritance diagram for obnamlib.hooks.Hook:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def __init__
def add_callback
def call_callbacks
def remove_callback

Public Attributes

 callbacks
 priorities

Static Public Attributes

int EARLY_PRIORITY = 250
int DEFAULT_PRIORITY = 500
int LATE_PRIORITY = 750

Detailed Description

A hook.

Definition at line 35 of file hooks.py.


Constructor & Destructor Documentation

Reimplemented in obnamlib.hooks.FilterHook.

Definition at line 43 of file hooks.py.

00043 
00044     def __init__(self):
00045         self.callbacks = []
00046         self.priorities = {}
        

Member Function Documentation

def obnamlib.hooks.Hook.add_callback (   self,
  callback,
  priority = DEFAULT_PRIORITY 
)
Add a callback to this hook.

Return an identifier that can be used to remove this callback.

Reimplemented in obnamlib.hooks.FilterHook.

Definition at line 47 of file hooks.py.

00047 
00048     def add_callback(self, callback, priority=DEFAULT_PRIORITY):
00049         '''Add a callback to this hook.
00050         
00051         Return an identifier that can be used to remove this callback.
00052 
00053         '''
00054 
00055         if callback not in self.callbacks:
00056             self.priorities[callback] = priority
00057             self.callbacks.append(callback)
00058             self.callbacks.sort(lambda x,y: cmp(self.priorities[x], 
00059                                                 self.priorities[y]))
00060             
00061         return callback
        
def obnamlib.hooks.Hook.call_callbacks (   self,
  args,
  kwargs 
)
Call all callbacks with the given arguments.

Definition at line 62 of file hooks.py.

00062 
00063     def call_callbacks(self, *args, **kwargs):
00064         '''Call all callbacks with the given arguments.'''
00065         for callback in self.callbacks:
00066             callback(*args, **kwargs)
        
def obnamlib.hooks.Hook.remove_callback (   self,
  callback_id 
)
Remove a specific callback.

Reimplemented in obnamlib.hooks.FilterHook.

Definition at line 67 of file hooks.py.

00067 
00068     def remove_callback(self, callback_id):
00069         '''Remove a specific callback.'''
00070         if callback_id in self.callbacks:
00071             self.callbacks.remove(callback_id)
00072             del self.priorities[callback_id]
00073 


Member Data Documentation

Definition at line 44 of file hooks.py.

Definition at line 40 of file hooks.py.

Definition at line 39 of file hooks.py.

Definition at line 41 of file hooks.py.

Definition at line 45 of file hooks.py.


The documentation for this class was generated from the following file: