1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from twisted.python import log
17 from twisted.internet import defer
18
19 from buildbot.process import buildstep
20 from buildbot.steps.source import Source
21 from buildbot.interfaces import BuildSlaveTooOldError
22
23 -class Bzr(Source):
24
25 name = 'bzr'
26 renderables = [ 'repourl', 'baseURL' ]
27
28 - def __init__(self, repourl=None, baseURL=None, mode='incremental',
29 method=None, defaultBranch=None, **kwargs):
30
31 self.repourl = repourl
32 self.baseURL = baseURL
33 self.branch = defaultBranch
34 self.mode = mode
35 self.method = method
36 Source.__init__(self, **kwargs)
37 self.addFactoryArguments(repourl=repourl,
38 mode=mode,
39 method=method,
40 baseURL=baseURL,
41 defaultBranch=defaultBranch,
42 )
43 if repourl and baseURL:
44 raise ValueError("you must provide exactly one of repourl and"
45 " baseURL")
46
47 if repourl is None and baseURL is None:
48 raise ValueError("you must privide at least one of repourl and"
49 " baseURL")
50
51 if self.repourl is None:
52 self.repourl = self.baseURL + defaultBranch
53
54 assert self.mode in ['incremental', 'full']
55
56 if self.mode == 'full':
57 assert self.method in ['clean', 'fresh', 'clobber', 'copy', None]
58
59 - def startVC(self, branch, revision, patch):
70
71 d.addCallback(checkInstall)
72 if self.mode == 'full':
73 d.addCallback(lambda _: self.full())
74 elif self.mode == 'incremental':
75 d.addCallback(lambda _: self.incremental())
76
77 d.addCallback(self.parseGotRevision)
78 d.addCallback(self.finish)
79 d.addErrback(self.failed)
80 return d
81
83 d = self._sourcedirIsUpdatable()
84 def _cmd(updatable):
85 if updatable:
86 command = ['update']
87 else:
88 command = ['checkout', self.repourl, '.']
89
90 if self.revision:
91 command.extend(['-r', self.revision])
92 return command
93
94 d.addCallback(_cmd)
95 d.addCallback(self._dovccmd)
96 return d
97
98 @defer.deferredGenerator
100 if self.method == 'clobber':
101 wfd = defer.waitForDeferred(self.clobber())
102 yield wfd
103 wfd.getResult()
104 return
105 elif self.method == 'copy':
106 self.workdir = 'source'
107 wfd = defer.waitForDeferred(self.copy())
108 yield wfd
109 wfd.getResult()
110 return
111
112 wfd = defer.waitForDeferred(self._sourcedirIsUpdatable())
113 yield wfd
114 updatable = wfd.getResult()
115 if not updatable:
116 log.msg("No bzr repo present, making full checkout")
117 d = self._doFull()
118 elif self.method == 'clean':
119 d = self.clean()
120 elif self.method == 'fresh':
121 d = self.fresh()
122 else:
123 raise ValueError("Unknown method, check your configuration")
124 wfd = defer.waitForDeferred(d)
125 yield wfd
126 wfd.getResult()
127
129 cmd = buildstep.RemoteCommand('rmdir', {'dir': self.workdir,
130 'logEnviron': self.logEnviron,})
131 cmd.useLog(self.stdio_log, False)
132 d = self.runCommand(cmd)
133 def checkRemoval(res):
134 if res != 0:
135 raise RuntimeError("Failed to delete directory")
136 return res
137 d.addCallback(lambda _: checkRemoval(cmd.rc))
138 d.addCallback(lambda _: self._doFull())
139 return d
140
155 d.addCallback(copy)
156 return d
157
159 d = self._dovccmd(['clean-tree', '--ignored', '--force'])
160 command = ['update']
161 if self.revision:
162 command.extend(['-r', self.revision])
163 d.addCallback(lambda _: self._dovccmd(command))
164 return d
165
167 d = self._dovccmd(['clean-tree', '--force'])
168 command = ['update']
169 if self.revision:
170 command.extend(['-r', self.revision])
171 d.addCallback(lambda _: self._dovccmd(command))
172 return d
173
180
182 d = defer.succeed(res)
183 def _gotResults(results):
184 self.setStatus(self.cmd, results)
185 log.msg("Closing log, sending result of the command %s " % \
186 (self.cmd))
187 return results
188 d.addCallback(_gotResults)
189 d.addCallbacks(self.finished, self.checkDisconnect)
190 return d
191
201 d.addCallback(_fail)
202 return d
203
209
210 - def _dovccmd(self, command, abandonOnFailure=True, collectStdout=False):
225 d.addCallback(lambda _: evaluateCommand(cmd))
226 return d
227
229 d = self._dovccmd(['--version'])
230 def check(res):
231 if res == 0:
232 return True
233 return False
234 d.addCallback(check)
235 return d
236
238 if self.method is not None and self.mode != 'incremental':
239 return self.method
240 elif self.mode == 'incremental':
241 return None
242 elif self.method is None and self.mode == 'full':
243 return 'fresh'
244
259 d.addCallback(setrev)
260 return d
261