1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import os, re
17
18 from twisted.python import log
19
20 from buildslave.commands.base import SourceBaseCommand
21 from buildslave import runprocess
22 from buildslave.util import Obfuscated
23
24
25 -class P4Base(SourceBaseCommand):
26 """Base class for P4 source-updaters
27
28 ['p4port'] (required): host:port for server to access
29 ['p4user'] (optional): user to use for access
30 ['p4passwd'] (optional): passwd to try for the user
31 ['p4client'] (optional): client spec to use
32 """
34 SourceBaseCommand.setup(self, args)
35 self.p4port = args['p4port']
36 self.p4client = args['p4client']
37 self.p4user = args['p4user']
38 self.p4passwd = args['p4passwd']
39
41
42
43 command = ['p4']
44 if self.p4port:
45 command.extend(['-p', self.p4port])
46 if self.p4user:
47 command.extend(['-u', self.p4user])
48 if self.p4passwd:
49 command.extend(['-P', Obfuscated(self.p4passwd, "XXXXXXXX")])
50 if self.p4client:
51 command.extend(['-c', self.p4client])
52
53 command.extend(['changes', '-s', 'submitted', '-m', '1', '#have'])
54 c = runprocess.RunProcess(self.builder, command, self.builder.basedir,
55 environ=self.env, timeout=self.timeout,
56 maxTime=self.maxTime, sendStdout=True,
57 sendRC=False, keepStdout=True,
58 usePTY=False, logEnviron=self.logEnviron)
59 self.command = c
60 d = c.start()
61
62 def _parse(res):
63
64
65
66 m = re.match('Change\s+(\d+)\s+', c.stdout)
67 if m:
68 return m.group(1)
69 return None
70 d.addCallback(_parse)
71 return d
72
73
75 """A P4 source-updater.
76
77 ['p4port'] (required): host:port for server to access
78 ['p4user'] (required): user to use for access
79 ['p4passwd'] (required): passwd to try for the user
80 ['p4client'] (required): client spec to use
81 ['p4extra_views'] (required): additional client views to use
82 ['p4base'] (required): view into the Perforce depot without branch name or trailing "..."
83 ['p4line_end'] (optional): value of the LineEnd client specification property
84 """
85
86 header = "p4"
87
89 P4Base.setup(self, args)
90 self.p4base = args['p4base']
91 self.p4extra_views = args['p4extra_views']
92 self.p4line_end = args.get('p4line_end', None)
93 self.p4mode = args['mode']
94 self.p4branch = args['branch']
95
96
97
98
99 def enc(x):
100 if isinstance(x, unicode):
101 return x.encode('utf8')
102 return x
103 self.sourcedata = str([
104 enc(x) for x in [
105
106 self.p4port,
107
108
109 self.p4client,
110
111
112 self.p4base,
113 self.p4branch,
114 self.p4extra_views,
115 self.p4line_end,
116
117
118 self.builder.basedir,
119 self.mode,
120 self.workdir
121 ]])
122
123
131
133 return self._doP4Sync(force=False)
134
136 command = ['p4']
137
138 if self.p4port:
139 command.extend(['-p', self.p4port])
140 if self.p4user:
141 command.extend(['-u', self.p4user])
142 if self.p4passwd:
143 command.extend(['-P', Obfuscated(self.p4passwd, "XXXXXXXX")])
144 if self.p4client:
145 command.extend(['-c', self.p4client])
146 command.extend(['sync'])
147 if force:
148 command.extend(['-f'])
149 if self.revision:
150 command.extend(['@' + str(self.revision)])
151 env = {}
152 c = runprocess.RunProcess(self.builder, command, self.builder.basedir,
153 environ=env, sendRC=False, timeout=self.timeout,
154 maxTime=self.maxTime, usePTY=False,
155 logEnviron=self.logEnviron)
156 self.command = c
157 d = c.start()
158 d.addCallback(self._abandonOnFailure)
159 return d
160
161
163 env = {}
164 command = ['p4']
165 client_spec = ''
166 client_spec += "Client: %s\n\n" % self.p4client
167 client_spec += "Owner: %s\n\n" % self.p4user
168 client_spec += "Description:\n\tCreated by %s\n\n" % self.p4user
169 client_spec += "Root:\t%s\n\n" % self.builder.basedir
170 client_spec += "Options:\tallwrite rmdir\n\n"
171 if self.p4line_end:
172 client_spec += "LineEnd:\t%s\n\n" % self.p4line_end
173 else:
174 client_spec += "LineEnd:\tlocal\n\n"
175
176
177 client_spec += "View:\n\t%s" % (self.p4base)
178 if self.p4branch:
179 client_spec += "%s/" % (self.p4branch)
180 client_spec += "... //%s/%s/...\n" % (self.p4client, self.srcdir)
181 if self.p4extra_views:
182 for k, v in self.p4extra_views:
183 client_spec += "\t%s/... //%s/%s%s/...\n" % (k, self.p4client,
184 self.srcdir, v)
185 if self.p4port:
186 command.extend(['-p', self.p4port])
187 if self.p4user:
188 command.extend(['-u', self.p4user])
189 if self.p4passwd:
190 command.extend(['-P', Obfuscated(self.p4passwd, "XXXXXXXX")])
191 command.extend(['client', '-i'])
192 log.msg(client_spec)
193
194
195
196
197
198
199
200
201
202
203
204 client_spec=client_spec.encode('ascii','ignore')
205
206 c = runprocess.RunProcess(self.builder, command, self.builder.basedir,
207 environ=env, sendRC=False, timeout=self.timeout,
208 maxTime=self.maxTime, initialStdin=client_spec,
209 usePTY=False, logEnviron=self.logEnviron)
210 self.command = c
211 d = c.start()
212 d.addCallback(self._abandonOnFailure)
213 d.addCallback(lambda _: self._doP4Sync(force=True))
214 return d
215
221
222
224 """A partial P4 source-updater. Requires manual setup of a per-slave P4
225 environment. The only thing which comes from the master is P4PORT.
226 'mode' is required to be 'copy'.
227
228 ['p4port'] (required): host:port for server to access
229 ['p4user'] (optional): user to use for access
230 ['p4passwd'] (optional): passwd to try for the user
231 ['p4client'] (optional): client spec to use
232 """
233
234 header = "p4 sync"
235
238
241
243 d = os.path.join(self.builder.basedir, self.srcdir)
244 command = [self.getCommand('p4')]
245 if self.p4port:
246 command.extend(['-p', self.p4port])
247 if self.p4user:
248 command.extend(['-u', self.p4user])
249 if self.p4passwd:
250 command.extend(['-P', Obfuscated(self.p4passwd, "XXXXXXXX")])
251 if self.p4client:
252 command.extend(['-c', self.p4client])
253 command.extend(['sync'])
254 if force:
255 command.extend(['-f'])
256 if self.revision:
257 command.extend(['@' + self.revision])
258 env = {}
259 c = runprocess.RunProcess(self.builder, command, d, environ=env,
260 sendRC=False, timeout=self.timeout,
261 maxTime=self.maxTime, usePTY=False,
262 logEnviron=self.logEnviron)
263 self.command = c
264 return c.start()
265
267 return self._doVC(force=False)
268
270 return self._doVC(force=True)
271
277