Package vtrace :: Module util
[hide private]
[frames] | no frames]

Source Code for Module vtrace.util

 1  ''' 
 2  Extra utilities for vtrace 
 3  ''' 
 4  # Copyright (C) 2007 Invisigoth - See LICENSE file for details 
 5   
 6  import vtrace 
 7  import vtrace.notifiers as v_notifiers 
 8  import vtrace.rmi as v_rmi 
 9   
10 -class TraceManager:
11 """ 12 A trace-manager is a utility class to extend from when you may be dealing 13 with multiple tracer objects. It allows for persistant mode settings and 14 persistent metadata as well as bundling a DistributedNotifier. You may also 15 extend from this to get auto-magic remote stuff for your managed traces. 16 """
17 - def __init__(self, trace=None):
18 self.trace = trace 19 self.dnotif = v_notifiers.DistributedNotifier() 20 self.modes = {} # See docs for trace modes 21 self.metadata = {} # Like traces, but persistant
22
23 - def manageTrace(self, trace):
24 """ 25 Set all the modes/meta/notifiers in this trace for management 26 by this TraceManager. 27 """ 28 self.trace = trace 29 if vtrace.remote: 30 trace.registerNotifier(vtrace.NOTIFY_ALL, v_rmi.getCallbackProxy(trace, self.dnotif)) 31 else: 32 trace.registerNotifier(vtrace.NOTIFY_ALL, self.dnotif) 33 34 for name,val in self.modes.items(): 35 trace.setMode(name, val) 36 37 for name,val in self.metadata.items(): 38 trace.setMeta(name, val)
39
40 - def unManageTrace(self, trace):
41 """ 42 Untie this trace manager from the trace. 43 """ 44 if vtrace.remote: 45 trace.deregisterNotifier(vtrace.NOTIFY_ALL, v_rmi.getCallbackProxy(trace, self.dnotif)) 46 else: 47 trace.deregisterNotifier(vtrace.NOTIFY_ALL, self.dnotif)
48
49 - def setMode(self, name, value):
50 if self.trace != None: 51 self.trace.setMode(name, value) 52 self.modes[name] = value
53
54 - def getMode(self, name, default=False):
55 if self.trace != None: 56 return self.trace.getMode(name, default) 57 return self.modes.get(name, default)
58
59 - def setMeta(self, name, value):
60 if self.trace != None: 61 self.trace.setMeta(name, value) 62 self.metadata[name] = value
63
64 - def getMeta(self, name, default=None):
65 if self.trace != None: 66 return self.trace.getMeta(name, default) 67 return self.metadata.get(name, default)
68
69 - def registerNotifier(self, event, notif):
70 self.dnotif.registerNotifier(event, notif)
71
72 - def deregisterNotifier(self, event, notif):
73 self.dnotif.deregisterNotifier(event, notif)
74
75 - def fireLocalNotifiers(self, event, trace):
76 """ 77 Deliver a local event to the DistributedNotifier managing 78 the traces. (used to locally bump notifiers) 79 """ 80 self.dnotif.notify(event, trace)
81