19 import sys, os, commands, string, time, traceback, pickle
21 from twisted.application
import internet, service
22 from twisted.internet
import protocol, reactor, utils, defer
23 from twisted.internet.task
import LoopingCall
30 self.logfile.write(
'connectionMade\n' )
34 self.logfile.write( data )
37 print 'stderr: ' + data
38 self.logfile.write(
'stderr: ' + data )
41 self.logfile.write(
'inConnectionLost\n' )
44 self.logfile.write(
'outConnectionLost\n' )
47 self.logfile.write(
'errConnectionLost\n' )
50 self.logfile.write(
'processEnded %s\n' % repr( status_object ) )
51 self.logfile.write( time.strftime(
'%H:%M:%S', time.localtime( time.time() ) ) +
'\n' )
53 self.deferred.callback(
None )
59 self.logfile.write( time.strftime(
'%H:%M:%S', time.localtime( time.time() ) ) +
'\n' )
76 pickle_file =
'runner.pickle'
85 def __init__( self, bin, cmdline, maps, sort = 0, multiplayer = 0, blank_run = 0 ):
90 print 'Operate in multiplayer mode'
91 self.
bin = os.path.abspath( bin )
92 if ( type( cmdline )
is type(
'' ) ):
93 self.
cmdline = string.split( cmdline,
' ' )
98 print 'Loading pickled status %s' % self.
pickle_file
103 print 'Sorting maps oldest runs first'
107 if ( os.path.exists( i_log ) ):
108 maps_sorted.append( ( i, os.path.getmtime( i_log ) ) )
110 maps_sorted.append( ( i, 0 ) )
111 maps_sorted.sort(
lambda x,y : cmp( x[1], y[1] ) )
114 self.maps.append(
'blankrun' )
115 for i
in maps_sorted:
116 self.maps.append( i[ 0 ] )
117 print 'Sorted as: %s\n' % repr( self.
maps )
120 return 'logs/' + string.translate( name, string.maketrans(
'/',
'-' ) ) +
'.log'
124 print 'child has died - state %d' % self.
state
133 self.p_transport.signalProcess(
"KILL" )
138 print 'sleepAVGReply %s%%' % s
142 print 'child process is interactive'
143 self.p_transport.write(
'quit\n' )
151 print traceback.format_tb( sys.exc_info()[2] )
152 print sys.exc_info()[0]
153 print 'exception raised in sleepAVGReply - killing process'
155 self.p_transport.signalProcess(
'KILL' )
158 print 'sleepAVGTimeout - killing process'
160 self.p_transport.signalProcess(
'KILL' )
165 if ( self.
state == 0
or self.
p_transport is None or self.p_transport.pid
is None ):
166 print 'checkCPU: no child process atm'
168 defer = utils.getProcessOutput(
'/bin/bash', [
'-c',
'cat /proc/%d/status | grep SleepAVG' % self.p_transport.pid ] )
175 print 'Starting map: ' + name
177 print 'Logging to: ' + logfile
179 cmdline = [ self.
bin ] + self.
cmdline + [
'+set',
'si_map', name ]
180 if ( name !=
'blankrun' ):
181 cmdline.append(
'+spawnServer' )
184 if ( name !=
'blankrun' ):
185 cmdline += [
'+devmap', name ]
186 print 'Command line: ' + repr( cmdline )
195 print 'doomService startService'
202 print 'doomService stopService'
203 if (
not self.p_transport.pid
is None ):
204 self.p_transport.signalProcess(
'KILL' )
208 pickle.dump( self.
status, handle )