1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from email.Utils import formatdate
17 import time
18 import re
19
20 from twisted.python import log
21 from twisted.internet import defer
22
23 from buildbot.process import buildstep
24 from buildbot.steps.shell import StringFileWriter
25 from buildbot.steps.source.base import Source
26 from buildbot.interfaces import BuildSlaveTooOldError
27
28 -class CVS(Source):
29
30 name = "cvs"
31
32 renderables = [ "cvsroot" ]
33
34 - def __init__(self, cvsroot=None, cvsmodule='', mode='incremental',
35 method=None, branch=None, global_options=[], extra_options=[],
36 login=None, **kwargs):
37
38 self.cvsroot = cvsroot
39 self.cvsmodule = cvsmodule
40 self.branch = branch
41 self.global_options = global_options
42 self.extra_options = extra_options
43 self.login = login
44 self.mode = mode
45 self.method = method
46 self.srcdir = 'source'
47 Source.__init__(self, **kwargs)
48
49 - def startVC(self, branch, revision, patch):
59 d.addCallback(checkInstall)
60 d.addCallback(self.checkLogin)
61
62 if self.mode == 'incremental':
63 d.addCallback(lambda _: self.incremental())
64 elif self.mode == 'full':
65 d.addCallback(lambda _: self.full())
66
67 d.addCallback(self.parseGotRevision)
68 d.addCallback(self.finish)
69 d.addErrback(self.failed)
70 return d
71
72 @defer.inlineCallbacks
74 updatable = yield self._sourcedirIsUpdatable()
75 if updatable:
76 rv = yield self.doUpdate()
77 else:
78 rv = yield self.clobber()
79 defer.returnValue(rv)
80
81 @defer.inlineCallbacks
83 if self.method == 'clobber':
84 rv = yield self.clobber()
85 defer.returnValue(rv)
86 return
87
88 elif self.method == 'copy':
89 rv = yield self.copy()
90 defer.returnValue(rv)
91 return
92
93 updatable = yield self._sourcedirIsUpdatable()
94 if not updatable:
95 log.msg("CVS repo not present, making full checkout")
96 rv = yield self.doCheckout(self.workdir)
97 elif self.method == 'clean':
98 rv = yield self.clean()
99 elif self.method == 'fresh':
100 rv = yield self.fresh()
101 else:
102 raise ValueError("Unknown method, check your configuration")
103 defer.returnValue(rv)
104
106 cmd = buildstep.RemoteCommand('rmdir', {'dir': self.workdir,
107 'logEnviron': self.logEnviron})
108 cmd.useLog(self.stdio_log, False)
109 d = self.runCommand(cmd)
110 def checkRemoval(res):
111 if res != 0:
112 raise RuntimeError("Failed to delete directory")
113 return res
114 d.addCallback(lambda _: checkRemoval(cmd.rc))
115 d.addCallback(lambda _: self.doCheckout(self.workdir))
116 return d
117
119 d = self.purge(True)
120 d.addCallback(lambda _: self.doUpdate())
121 return d
122
124 d = self.purge(False)
125 d.addCallback(lambda _: self.doUpdate())
126 return d
127
143 d.addCallback(copy)
144 def resetWorkdir(_):
145 self.workdir = 'build'
146 return 0
147 d.addCallback(resetWorkdir)
148 return d
149
150 - def purge(self, ignore_ignores):
164 d.addCallback(evaluate)
165 return d
166
177
190
196 d.addCallback(_gotResults)
197 d.addCallbacks(self.finished, self.checkDisconnect)
198 return d
199
201 if self.login:
202 d = defer.succeed(0)
203 else:
204 d = self._dovccmd(['-d', self.cvsroot, 'login'])
205 def setLogin(res):
206
207 self.login = True
208 return res
209 d.addCallback(setLogin)
210
211 return d
212
213 - def _dovccmd(self, command, workdir=None):
230 d.addCallback(lambda _: evaluateCommand(cmd))
231 return d
232
233 @defer.inlineCallbacks
235 myFileWriter = StringFileWriter()
236 args = {
237 'workdir': self.build.path_module.join(self.workdir, 'CVS'),
238 'writer': myFileWriter,
239 'maxsize': None,
240 'blocksize': 32*1024,
241 }
242
243 cmd = buildstep.RemoteCommand('uploadFile',
244 dict(slavesrc='Root', **args),
245 ignore_updates=True)
246 yield self.runCommand(cmd)
247 if cmd.rc is not None and cmd.rc != 0:
248 defer.returnValue(False)
249 return
250
251
252
253 cvsroot_without_pw = re.sub("(:pserver:[^:]*):[^@]*(@.*)",
254 r"\1\2", self.cvsroot)
255 if myFileWriter.buffer.strip() not in (self.cvsroot,
256 cvsroot_without_pw):
257 defer.returnValue(False)
258 return
259
260 myFileWriter.buffer = ""
261 cmd = buildstep.RemoteCommand('uploadFile',
262 dict(slavesrc='Repository', **args),
263 ignore_updates=True)
264 yield self.runCommand(cmd)
265 if cmd.rc is not None and cmd.rc != 0:
266 defer.returnValue(False)
267 return
268 if myFileWriter.buffer.strip() != self.cvsmodule:
269 defer.returnValue(False)
270 return
271
272 defer.returnValue(True)
273
278
280 d = self._dovccmd(['--version'])
281 def check(res):
282 if res == 0:
283 return True
284 return False
285 d.addCallback(check)
286 return d
287
289 if self.method is not None and self.mode != 'incremental':
290 return self.method
291 elif self.mode == 'incremental':
292 return None
293 elif self.method is None and self.mode == 'full':
294 return 'fresh'
295
297 if not changes:
298 return None
299 lastChange = max([c.when for c in changes])
300 lastSubmit = max([br.submittedAt for br in self.build.requests])
301 when = (lastChange + lastSubmit) / 2
302 return formatdate(when)
303