1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import os
18 from twisted.python.failure import Failure
19 from twisted.internet import defer, reactor, protocol, error
20 from twisted.protocols.basic import LineOnlyReceiver
21
24
33
36 self.lw.dataReceived(data)
38 print "ERR: '%s'" % (data,)
39
40
42 POLL_INTERVAL = 0.1
43 TIMEOUT_DELAY = 10.0
44 delimiter = os.linesep
45
47 self.logfile = logfile
48 self.in_reconfig = False
49 self.transport = FakeTransport()
50 self.pp = TailProcess()
51 self.pp.lw = self
52 self.processtype = "buildmaster"
53 self.timer = None
54
56
57 if not os.path.exists(self.logfile):
58 open(self.logfile, 'a').close()
59
60
61
62
63
64
65 self.p = reactor.spawnProcess(self.pp, "/usr/bin/tail",
66 ("tail", "-f", "-n", "0", self.logfile),
67 env=os.environ,
68 )
69 self.running = True
70 d = defer.maybeDeferred(self._start)
71 return d
72
77
85
87 try:
88 self.p.signalProcess("KILL")
89 except error.ProcessExitedAlready:
90 pass
91 if self.timer:
92 self.timer.cancel()
93 self.timer = None
94 self.running = False
95 self.in_reconfig = False
96 self.d.callback(results)
97
99 if not self.running:
100 return
101 if "Log opened." in line:
102 self.in_reconfig = True
103 if "loading configuration from" in line:
104 self.in_reconfig = True
105 if "Creating BuildSlave" in line:
106 self.processtype = "buildslave"
107
108 if self.in_reconfig:
109 print line
110
111 if "message from master: attached" in line:
112 return self.finished("buildslave")
113 if "I will keep using the previous config file" in line:
114 return self.finished(Failure(ReconfigError()))
115 if "configuration update complete" in line:
116 return self.finished("buildmaster")
117