~ubuntu-branches/ubuntu/trusty/buildbot/trusty-proposed

« back to all changes in this revision

Viewing changes to buildbot/status/web/grid.py

  • Committer: Package Import Robot
  • Author(s): Andriy Senkovych
  • Date: 2013-10-10 13:22:47 UTC
  • mfrom: (1.2.10)
  • Revision ID: package-import@ubuntu.com-20131010132247-m622rpa3yemt62te
Tags: 0.8.8-1
* New upstream release
* Remove text-client.patch (applied upstream)
* Add bash-completion. Thanks to Elmir Jagudin
* debian/control: add Vcs-* fields

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
 
88
88
        defer.returnValue(cxt)
89
89
 
90
 
    def getSourceStampKey(self, ss):
 
90
    def getSourceStampKey(self, sourcestamps):
91
91
        """Given two source stamps, we want to assign them to the same row if
92
92
        they are the same version of code, even if they differ in minor detail.
93
93
 
94
94
        This function returns an appropriate comparison key for that.
95
95
        """
96
 
        return (ss.branch, ss.revision, ss.patch)
 
96
        # TODO: Maybe order sourcestamps in key by codebases names?
 
97
        return tuple([(ss.branch, ss.revision, ss.patch) for ss in sourcestamps])
 
98
 
 
99
    def clearRecentBuildsCache(self):
 
100
        self.__recentBuildsCache__ = {}
97
101
 
98
102
    def getRecentBuilds(self, builder, numBuilds, branch):
 
103
        cache = getattr(self, '__recentBuildsCache__', {})
 
104
        key = (builder.getName(), branch, numBuilds)
 
105
        try:
 
106
            return cache[key]
 
107
        except KeyError:
 
108
            # cache miss, get the value and store it in the cache
 
109
            result = [b for b in self.__getRecentBuilds(builder, numBuilds, branch)]
 
110
            cache[key] = result
 
111
            return result
 
112
 
 
113
    def __getRecentBuilds(self, builder, numBuilds, branch):
99
114
        """
100
115
        get a list of most recent builds on given builder
101
116
        """
135
150
            if categories and builder.category not in categories:
136
151
                continue
137
152
            for build in self.getRecentBuilds(builder, numBuilds, branch):
138
 
                #TODO: support multiple sourcestamps
139
 
                ss = build.getSourceStamps(absolute=True)[0]
140
 
                key= self.getSourceStampKey(ss)
141
 
                start = build.getTimes()[0]
 
153
                ss = build.getSourceStamps(absolute=True)
 
154
                key = self.getSourceStampKey(ss)
 
155
                start = min(build.getTimes())
142
156
                if key not in sourcestamps or sourcestamps[key][1] > start:
143
157
                    sourcestamps[key] = (ss, start)
144
158
 
145
159
        # now sort those and take the NUMBUILDS most recent
146
 
        sourcestamps = sourcestamps.values()
147
 
        sourcestamps.sort(lambda x, y: cmp(x[1], y[1]))
148
 
        sourcestamps = map(lambda tup : tup[0], sourcestamps)
149
 
        sourcestamps = sourcestamps[-numBuilds:]
 
160
        sourcestamps = sorted(sourcestamps.itervalues(), key = lambda stamp: stamp[1])
 
161
        sourcestamps = [stamp[0] for stamp in sourcestamps][-numBuilds:]
150
162
 
151
163
        return sourcestamps
152
164
 
176
188
        cxt.update({'categories': categories,
177
189
                    'branch': branch,
178
190
                    'ANYBRANCH': ANYBRANCH,
179
 
                    'stamps': map(SourceStamp.asDict, stamps)
 
191
                    'stamps': [map(SourceStamp.asDict, sstamp) for sstamp in stamps],
180
192
                   })
181
193
        
182
 
        sortedBuilderNames = status.getBuilderNames()[:]
183
 
        sortedBuilderNames.sort()
 
194
        sortedBuilderNames = sorted(status.getBuilderNames())
184
195
        
185
196
        cxt['builders'] = []
186
197
 
192
203
                continue
193
204
 
194
205
            for build in self.getRecentBuilds(builder, numBuilds, branch):
195
 
                #TODO: support multiple sourcestamps
196
 
                if len(build.getSourceStamps()) == 1:
197
 
                    ss = build.getSourceStamps(absolute=True)[0]
198
 
                    key= self.getSourceStampKey(ss)
199
 
                    for i in range(len(stamps)):
200
 
                        if key == self.getSourceStampKey(stamps[i]) and builds[i] is None:
201
 
                            builds[i] = build
 
206
                ss = build.getSourceStamps(absolute=True)
 
207
                key = self.getSourceStampKey(ss)
 
208
 
 
209
                for i, sstamp in enumerate(stamps):
 
210
                    if key == self.getSourceStampKey(sstamp) and builds[i] is None:
 
211
                        builds[i] = build
202
212
 
203
213
            b = yield self.builder_cxt(request, builder)
204
214
 
208
218
 
209
219
            cxt['builders'].append(b)
210
220
 
 
221
        self.clearRecentBuildsCache()
211
222
        template = request.site.buildbot_service.templates.get_template("grid.html")
212
223
        defer.returnValue(template.render(**cxt))
213
224
 
243
254
        cxt.update({'categories': categories,
244
255
                    'branch': branch,
245
256
                    'ANYBRANCH': ANYBRANCH,
246
 
                    'stamps': map(SourceStamp.asDict, stamps),
 
257
                    'stamps': [map(SourceStamp.asDict, sstamp) for sstamp in stamps],
247
258
                    })
248
259
 
249
 
        sortedBuilderNames = status.getBuilderNames()[:]
250
 
        sortedBuilderNames.sort()
 
260
        sortedBuilderNames = sorted(status.getBuilderNames())
251
261
        
252
262
        cxt['sorted_builder_names'] = sortedBuilderNames
253
263
        cxt['builder_builds'] = builder_builds = []
265
275
 
266
276
            for build in self.getRecentBuilds(builder, numBuilds, branch):
267
277
                #TODO: support multiple sourcestamps
268
 
                if len(build.getSourceStamps()) == 1:
269
 
                    ss = build.getSourceStamps(absolute=True)[0]
270
 
                    key = self.getSourceStampKey(ss)
271
 
                    for i in range(len(stamps)):
272
 
                        if key == self.getSourceStampKey(stamps[i]) and builds[i] is None:
273
 
                            builds[i] = build
 
278
                ss = build.getSourceStamps(absolute=True)
 
279
                key = self.getSourceStampKey(ss)
 
280
 
 
281
                for i, sstamp in enumerate(stamps):
 
282
                    if key == self.getSourceStampKey(sstamp) and builds[i] is None:
 
283
                        builds[i] = build
274
284
 
275
285
            b = yield self.builder_cxt(request, builder)
276
286
            builders.append(b)
277
287
 
278
288
            builder_builds.append(map(lambda b: self.build_cxt(request, b), builds))
279
289
 
 
290
        self.clearRecentBuildsCache()
280
291
        template = request.site.buildbot_service.templates.get_template('grid_transposed.html')
281
 
        defer.returnValue(template.render(**cxt))
 
 
b'\\ No newline at end of file'
 
292
        defer.returnValue(template.render(**cxt))