Chromium Code Reviews| Index: third_party/buildbot_8_4p1/buildbot/status/web/status_json.py |
| diff --git a/third_party/buildbot_8_4p1/buildbot/status/web/status_json.py b/third_party/buildbot_8_4p1/buildbot/status/web/status_json.py |
| index b656563257e3b0dbe89ca0e3fe26b330c1e7d99b..9ece8200b2460f06c69abff339a8497753e4e05e 100644 |
| --- a/third_party/buildbot_8_4p1/buildbot/status/web/status_json.py |
| +++ b/third_party/buildbot_8_4p1/buildbot/status/web/status_json.py |
| @@ -16,6 +16,7 @@ |
| """Simple JSON exporter.""" |
| +import collections |
| import datetime |
| import os |
| import re |
| @@ -414,12 +415,14 @@ class BuilderSlavesJsonResources(JsonResource): |
| pageTitle = 'BuilderSlaves' |
| def __init__(self, status, builder_status): |
| + buildcache = collections.defaultdict(dict) |
| JsonResource.__init__(self, status) |
| self.builder_status = builder_status |
| for slave_name in self.builder_status.slavenames: |
| self.putChild(slave_name, |
| SlaveJsonResource(status, |
| - self.status.getSlave(slave_name))) |
| + self.status.getSlave(slave_name), |
| + buildcache=buildcache)) |
| class BuildJsonResource(JsonResource): |
| @@ -620,12 +623,17 @@ class SlaveJsonResource(JsonResource): |
| """ |
| pageTitle = 'Slave' |
| - def __init__(self, status, slave_status): |
| + def __init__(self, status, slave_status, buildcache): |
| JsonResource.__init__(self, status) |
| self.slave_status = slave_status |
| self.name = self.slave_status.getName() |
| self.builders = None |
| + # buildcache is used to cache build information across multiple |
| + # invocations of SlaveJsonResource. It should be set to an empty |
| + # collections.defaultdict(dict). |
| + self.buildcache = buildcache |
| + |
| def getBuilders(self): |
| if self.builders is None: |
| # Figure out all the builders to which it's attached |
| @@ -635,21 +643,24 @@ class SlaveJsonResource(JsonResource): |
| self.builders.append(builderName) |
| return self.builders |
| + def getSlaveBuildMap(self): |
| + if not self.buildcache: |
| + for builderName in self.getBuilders(): |
|
iannucci
2013/06/28 23:25:53
So the code inside the if statement will be execut
|
| + builder_status = self.status.getBuilder(builderName) |
| + for i in range(1, builder_status.buildCacheSize - 1): |
| + build_status = builder_status.getBuild(-i) |
| + if not build_status or not build_status.isFinished(): |
| + # If not finished, it will appear in runningBuilds. |
| + break |
| + slave = self.buildcache[build_status.getSlavename()] |
| + slave.setdefault(builderName, []).append( |
| + build_status.getNumber()) |
| + return self.buildcache[self.name] |
| + |
| def asDict(self, request): |
| results = self.slave_status.asDict() |
| # Enhance it by adding more informations. |
| - results['builders'] = {} |
| - for builderName in self.getBuilders(): |
| - builds = [] |
| - builder_status = self.status.getBuilder(builderName) |
| - for i in range(1, builder_status.buildCacheSize - 1): |
| - build_status = builder_status.getBuild(-i) |
| - if not build_status or not build_status.isFinished(): |
| - # If not finished, it will appear in runningBuilds. |
| - break |
| - if build_status.getSlavename() == self.name: |
| - builds.append(build_status.getNumber()) |
| - results['builders'][builderName] = builds |
| + results['builders'] = self.getSlaveBuildMap() |
| return results |
| @@ -659,11 +670,13 @@ class SlavesJsonResource(JsonResource): |
| pageTitle = 'Slaves' |
| def __init__(self, status): |
| + buildcache = collections.defaultdict(dict) |
| JsonResource.__init__(self, status) |
| for slave_name in status.getSlaveNames(): |
| self.putChild(slave_name, |
| SlaveJsonResource(status, |
| - status.getSlave(slave_name))) |
| + status.getSlave(slave_name), |
| + buildcache=buildcache)) |
| class SourceStampJsonResource(JsonResource): |