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 buildslave.commands.base import SourceBaseCommand
22 from buildslave import runprocess
23
24
25 -class Bzr(SourceBaseCommand):
26 """bzr-specific VC operation. In addition to the arguments
27 handled by SourceBaseCommand, this command reads the following keys:
28
29 ['repourl'] (required): the Bzr repository string
30 ['forceSharedRepo']: force this to a shared repo
31 """
32
33 header = "bzr operation"
34
41
48
53
54 if self.forceSharedRepo:
55 d = self.doForceSharedRepo();
56 d.addCallback(cont)
57 return d
58 else:
59 return cont(None)
60
73
106
108 bzr = self.getCommand('bzr')
109 tmpdir = os.path.join(self.builder.basedir, "export-temp")
110 srcdir = os.path.join(self.builder.basedir, self.srcdir)
111 command = [bzr, 'checkout', '--lightweight']
112 if self.revision:
113 command.append('--revision')
114 command.append(str(self.revision))
115 command.append(self.repourl)
116 command.append(tmpdir)
117 c = runprocess.RunProcess(self.builder, command, self.builder.basedir,
118 sendRC=False, timeout=self.timeout,
119 maxTime=self.maxTime, logEnviron=self.logEnviron,
120 usePTY=False)
121 self.command = c
122 d = c.start()
123 def _export(res):
124 command = [bzr, 'export', srcdir]
125 c = runprocess.RunProcess(self.builder, command, tmpdir,
126 sendRC=False, timeout=self.timeout,
127 maxTime=self.maxTime, logEnviron=self.logEnviron,
128 usePTY=False)
129 self.command = c
130 return c.start()
131 d.addCallback(_export)
132 return d
133
135 bzr = self.getCommand('bzr')
136
137
138
139
140 c = runprocess.RunProcess(self.builder, [bzr, 'info', '.'],
141 self.builder.basedir,
142 sendStderr=False, sendRC=False,
143 logEnviron=self.logEnviron,usePTY=False)
144 d = c.start()
145 def afterCheckSharedRepo(res):
146 if type(res) is int and res != 0:
147 log.msg("No shared repo found, creating it")
148
149 c = runprocess.RunProcess(self.builder, [bzr, 'init-repo', '.'],
150 self.builder.basedir,
151 sendRC=False, logEnviron=self.logEnviron,
152 usePTY=False)
153 self.command = c
154 return c.start()
155 else:
156 return defer.succeed(res)
157 d.addCallback(afterCheckSharedRepo)
158 return d
159
161
162
163
164 for line in out.split("\n"):
165 colon = line.find(":")
166 if colon != -1:
167 key, value = line[:colon], line[colon+2:]
168 if key == "revno":
169 return int(value)
170 raise ValueError("unable to find revno: in bzr output: '%s'" % out)
171
173 bzr = self.getCommand('bzr')
174 command = [bzr, "version-info"]
175 c = runprocess.RunProcess(self.builder, command,
176 os.path.join(self.builder.basedir, self.srcdir),
177 environ=self.env,
178 sendStdout=False, sendStderr=False, sendRC=False,
179 keepStdout=True, logEnviron=self.logEnviron,
180 usePTY=False)
181 d = c.start()
182 def _parse(res):
183 try:
184 return self.get_revision_number(c.stdout)
185 except ValueError:
186 msg =("Bzr.parseGotRevision unable to parse output "
187 "of bzr version-info: '%s'" % c.stdout.strip())
188 log.msg(msg)
189 self.sendStatus({'header': msg + "\n"})
190 return None
191 d.addCallback(_parse)
192 return d
193