Author: nunofsantos
Date: 2007-11-27 17:09:16 -0500 (Tue, 27 Nov 2007)
New Revision: 1375
Modified:
mgmt/mint/python/mint/__init__.py
Log:
replace prints with conditional logging, off by default
Modified: mgmt/mint/python/mint/__init__.py
===================================================================
--- mgmt/mint/python/mint/__init__.py 2007-11-27 22:03:51 UTC (rev 1374)
+++ mgmt/mint/python/mint/__init__.py 2007-11-27 22:09:16 UTC (rev 1375)
@@ -42,10 +42,18 @@
class MintModel:
- def __init__(self):
+ def __init__(self, debug=False):
self.currentMethodId = 1
self.outstandingMethodCalls = dict()
self.connectedBrokers = dict()
+ self.debug = debug
+
+ def setDebug(self, debug=True):
+ self.debug = debug
+
+ def log(self, message):
+ if (self.debug):
+ print message
def sanitizeDict(self, d):
if ("id" in d):
@@ -65,14 +73,14 @@
return ""
def configCallback(self, broker, objectName, list, timestamps):
- print "\nCONFIG---------------------------------------------------"
- print objectName
+ self.log("\nCONFIG---------------------------------------------------")
+ self.log(objectName)
d = self.sanitizeDict(dict(list))
connectedBroker = self.connectedBrokers[broker]
d["managedBroker"] = broker
d["recTime"] = datetime.fromtimestamp(timestamps[0]/1000000000)
d["creationTime"] = datetime.fromtimestamp(timestamps[1]/1000000000)
- print d
+ self.log(d)
###FIX
if (objectName == "broker"):
# needs special handling until schema is sendind info about systems
@@ -86,16 +94,16 @@
###FIX
obj = connectedBroker.getByOriginalId(schema.schemaNameToClassMap[objectName],
d["idOriginal"], create=True)
obj.set(**d)
- print "END CONFIG---------------------------------------------------\n"
+ self.log("END
CONFIG---------------------------------------------------\n")
return obj
def instCallback(self, broker, objectName, list, timestamps):
- print "\nINST---------------------------------------------------"
- print objectName
+ self.log("\nINST---------------------------------------------------")
+ self.log(objectName)
d = self.sanitizeDict(dict(list))
connectedBroker = self.connectedBrokers[broker]
d["recTime"] = datetime.fromtimestamp(timestamps[0]/1000000000)
- print d
+ self.log(d)
obj = connectedBroker.getByOriginalId(schema.schemaNameToClassMap[objectName],
d[self.convertIdKey("id")])
d[objectName] = obj
objNameStats = eval("schema.%sStats" %
(schema.schemaNameToClassMap[objectName].__name__))
@@ -108,18 +116,18 @@
d["statsPrev"] = obj.stats
d["stats"] = objStats
obj.set(**d)
- print "END INST---------------------------------------------------\n"
+ self.log("END INST---------------------------------------------------\n")
return objStats
def methodCallback(self, broker, methodId, errorNo, errorText, args):
- print "\nMETHOD---------------------------------------------------"
- print "MethodId=%d" % (methodId)
- print "Error: %d %s" % (errorNo, errorText)
- print "Args: "
- print args
+ self.log("\nMETHOD---------------------------------------------------")
+ self.log("MethodId=%d" % (methodId))
+ self.log("Error: %d %s" % (errorNo, errorText))
+ self.log("Args: ")
+ self.log(args)
method = self.outstandingMethodCalls.pop(methodId)
result = method(errorText, args)
- print "END METHOD---------------------------------------------------\n"
+ self.log("END
METHOD---------------------------------------------------\n")
return result
def connectToBroker(self, host, port):