1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import os
17
18 from twisted.python import log
19 from twisted.internet import defer
20
21 from buildbot.process import buildstep
22 from buildbot.steps.source.base import Source
23 from buildbot.interfaces import BuildSlaveTooOldError
24
25 -class Bzr(Source):
26
27 name = 'bzr'
28 renderables = [ 'repourl', 'baseURL' ]
29
30 - def __init__(self, repourl=None, baseURL=None, mode='incremental',
31 method=None, defaultBranch=None, **kwargs):
32
33 self.repourl = repourl
34 self.baseURL = baseURL
35 self.branch = defaultBranch
36 self.mode = mode
37 self.method = method
38 Source.__init__(self, **kwargs)
39 if repourl and baseURL:
40 raise ValueError("you must provide exactly one of repourl and"
41 " baseURL")
42
43 if repourl is None and baseURL is None:
44 raise ValueError("you must privide at least one of repourl and"
45 " baseURL")
46
47 if baseURL is not None and defaultBranch is None:
48 raise ValueError("you must provide defaultBranch with baseURL")
49
50 assert self.mode in ['incremental', 'full']
51
52 if self.mode == 'full':
53 assert self.method in ['clean', 'fresh', 'clobber', 'copy', None]
54
55 - 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.inlineCallbacks
100 if self.method == 'clobber':
101 yield self.clobber()
102 return
103 elif self.method == 'copy':
104 self.workdir = 'source'
105 yield self.copy()
106 return
107
108 updatable = self._sourcedirIsUpdatable()
109 if not updatable:
110 log.msg("No bzr repo present, making full checkout")
111 yield self._doFull()
112 elif self.method == 'clean':
113 yield self.clean()
114 elif self.method == 'fresh':
115 yield self.fresh()
116 else:
117 raise ValueError("Unknown method, check your configuration")
118
120 cmd = buildstep.RemoteCommand('rmdir', {'dir': self.workdir,
121 'logEnviron': self.logEnviron,})
122 cmd.useLog(self.stdio_log, False)
123 d = self.runCommand(cmd)
124 def checkRemoval(res):
125 if res != 0:
126 raise RuntimeError("Failed to delete directory")
127 return res
128 d.addCallback(lambda _: checkRemoval(cmd.rc))
129 d.addCallback(lambda _: self._doFull())
130 return d
131
146 d.addCallback(copy)
147 return d
148
150 d = self._dovccmd(['clean-tree', '--ignored', '--force'])
151 command = ['update']
152 if self.revision:
153 command.extend(['-r', self.revision])
154 d.addCallback(lambda _: self._dovccmd(command))
155 return d
156
158 d = self._dovccmd(['clean-tree', '--force'])
159 command = ['update']
160 if self.revision:
161 command.extend(['-r', self.revision])
162 d.addCallback(lambda _: self._dovccmd(command))
163 return d
164
171
173 d = defer.succeed(res)
174 def _gotResults(results):
175 self.setStatus(self.cmd, results)
176 log.msg("Closing log, sending result of the command %s " % \
177 (self.cmd))
178 return results
179 d.addCallback(_gotResults)
180 d.addCallbacks(self.finished, self.checkDisconnect)
181 return d
182
192 d.addCallback(_fail)
193 return d
194
200
201 - def _dovccmd(self, command, abandonOnFailure=True, collectStdout=False):
217 d.addCallback(lambda _: evaluateCommand(cmd))
218 return d
219
221 d = self._dovccmd(['--version'])
222 def check(res):
223 if res == 0:
224 return True
225 return False
226 d.addCallback(check)
227 return d
228
230 if self.method is not None and self.mode != 'incremental':
231 return self.method
232 elif self.mode == 'incremental':
233 return None
234 elif self.method is None and self.mode == 'full':
235 return 'fresh'
236
251 d.addCallback(setrev)
252 return d
253