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
72
104
106 bzr = self.getCommand('bzr')
107 tmpdir = os.path.join(self.builder.basedir, "export-temp")
108 srcdir = os.path.join(self.builder.basedir, self.srcdir)
109 command = [bzr, 'checkout', '--lightweight']
110 if self.revision:
111 command.append('--revision')
112 command.append(str(self.revision))
113 command.append(self.repourl)
114 command.append(tmpdir)
115 c = runprocess.RunProcess(self.builder, command, self.builder.basedir,
116 sendRC=False, timeout=self.timeout,
117 maxTime=self.maxTime, usePTY=False)
118 self.command = c
119 d = c.start()
120 def _export(res):
121 command = [bzr, 'export', srcdir]
122 c = runprocess.RunProcess(self.builder, command, tmpdir,
123 sendRC=False, timeout=self.timeout,
124 maxTime=self.maxTime, usePTY=False)
125 self.command = c
126 return c.start()
127 d.addCallback(_export)
128 return d
129
131 bzr = self.getCommand('bzr')
132
133
134
135
136 c = runprocess.RunProcess(self.builder, [bzr, 'info', '.'],
137 self.builder.basedir,
138 sendStderr=False, sendRC=False, usePTY=False)
139 d = c.start()
140 def afterCheckSharedRepo(res):
141 if type(res) is int and res != 0:
142 log.msg("No shared repo found, creating it")
143
144 c = runprocess.RunProcess(self.builder, [bzr, 'init-repo', '.'],
145 self.builder.basedir,
146 sendRC=False, usePTY=False)
147 self.command = c
148 return c.start()
149 else:
150 return defer.succeed(res)
151 d.addCallback(afterCheckSharedRepo)
152 return d
153
155
156
157
158 for line in out.split("\n"):
159 colon = line.find(":")
160 if colon != -1:
161 key, value = line[:colon], line[colon+2:]
162 if key == "revno":
163 return int(value)
164 raise ValueError("unable to find revno: in bzr output: '%s'" % out)
165
167 bzr = self.getCommand('bzr')
168 command = [bzr, "version-info"]
169 c = runprocess.RunProcess(self.builder, command,
170 os.path.join(self.builder.basedir, self.srcdir),
171 environ=self.env,
172 sendStdout=False, sendStderr=False, sendRC=False,
173 keepStdout=True, usePTY=False)
174 d = c.start()
175 def _parse(res):
176 try:
177 return self.get_revision_number(c.stdout)
178 except ValueError:
179 msg =("Bzr.parseGotRevision unable to parse output "
180 "of bzr version-info: '%s'" % c.stdout.strip())
181 log.msg(msg)
182 self.sendStatus({'header': msg + "\n"})
183 return None
184 d.addCallback(_parse)
185 return d
186