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 |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 BuilderJsonResource(status, | 407 BuilderJsonResource(status, |
| 408 status.getBuilder(builder_name))) | 408 status.getBuilder(builder_name))) |
| 409 | 409 |
| 410 | 410 |
| 411 class BuilderSlavesJsonResources(JsonResource): | 411 class BuilderSlavesJsonResources(JsonResource): |
| 412 help = """Describe the slaves attached to a single builder. | 412 help = """Describe the slaves attached to a single builder. |
| 413 """ | 413 """ |
| 414 pageTitle = 'BuilderSlaves' | 414 pageTitle = 'BuilderSlaves' |
| 415 | 415 |
| 416 def __init__(self, status, builder_status): | 416 def __init__(self, status, builder_status): |
| 417 buildcache = {} | |
|
Isaac (away)
2013/04/04 21:24:38
Maybe:
self.buildcache = collections.defaultdict(
| |
| 417 JsonResource.__init__(self, status) | 418 JsonResource.__init__(self, status) |
| 418 self.builder_status = builder_status | 419 self.builder_status = builder_status |
| 419 for slave_name in self.builder_status.slavenames: | 420 for slave_name in self.builder_status.slavenames: |
| 420 self.putChild(slave_name, | 421 self.putChild(slave_name, |
| 421 SlaveJsonResource(status, | 422 SlaveJsonResource(status, |
| 422 self.status.getSlave(slave_name))) | 423 self.status.getSlave(slave_name), |
| 424 buildcache=buildcache)) | |
|
Isaac (away)
2013/04/04 21:24:38
buildcache=self.buildcache
Mike Stip (use stip instead)
2013/04/05 23:35:04
It's probably not a good idea to persist this cach
| |
| 423 | 425 |
| 424 | 426 |
| 425 class BuildJsonResource(JsonResource): | 427 class BuildJsonResource(JsonResource): |
| 426 help = """Describe a single build. | 428 help = """Describe a single build. |
| 427 """ | 429 """ |
| 428 pageTitle = 'Build' | 430 pageTitle = 'Build' |
| 429 | 431 |
| 430 def __init__(self, status, build_status): | 432 def __init__(self, status, build_status): |
| 431 JsonResource.__init__(self, status) | 433 JsonResource.__init__(self, status) |
| 432 self.build_status = build_status | 434 self.build_status = build_status |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 613 | 615 |
| 614 def asDict(self, request): | 616 def asDict(self, request): |
| 615 return self.status.asDict() | 617 return self.status.asDict() |
| 616 | 618 |
| 617 | 619 |
| 618 class SlaveJsonResource(JsonResource): | 620 class SlaveJsonResource(JsonResource): |
| 619 help = """Describe a slave. | 621 help = """Describe a slave. |
| 620 """ | 622 """ |
| 621 pageTitle = 'Slave' | 623 pageTitle = 'Slave' |
| 622 | 624 |
| 623 def __init__(self, status, slave_status): | 625 def __init__(self, status, slave_status, buildcache=None): |
|
Isaac (away)
2013/04/04 21:24:38
why optional?
Mike Stip (use stip instead)
2013/04/05 23:35:04
It's only needed if you are repeatedly creating Sl
Isaac (away)
2013/04/05 23:45:01
As far as I can tell, the only clients are in this
| |
| 624 JsonResource.__init__(self, status) | 626 JsonResource.__init__(self, status) |
| 625 self.slave_status = slave_status | 627 self.slave_status = slave_status |
| 626 self.name = self.slave_status.getName() | 628 self.name = self.slave_status.getName() |
| 627 self.builders = None | 629 self.builders = None |
| 628 | 630 |
| 631 # buildcache is used to cache build information across multiple | |
| 632 # invoations of SlaveJsonResource. It should be set to an empty {}. | |
| 633 # Without it, each invocation will do a full build scan. | |
| 634 self.buildcache = buildcache | |
| 635 | |
| 629 def getBuilders(self): | 636 def getBuilders(self): |
| 630 if self.builders is None: | 637 if self.builders is None: |
| 631 # Figure out all the builders to which it's attached | 638 # Figure out all the builders to which it's attached |
| 632 self.builders = [] | 639 self.builders = [] |
| 633 for builderName in self.status.getBuilderNames(): | 640 for builderName in self.status.getBuilderNames(): |
| 634 if self.name in self.status.getBuilder(builderName).slavenames: | 641 if self.name in self.status.getBuilder(builderName).slavenames: |
| 635 self.builders.append(builderName) | 642 self.builders.append(builderName) |
| 636 return self.builders | 643 return self.builders |
| 637 | 644 |
| 638 def asDict(self, request): | 645 def mapSlavesToBuilds(self): |
|
Isaac (away)
2013/04/04 21:24:38
I think this would be cleaner if it buildcache[sel
Mike Stip (use stip instead)
2013/04/05 23:35:04
The scan works by creating all slaves at once, so
| |
| 639 results = self.slave_status.asDict() | 646 if self.buildcache: |
| 640 # Enhance it by adding more informations. | 647 return |
| 641 results['builders'] = {} | 648 self.buildcache = {} |
|
Isaac (away)
2013/04/04 21:24:38
646-648 can be removed if param not optional.
| |
| 642 for builderName in self.getBuilders(): | 649 for builderName in self.getBuilders(): |
| 643 builds = [] | 650 builds = [] |
| 644 builder_status = self.status.getBuilder(builderName) | 651 builder_status = self.status.getBuilder(builderName) |
| 645 for i in range(1, builder_status.buildCacheSize - 1): | 652 for i in range(1, builder_status.buildCacheSize - 1): |
| 646 build_status = builder_status.getBuild(-i) | 653 build_status = builder_status.getBuild(-i) |
| 647 if not build_status or not build_status.isFinished(): | 654 if not build_status or not build_status.isFinished(): |
| 648 # If not finished, it will appear in runningBuilds. | 655 # If not finished, it will appear in runningBuilds. |
| 649 break | 656 break |
| 650 if build_status.getSlavename() == self.name: | 657 slave = self.buildcache.get(build_status.getSlavename(), {}) |
|
Isaac (away)
2013/04/04 21:24:38
if buildcache is defaultdict. 657-660 become:
sla
| |
| 651 builds.append(build_status.getNumber()) | 658 self.buildcache[build_status.getSlavename()] = slave |
| 652 results['builders'][builderName] = builds | 659 slave[builderName] = slave.get(builderName, []) |
| 660 slave[builderName].append(build_status.getNumber()) | |
| 661 | |
|
Isaac (away)
2013/04/04 21:24:38
return self.buildcache[self.name]
| |
| 662 def asDict(self, request): | |
| 663 results = self.slave_status.asDict() | |
| 664 # Enhance it by adding more informations. | |
| 665 self.mapSlavesToBuilds() | |
| 666 results['builders'] = self.buildcache.get(self.name, {}) | |
|
Isaac (away)
2013/04/04 21:24:38
results['builders'] = getSlavesToBuildMap()
| |
| 653 return results | 667 return results |
| 654 | 668 |
| 655 | 669 |
| 656 class SlavesJsonResource(JsonResource): | 670 class SlavesJsonResource(JsonResource): |
| 657 help = """List the registered slaves. | 671 help = """List the registered slaves. |
| 658 """ | 672 """ |
| 659 pageTitle = 'Slaves' | 673 pageTitle = 'Slaves' |
| 660 | 674 |
| 661 def __init__(self, status): | 675 def __init__(self, status): |
| 676 buildcache = {} | |
|
Isaac (away)
2013/04/04 21:24:38
Maybe self.buildcache = collections.defaultdict(di
Mike Stip (use stip instead)
2013/04/05 23:35:04
Done.
| |
| 662 JsonResource.__init__(self, status) | 677 JsonResource.__init__(self, status) |
| 663 for slave_name in status.getSlaveNames(): | 678 for slave_name in status.getSlaveNames(): |
| 664 self.putChild(slave_name, | 679 self.putChild(slave_name, |
| 665 SlaveJsonResource(status, | 680 SlaveJsonResource(status, |
| 666 status.getSlave(slave_name))) | 681 status.getSlave(slave_name), |
| 682 buildcache=buildcache)) | |
|
Isaac (away)
2013/04/04 21:24:38
self.buildcache
| |
| 667 | 683 |
| 668 | 684 |
| 669 class SourceStampJsonResource(JsonResource): | 685 class SourceStampJsonResource(JsonResource): |
| 670 help = """Describe the sources for a SourceStamp. | 686 help = """Describe the sources for a SourceStamp. |
| 671 """ | 687 """ |
| 672 pageTitle = 'SourceStamp' | 688 pageTitle = 'SourceStamp' |
| 673 | 689 |
| 674 def __init__(self, status, source_stamp): | 690 def __init__(self, status, source_stamp): |
| 675 # buildbot.sourcestamp.SourceStamp | 691 # buildbot.sourcestamp.SourceStamp |
| 676 JsonResource.__init__(self, status) | 692 JsonResource.__init__(self, status) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 738 if not builder: | 754 if not builder: |
| 739 return | 755 return |
| 740 EXAMPLES = EXAMPLES.replace('<A_BUILDER>', builder.getName()) | 756 EXAMPLES = EXAMPLES.replace('<A_BUILDER>', builder.getName()) |
| 741 build = builder.getBuild(-1) | 757 build = builder.getBuild(-1) |
| 742 if build: | 758 if build: |
| 743 EXAMPLES = EXAMPLES.replace('<A_BUILD>', str(build.getNumber())) | 759 EXAMPLES = EXAMPLES.replace('<A_BUILD>', str(build.getNumber())) |
| 744 if builder.slavenames: | 760 if builder.slavenames: |
| 745 EXAMPLES = EXAMPLES.replace('<A_SLAVE>', builder.slavenames[0]) | 761 EXAMPLES = EXAMPLES.replace('<A_SLAVE>', builder.slavenames[0]) |
| 746 | 762 |
| 747 # vim: set ts=4 sts=4 sw=4 et: | 763 # vim: set ts=4 sts=4 sw=4 et: |
| OLD | NEW |