1 import os
2
3 from twisted.python import log
4 from twisted.internet import defer
5
6 from buildslave.commands.base import SourceBaseCommand
7 from buildslave import runprocess
8 from buildslave.commands import utils
9
10
11 -class Bzr(SourceBaseCommand):
12 """bzr-specific VC operation. In addition to the arguments
13 handled by SourceBaseCommand, this command reads the following keys:
14
15 ['repourl'] (required): the Bzr repository string
16 ['forceSharedRepo']: force this to a shared repo
17 """
18
19 header = "bzr operation"
20
27
34
39
40 if self.forceSharedRepo:
41 d = self.doForceSharedRepo();
42 d.addCallback(cont)
43 return d
44 else:
45 return cont(None)
46
58
90
92 bzr = self.getCommand('bzr')
93 tmpdir = os.path.join(self.builder.basedir, "export-temp")
94 srcdir = os.path.join(self.builder.basedir, self.srcdir)
95 command = [bzr, 'checkout', '--lightweight']
96 if self.revision:
97 command.append('--revision')
98 command.append(str(self.revision))
99 command.append(self.repourl)
100 command.append(tmpdir)
101 c = runprocess.RunProcess(self.builder, command, self.builder.basedir,
102 sendRC=False, timeout=self.timeout,
103 maxTime=self.maxTime, usePTY=False)
104 self.command = c
105 d = c.start()
106 def _export(res):
107 command = [bzr, 'export', srcdir]
108 c = runprocess.RunProcess(self.builder, command, tmpdir,
109 sendRC=False, timeout=self.timeout,
110 maxTime=self.maxTime, usePTY=False)
111 self.command = c
112 return c.start()
113 d.addCallback(_export)
114 return d
115
117 bzr = self.getCommand('bzr')
118
119
120
121
122 c = runprocess.RunProcess(self.builder, [bzr, 'info', '.'],
123 self.builder.basedir,
124 sendStderr=False, sendRC=False, usePTY=False)
125 d = c.start()
126 def afterCheckSharedRepo(res):
127 if type(res) is int and res != 0:
128 log.msg("No shared repo found, creating it")
129
130 c = runprocess.RunProcess(self.builder, [bzr, 'init-repo', '.'],
131 self.builder.basedir,
132 sendRC=False, usePTY=False)
133 self.command = c
134 return c.start()
135 else:
136 return defer.succeed(res)
137 d.addCallback(afterCheckSharedRepo)
138 return d
139
141
142
143
144 for line in out.split("\n"):
145 colon = line.find(":")
146 if colon != -1:
147 key, value = line[:colon], line[colon+2:]
148 if key == "revno":
149 return int(value)
150 raise ValueError("unable to find revno: in bzr output: '%s'" % out)
151
153 bzr = self.getCommand('bzr')
154 command = [bzr, "version-info"]
155 c = runprocess.RunProcess(self.builder, command,
156 os.path.join(self.builder.basedir, self.srcdir),
157 environ=self.env,
158 sendStdout=False, sendStderr=False, sendRC=False,
159 keepStdout=True, usePTY=False)
160 d = c.start()
161 def _parse(res):
162 try:
163 return self.get_revision_number(c.stdout)
164 except ValueError:
165 msg =("Bzr.parseGotRevision unable to parse output "
166 "of bzr version-info: '%s'" % c.stdout.strip())
167 log.msg(msg)
168 self.sendStatus({'header': msg + "\n"})
169 return None
170 d.addCallback(_parse)
171 return d
172