<s> import cPickle , mmap , os , struct , time <EOL> from conary . repository import calllog <EOL> from conary . lib import log <EOL> class RepositoryCallLogEntry : <EOL> def __init__ ( self , info ) : <EOL> self . revision = info [ <NUM_LIT:0> ] <EOL> if ( self . revision == <NUM_LIT:1> ) : <EOL> self . entKey = '<STR_LIT>' <EOL> ( self . serverName , self . timeStamp , self . remoteIp , <EOL> ( self . user , self . entClass ) , <EOL> self . methodName , self . args , self . exceptionStr ) = info [ <NUM_LIT:1> : ] <EOL> elif ( self . revision == <NUM_LIT:2> ) : <EOL> ( self . serverName , self . timeStamp , self . remoteIp , <EOL> ( self . user , self . entClass , self . entKey ) , <EOL> self . methodName , self . args , self . exceptionStr ) = info [ <NUM_LIT:1> : ] <EOL> elif ( self . revision == <NUM_LIT:3> ) : <EOL> ( self . serverName , self . timeStamp , self . remoteIp , <EOL> ( self . user , self . entitlements ) , <EOL> self . methodName , self . args , self . exceptionStr ) = info [ <NUM_LIT:1> : ] <EOL> elif ( self . revision == <NUM_LIT:4> ) : <EOL> ( self . serverName , self . timeStamp , self . remoteIp , <EOL> ( self . user , self . entitlements ) , <EOL> self . methodName , self . args , self . kwArgs , <EOL> self . exceptionStr ) = info [ <NUM_LIT:1> : ] <EOL> elif ( self . revision == <NUM_LIT:5> ) : <EOL> ( self . serverName , self . timeStamp , self . remoteIp , <EOL> ( self . user , self . entitlements ) , <EOL> self . methodName , self . args , self . kwArgs , <EOL> self . exceptionStr , self . latency ) = info [ <NUM_LIT:1> : ] <EOL> elif ( self . revision == <NUM_LIT:6> ) : <EOL> ( self . serverName , self . timeStamp , self . remoteIp , <EOL> ( self . user , self . entitlements ) , <EOL> self . methodName , self . args , self . kwArgs , <EOL> self . exceptionStr , self . latency , self . systemId ) = info [ <NUM_LIT:1> : ] <EOL> else : <EOL> assert ( <NUM_LIT:0> ) <EOL> class RepositoryCallLogger ( calllog . AbstractCallLogger ) : <EOL> EntryClass = RepositoryCallLogEntry <EOL> logFormatRevision = <NUM_LIT:6> <EOL> def __init__ ( self , logPath , serverNameList , readOnly = False ) : <EOL> self . serverNameList = serverNameList <EOL> calllog . AbstractCallLogger . __init__ ( self , logPath , readOnly = readOnly ) <EOL> def log ( self , remoteIp , authToken , methodName , args , kwArgs = { } , <EOL> exception = None , latency = None , systemId = None ) : <EOL> self . reopen ( ) <EOL> if exception : <EOL> exception = str ( exception ) <EOL> ( user , entitlements ) = authToken [ <NUM_LIT:0> ] , authToken [ <NUM_LIT:2> ] <EOL> logStr = cPickle . dumps ( ( self . logFormatRevision , self . serverNameList , <EOL> time . time ( ) , remoteIp , ( user , entitlements ) , <EOL> methodName , args , kwArgs , exception , <EOL> latency , systemId ) ) <EOL> try : <EOL> self . fobj . write ( struct . pack ( "<STR_LIT>" , len ( logStr ) ) + logStr ) <EOL> self . fobj . flush ( ) <EOL> except IOError , e : <EOL> log . warning ( "<STR_LIT>" , <EOL> str ( e ) , remoteIp , user , methodName ) <EOL> def __iter__ ( self ) : <EOL> fd = os . open ( self . path , os . O_RDONLY ) <EOL> size = os . fstat ( fd ) . st_size <EOL> if size == <NUM_LIT:0> : <EOL> raise StopIteration <EOL> map = mmap . mmap ( fd , size , access = mmap . ACCESS_READ ) <EOL> i = <NUM_LIT:0> <EOL> while i < size : <EOL> length = struct . unpack ( "<STR_LIT>" , map [ i : i + <NUM_LIT:4> ] ) [ <NUM_LIT:0> ] <EOL> i += <NUM_LIT:4> <EOL> yield self . EntryClass ( cPickle . loads ( map [ i : i + length ] ) ) <EOL> i += length <EOL> os . close ( fd ) </s>
