OLD | NEW |
1 # This file is part of Buildbot. Buildbot is free software: you can | 1 # This file is part of Buildbot. Buildbot is free software: you can |
2 # redistribute it and/or modify it under the terms of the GNU General Public | 2 # redistribute it and/or modify it under the terms of the GNU General Public |
3 # License as published by the Free Software Foundation, version 2. | 3 # License as published by the Free Software Foundation, version 2. |
4 # | 4 # |
5 # This program is distributed in the hope that it will be useful, but WITHOUT | 5 # This program is distributed in the hope that it will be useful, but WITHOUT |
6 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 6 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
7 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | 7 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
8 # details. | 8 # details. |
9 # | 9 # |
10 # You should have received a copy of the GNU General Public License along with | 10 # You should have received a copy of the GNU General Public License along with |
11 # this program; if not, write to the Free Software Foundation, Inc., 51 | 11 # this program; if not, write to the Free Software Foundation, Inc., 51 |
12 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 12 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
13 # | 13 # |
14 # Portions Copyright Buildbot Team Members | 14 # Portions Copyright Buildbot Team Members |
15 # Original Copyright (c) 2010 The Chromium Authors. | 15 # Original Copyright (c) 2010 The Chromium Authors. |
16 | 16 |
17 """Simple JSON exporter.""" | 17 """Simple JSON exporter.""" |
18 | 18 |
| 19 import collections |
19 import datetime | 20 import datetime |
20 import os | 21 import os |
21 import re | 22 import re |
22 | 23 |
23 from twisted.internet import defer | 24 from twisted.internet import defer |
24 from twisted.web import html, resource, server | 25 from twisted.web import html, resource, server |
25 | 26 |
26 from buildbot.status.web.base import HtmlResource | 27 from buildbot.status.web.base import HtmlResource |
27 from buildbot.util import json | 28 from buildbot.util import json |
28 | 29 |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 | 629 |
629 def getBuilders(self): | 630 def getBuilders(self): |
630 if self.builders is None: | 631 if self.builders is None: |
631 # Figure out all the builders to which it's attached | 632 # Figure out all the builders to which it's attached |
632 self.builders = [] | 633 self.builders = [] |
633 for builderName in self.status.getBuilderNames(): | 634 for builderName in self.status.getBuilderNames(): |
634 if self.name in self.status.getBuilder(builderName).slavenames: | 635 if self.name in self.status.getBuilder(builderName).slavenames: |
635 self.builders.append(builderName) | 636 self.builders.append(builderName) |
636 return self.builders | 637 return self.builders |
637 | 638 |
| 639 def getSlaveBuildMap(self, buildcache, buildercache): |
| 640 for builderName in self.getBuilders(): |
| 641 if builderName not in buildercache: |
| 642 buildercache.add(builderName) |
| 643 builder_status = self.status.getBuilder(builderName) |
| 644 for i in range(1, builder_status.buildCacheSize - 1): |
| 645 build_status = builder_status.getBuild(-i) |
| 646 if not build_status or not build_status.isFinished(): |
| 647 # If not finished, it will appear in runningBuilds. |
| 648 break |
| 649 slave = buildcache[build_status.getSlavename()] |
| 650 slave.setdefault(builderName, []).append( |
| 651 build_status.getNumber()) |
| 652 return buildcache[self.name] |
| 653 |
638 def asDict(self, request): | 654 def asDict(self, request): |
| 655 if not hasattr(request, 'custom_data'): |
| 656 request.custom_data = {} |
| 657 if 'buildcache' not in request.custom_data: |
| 658 # buildcache is used to cache build information across multiple |
| 659 # invocations of SlaveJsonResource. It should be set to an empty |
| 660 # collections.defaultdict(dict). |
| 661 request.custom_data['buildcache'] = collections.defaultdict(dict) |
| 662 |
| 663 # Tracks which builders have been stored in the buildcache. |
| 664 request.custom_data['buildercache'] = set() |
| 665 |
639 results = self.slave_status.asDict() | 666 results = self.slave_status.asDict() |
640 # Enhance it by adding more informations. | 667 # Enhance it by adding more information. |
641 results['builders'] = {} | 668 results['builders'] = self.getSlaveBuildMap( |
642 for builderName in self.getBuilders(): | 669 request.custom_data['buildcache'], |
643 builds = [] | 670 request.custom_data['buildercache']) |
644 builder_status = self.status.getBuilder(builderName) | |
645 for i in range(1, builder_status.buildCacheSize - 1): | |
646 build_status = builder_status.getBuild(-i) | |
647 if not build_status or not build_status.isFinished(): | |
648 # If not finished, it will appear in runningBuilds. | |
649 break | |
650 if build_status.getSlavename() == self.name: | |
651 builds.append(build_status.getNumber()) | |
652 results['builders'][builderName] = builds | |
653 return results | 671 return results |
654 | 672 |
655 | 673 |
656 class SlavesJsonResource(JsonResource): | 674 class SlavesJsonResource(JsonResource): |
657 help = """List the registered slaves. | 675 help = """List the registered slaves. |
658 """ | 676 """ |
659 pageTitle = 'Slaves' | 677 pageTitle = 'Slaves' |
660 | 678 |
661 def __init__(self, status): | 679 def __init__(self, status): |
662 JsonResource.__init__(self, status) | 680 JsonResource.__init__(self, status) |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 if not builder: | 756 if not builder: |
739 return | 757 return |
740 EXAMPLES = EXAMPLES.replace('<A_BUILDER>', builder.getName()) | 758 EXAMPLES = EXAMPLES.replace('<A_BUILDER>', builder.getName()) |
741 build = builder.getBuild(-1) | 759 build = builder.getBuild(-1) |
742 if build: | 760 if build: |
743 EXAMPLES = EXAMPLES.replace('<A_BUILD>', str(build.getNumber())) | 761 EXAMPLES = EXAMPLES.replace('<A_BUILD>', str(build.getNumber())) |
744 if builder.slavenames: | 762 if builder.slavenames: |
745 EXAMPLES = EXAMPLES.replace('<A_SLAVE>', builder.slavenames[0]) | 763 EXAMPLES = EXAMPLES.replace('<A_SLAVE>', builder.slavenames[0]) |
746 | 764 |
747 # vim: set ts=4 sts=4 sw=4 et: | 765 # vim: set ts=4 sts=4 sw=4 et: |
OLD | NEW |