Chromium Code Reviews| 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 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 BuilderJsonResource(status, | 408 BuilderJsonResource(status, |
| 408 status.getBuilder(builder_name))) | 409 status.getBuilder(builder_name))) |
| 409 | 410 |
| 410 | 411 |
| 411 class BuilderSlavesJsonResources(JsonResource): | 412 class BuilderSlavesJsonResources(JsonResource): |
| 412 help = """Describe the slaves attached to a single builder. | 413 help = """Describe the slaves attached to a single builder. |
| 413 """ | 414 """ |
| 414 pageTitle = 'BuilderSlaves' | 415 pageTitle = 'BuilderSlaves' |
| 415 | 416 |
| 416 def __init__(self, status, builder_status): | 417 def __init__(self, status, builder_status): |
| 418 buildcache = collections.defaultdict(dict) | |
| 417 JsonResource.__init__(self, status) | 419 JsonResource.__init__(self, status) |
| 418 self.builder_status = builder_status | 420 self.builder_status = builder_status |
| 419 for slave_name in self.builder_status.slavenames: | 421 for slave_name in self.builder_status.slavenames: |
| 420 self.putChild(slave_name, | 422 self.putChild(slave_name, |
| 421 SlaveJsonResource(status, | 423 SlaveJsonResource(status, |
| 422 self.status.getSlave(slave_name))) | 424 self.status.getSlave(slave_name), |
| 425 buildcache=buildcache)) | |
| 423 | 426 |
| 424 | 427 |
| 425 class BuildJsonResource(JsonResource): | 428 class BuildJsonResource(JsonResource): |
| 426 help = """Describe a single build. | 429 help = """Describe a single build. |
| 427 """ | 430 """ |
| 428 pageTitle = 'Build' | 431 pageTitle = 'Build' |
| 429 | 432 |
| 430 def __init__(self, status, build_status): | 433 def __init__(self, status, build_status): |
| 431 JsonResource.__init__(self, status) | 434 JsonResource.__init__(self, status) |
| 432 self.build_status = build_status | 435 self.build_status = build_status |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 613 | 616 |
| 614 def asDict(self, request): | 617 def asDict(self, request): |
| 615 return self.status.asDict() | 618 return self.status.asDict() |
| 616 | 619 |
| 617 | 620 |
| 618 class SlaveJsonResource(JsonResource): | 621 class SlaveJsonResource(JsonResource): |
| 619 help = """Describe a slave. | 622 help = """Describe a slave. |
| 620 """ | 623 """ |
| 621 pageTitle = 'Slave' | 624 pageTitle = 'Slave' |
| 622 | 625 |
| 623 def __init__(self, status, slave_status): | 626 def __init__(self, status, slave_status, buildcache): |
| 624 JsonResource.__init__(self, status) | 627 JsonResource.__init__(self, status) |
| 625 self.slave_status = slave_status | 628 self.slave_status = slave_status |
| 626 self.name = self.slave_status.getName() | 629 self.name = self.slave_status.getName() |
| 627 self.builders = None | 630 self.builders = None |
| 628 | 631 |
| 632 # buildcache is used to cache build information across multiple | |
| 633 # invocations of SlaveJsonResource. It should be set to an empty | |
| 634 # collections.defaultdict(dict). | |
| 635 self.buildcache = buildcache | |
| 636 | |
| 629 def getBuilders(self): | 637 def getBuilders(self): |
| 630 if self.builders is None: | 638 if self.builders is None: |
| 631 # Figure out all the builders to which it's attached | 639 # Figure out all the builders to which it's attached |
| 632 self.builders = [] | 640 self.builders = [] |
| 633 for builderName in self.status.getBuilderNames(): | 641 for builderName in self.status.getBuilderNames(): |
| 634 if self.name in self.status.getBuilder(builderName).slavenames: | 642 if self.name in self.status.getBuilder(builderName).slavenames: |
| 635 self.builders.append(builderName) | 643 self.builders.append(builderName) |
| 636 return self.builders | 644 return self.builders |
| 637 | 645 |
| 646 def getSlaveBuildMap(self): | |
| 647 if not self.buildcache: | |
| 648 for builderName in self.getBuilders(): | |
|
iannucci
2013/06/28 23:25:53
So the code inside the if statement will be execut
| |
| 649 builder_status = self.status.getBuilder(builderName) | |
| 650 for i in range(1, builder_status.buildCacheSize - 1): | |
| 651 build_status = builder_status.getBuild(-i) | |
| 652 if not build_status or not build_status.isFinished(): | |
| 653 # If not finished, it will appear in runningBuilds. | |
| 654 break | |
| 655 slave = self.buildcache[build_status.getSlavename()] | |
| 656 slave.setdefault(builderName, []).append( | |
| 657 build_status.getNumber()) | |
| 658 return self.buildcache[self.name] | |
| 659 | |
| 638 def asDict(self, request): | 660 def asDict(self, request): |
| 639 results = self.slave_status.asDict() | 661 results = self.slave_status.asDict() |
| 640 # Enhance it by adding more informations. | 662 # Enhance it by adding more informations. |
| 641 results['builders'] = {} | 663 results['builders'] = self.getSlaveBuildMap() |
| 642 for builderName in self.getBuilders(): | |
| 643 builds = [] | |
| 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 | 664 return results |
| 654 | 665 |
| 655 | 666 |
| 656 class SlavesJsonResource(JsonResource): | 667 class SlavesJsonResource(JsonResource): |
| 657 help = """List the registered slaves. | 668 help = """List the registered slaves. |
| 658 """ | 669 """ |
| 659 pageTitle = 'Slaves' | 670 pageTitle = 'Slaves' |
| 660 | 671 |
| 661 def __init__(self, status): | 672 def __init__(self, status): |
| 673 buildcache = collections.defaultdict(dict) | |
| 662 JsonResource.__init__(self, status) | 674 JsonResource.__init__(self, status) |
| 663 for slave_name in status.getSlaveNames(): | 675 for slave_name in status.getSlaveNames(): |
| 664 self.putChild(slave_name, | 676 self.putChild(slave_name, |
| 665 SlaveJsonResource(status, | 677 SlaveJsonResource(status, |
| 666 status.getSlave(slave_name))) | 678 status.getSlave(slave_name), |
| 679 buildcache=buildcache)) | |
| 667 | 680 |
| 668 | 681 |
| 669 class SourceStampJsonResource(JsonResource): | 682 class SourceStampJsonResource(JsonResource): |
| 670 help = """Describe the sources for a SourceStamp. | 683 help = """Describe the sources for a SourceStamp. |
| 671 """ | 684 """ |
| 672 pageTitle = 'SourceStamp' | 685 pageTitle = 'SourceStamp' |
| 673 | 686 |
| 674 def __init__(self, status, source_stamp): | 687 def __init__(self, status, source_stamp): |
| 675 # buildbot.sourcestamp.SourceStamp | 688 # buildbot.sourcestamp.SourceStamp |
| 676 JsonResource.__init__(self, status) | 689 JsonResource.__init__(self, status) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 738 if not builder: | 751 if not builder: |
| 739 return | 752 return |
| 740 EXAMPLES = EXAMPLES.replace('<A_BUILDER>', builder.getName()) | 753 EXAMPLES = EXAMPLES.replace('<A_BUILDER>', builder.getName()) |
| 741 build = builder.getBuild(-1) | 754 build = builder.getBuild(-1) |
| 742 if build: | 755 if build: |
| 743 EXAMPLES = EXAMPLES.replace('<A_BUILD>', str(build.getNumber())) | 756 EXAMPLES = EXAMPLES.replace('<A_BUILD>', str(build.getNumber())) |
| 744 if builder.slavenames: | 757 if builder.slavenames: |
| 745 EXAMPLES = EXAMPLES.replace('<A_SLAVE>', builder.slavenames[0]) | 758 EXAMPLES = EXAMPLES.replace('<A_SLAVE>', builder.slavenames[0]) |
| 746 | 759 |
| 747 # vim: set ts=4 sts=4 sw=4 et: | 760 # vim: set ts=4 sts=4 sw=4 et: |
| OLD | NEW |