1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 import os.path
39
40 from zope.interface import implements
41 from twisted.application import strports
42 from twisted.python import log, runtime
43 from twisted.protocols import basic
44 from twisted.cred import portal, checkers
45 from twisted.spread import pb
46
47 from buildbot import pbutil
48 from buildbot.sourcestamp import SourceStamp
49 from buildbot.changes.maildir import MaildirService
50 from buildbot.process.properties import Properties
51 from buildbot.schedulers import base
52 from buildbot.status.builder import BuildSetStatus
53
54
56
60
62
63
64
65
66 if builderNames:
67 for b in builderNames:
68 if not b in self.builderNames:
69 log.msg("%s got with builder %s" % (self, b))
70 log.msg(" but that wasn't in our list: %s"
71 % (self.builderNames,))
72 return []
73 else:
74 builderNames = self.builderNames
75 return builderNames
76
79
82 self.strings = []
83 self.transport = self
84 self.error = False
85
87 self.strings.append(s)
88
91
93 compare_attrs = ( 'name', 'builderNames', 'jobdir', 'properties' )
94
95 - def __init__(self, name, builderNames, jobdir,
96 properties={}):
101
107
109
110
111
112
113
114
115
116
117
118 p = JobFileScanner()
119 p.dataReceived(f.read())
120 if p.error:
121 raise BadJobfile("unable to parse netstrings")
122 s = p.strings
123 ver = s.pop(0)
124 if ver == "1":
125 buildsetID, branch, baserev, patchlevel, diff = s[:5]
126 builderNames = s[5:]
127 if branch == "":
128 branch = None
129 if baserev == "":
130 baserev = None
131 patchlevel = int(patchlevel)
132 patch = (patchlevel, diff)
133 ss = SourceStamp("Old client", branch, baserev, patch)
134 elif ver == "2":
135 buildsetID, branch, baserev, patchlevel, diff, repository, project = s[:7]
136 builderNames = s[7:]
137 if branch == "":
138 branch = None
139 if baserev == "":
140 baserev = None
141 patchlevel = int(patchlevel)
142 patch = (patchlevel, diff)
143 ss = SourceStamp(branch, baserev, patch, repository=repository,
144 project=project)
145 else:
146 raise BadJobfile("unknown version '%s'" % ver)
147 return builderNames, ss, buildsetID
148
150 md = os.path.join(self.parent.parent.basedir, self.jobdir)
151 if runtime.platformType == "posix":
152
153
154 path = os.path.join(md, "new", filename)
155 f = open(path, "r")
156 os.rename(os.path.join(md, "new", filename),
157 os.path.join(md, "cur", filename))
158 else:
159
160
161
162 os.rename(os.path.join(md, "new", filename),
163 os.path.join(md, "cur", filename))
164 path = os.path.join(md, "cur", filename)
165 f = open(path, "r")
166
167 try:
168 builderNames, ss, jobid = self.parseJob(f)
169 except BadJobfile:
170 log.msg("%s reports a bad jobfile in %s" % (self, filename))
171 log.err()
172 return
173
174 builderNames = self.filterBuilderList(builderNames)
175 if not builderNames:
176 return
177 reason = "'try' job"
178 d = self.parent.db.runInteraction(self._try, ss, builderNames, reason)
179 def _done(ign):
180 self.parent.loop_done()
181 d.addCallback(_done)
182 return d
183
184 - def _try(self, t, ss, builderNames, reason):
189
191 compare_attrs = ( 'name', 'builderNames', 'port', 'userpass', 'properties' )
192 implements(portal.IRealm)
193
194 - def __init__(self, name, builderNames, port, userpass,
195 properties={}):
196 base.BaseScheduler.__init__(self, name, builderNames, properties)
197 if type(port) is int:
198 port = "tcp:%d" % port
199 self.port = port
200 self.userpass = userpass
201 c = checkers.InMemoryUsernamePasswordDatabaseDontUse()
202 for user,passwd in self.userpass:
203 c.addUser(user, passwd)
204
205 p = portal.Portal(self)
206 p.registerChecker(c)
207 f = pb.PBServerFactory(p)
208 s = strports.service(port, f)
209 s.setServiceParent(self)
210
212
213 return self.services[0]._port.getHost().port
214
216 log.msg("%s got connection from user %s" % (self, avatarID))
217 assert interface == pb.IPerspective
218 p = Try_Userpass_Perspective(self, avatarID)
219 return (pb.IPerspective, p, lambda: None)
220
225
226 - def perspective_try(self, branch, revision, patch, repository, project,
227 builderNames, properties={}, ):
228 log.msg("user %s requesting build on builders %s" % (self.username,
229 builderNames))
230
231 builderNames = self.parent.filterBuilderList(builderNames)
232 if not builderNames:
233 return
234 ss = SourceStamp(branch, revision, patch, repository=repository,
235 project=project)
236 reason = "'try' job from user %s" % self.username
237
238
239 combined_props = Properties()
240 combined_props.updateFromProperties(self.parent.properties)
241 combined_props.update(properties, "try build")
242
243 status = self.parent.parent.parent.status
244 db = self.parent.parent.db
245 d = db.runInteraction(self._try, ss, builderNames, reason,
246 combined_props, db)
247 def _done(bsid):
248
249 bss = BuildSetStatus(bsid, status, db)
250 from buildbot.status.client import makeRemote
251 r = makeRemote(bss)
252
253 return r
254 d.addCallback(_done)
255 return d
256
257 - def _try(self, t, ss, builderNames, reason, combined_props, db):
263
270