All pastes #278665 Raw Edit

Nagappan

public python v1 · immutable
·published 2006-12-14 08:37 UTC
rendered paste body
Index: ldtp.py===================================================================RCS file: /cvs/ldtp/ldtp/python/ldtp.py,vretrieving revision 1.46diff -u -p -r1.46 ldtp.py--- ldtp.py	5 Dec 2006 06:26:45 -0000	1.46+++ ldtp.py	14 Dec 2006 08:36:30 -0000@@ -219,13 +219,13 @@ def generatexml (commandId, *args): 	if ldtpDebug != None: 		print str (commandId) + ' (', 	if argsLen >= 1:-		_xml = _xml + '<ID>' + saxutils.escape(args[0]) + '</ID>'+		_xml = _xml + '<ID>' + saxutils.escape (args [0]) + '</ID>' 	if commandId != command.INITAPPMAP and argsLen >= 2:-		_xml = _xml + '<CONTEXT>' + saxutils.escape(args[1]) + '</CONTEXT>'+		_xml = _xml + '<CONTEXT>' + saxutils.escape (args [1]) + '</CONTEXT>' 		if ldtpDebug != None: 			print args[1], 	if argsLen >= 3:-		_xml = _xml + '<COMPONENT>' + saxutils.escape(args[2]) + '</COMPONENT>'+		_xml = _xml + '<COMPONENT>' + saxutils.escape (args [2]) + '</COMPONENT>' 		if ldtpDebug != None: 			print ', ' + args[2], 	if argsLen >= 4:@@ -835,7 +835,9 @@ LDTP_LOG_MEMINFO     = 73 LDTP_LOG_CPUINFO     = 74 LDTP_LOG_TESTCASESTART  = 75 LDTP_LOG_TESTCASEEND    = 76-LDTP_LOG_TESTCASESTATUS = 75+LDTP_LOG_TESTCASESTATUS = 77+LDTP_LOG_STARTTAG = 78+LDTP_LOG_STOPTAG  = 79  logging.addLevelName (LDTP_LOG_TESTSTART, 'TESTSTART') logging.addLevelName (LDTP_LOG_TESTEND, 'TESTEND')@@ -854,6 +856,8 @@ logging.addLevelName (LDTP_LOG_SCRIPTSTA logging.addLevelName (LDTP_LOG_SCRIPTEND, 'SCRIPTEND') logging.addLevelName (LDTP_LOG_MEMINFO, 'MEMINFO') logging.addLevelName (LDTP_LOG_CPUINFO, 'CPUINFO')+logging.addLevelName (LDTP_LOG_STARTTAG, 'STARTTAG')+logging.addLevelName (LDTP_LOG_STOPTAG, 'STOPTAG')  class state: 	INVALID = 0@@ -2231,6 +2235,55 @@ def setloglevel (level): 	else: 		return 0 +currentPyVersion = sys.version+regexp = re.compile ('2.5', re.IGNORECASE)+class LdtpLogRecord (logging.LogRecord):+    """+    LogRecord subclass that stores a unique -- transaction -- time+    as an additional attribute+    """+    def __init__ (self, name, level, pathname, lineno, msg, args, exc_info):+	    if level == LDTP_LOG_STARTTAG:+		    msg = '<' + msg + '>'+	    elif level == LDTP_LOG_STOPTAG:+		    msg = '</' + msg + '>'+	    else:+		    msg = '<' + logging.getLevelName (level) +'>' + saxutils.escape (msg) + '</' + logging.getLevelName (level) + '>'+	    if regexp.search (currentPyVersion) == None:+		    logging.LogRecord.__init__ (self, name, level, pathname, lineno, msg, args, exc_info)+	    else:+		    logging.LogRecord.__init__ (self, name, level, pathname, lineno, msg, args, exc_info, None)++if regexp.search (currentPyVersion) == None:+	def makeRecord (name, level, fn, lno, msg, args, exc_info, func = None, extra = None):+		if type (level) != int and len (msg) == 0:+			exc_info = args+			args = msg+			msg = lno+			lno = fn+			fn = level+			level = name+			name = logging.getLogger ('XML').name+		return LdtpLogRecord (name, level, fn, lno, msg, args, exc_info)+else:+	def makeRecord (self, name, level, fn, lno, msg, args, exc_info, func = None, extra = None):+		if type (level) != int and len (msg) == 0:+			exc_info = args+			args = msg+			msg = lno+			lno = fn+			fn = level+			level = name+			name = logging.getLogger ('XML').name+		return LdtpLogRecord (name, level, fn, lno, msg, args, exc_info)++class LdtpLogger (logging.Logger):+    """+    Logger subclass that uses CustomLogRecord as its LogRecord class+    """+    def __init__ (self, name, level=logging.NOTSET):+        logging.Logger.__init__ (self, name, level)+ def startlog (logFileName, fileOverWrite = 1): 	""" Start logging on the specified file. second arugment is optional and 1 is default value 	0 - Append log to an existing file@@ -2247,17 +2300,24 @@ def startlog (logFileName, fileOverWrite 	try: 		global xmlhdlr, logger +		logging.setLoggerClass (LdtpLogger) 		logger = logging.getLogger ('XML') 		xmlLogMode = 'w' 		if fileOverWrite == 0: 			xmlLogMode = 'a'-		xmlhdlr = logging.FileHandler (logFileName, xmlLogMode)+		try:+			xmlhdlr = logging.FileHandler (logFileName, xmlLogMode)+		except IOError:+			pass 		# Format we want to log-		FORMAT = "<%(levelname)s>%(message)s</%(levelname)s>"-		formatter = logging.Formatter (FORMAT)-		xmlhdlr.setFormatter (formatter)+		#FORMAT = "<%(levelname)s>%(message)s</%(levelname)s>"+		#formatter = logging.Formatter (FORMAT)+		#xmlhdlr.setFormatter (formatter) 		logger.addHandler (xmlhdlr) 		logger.setLevel (logging.WARNING)+		logger.makeRecord = makeRecord+		if fileOverWrite == 1:+			logger.log (LDTP_LOG_STARTTAG, 'ldtp')  		return 1 	except LdtpExecutionError, msg:@@ -2341,6 +2401,7 @@ def stoplog (handler = None): 	if handler != None: 		logger.removeHandler (handler) 	elif xmlhdlr != None:+		logger.log (LDTP_LOG_STOPTAG, 'ldtp') 		logger.removeHandler (xmlhdlr) 	else: 		print "DEBUG ********"