Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: third_party/buildbot_8_4p1/buildbot/status/web/status_json.py

Issue 13619004: Only calculate slave->build mapping once in json output. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Added readme.chromium changes. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 # This builder hasn't been processed in this request yet.
iannucci 2013/06/30 08:16:16 obvious comment is obvious? :)
643 buildercache.add(builderName)
644 builder_status = self.status.getBuilder(builderName)
645 for i in range(1, builder_status.buildCacheSize - 1):
646 build_status = builder_status.getBuild(-i)
iannucci 2013/06/30 08:16:16 This loop construction looks ugly, but I'm assumin
647 if not build_status or not build_status.isFinished():
648 # If not finished, it will appear in runningBuilds.
649 break
650 slave = buildcache[build_status.getSlavename()]
iannucci 2013/06/30 08:16:16 how is slavename guaranteed to exist in buildcache
Mike Stip (use stip instead) 2013/06/30 08:29:54 collections.defaultdict(dict)
651 slave.setdefault(builderName, []).append(
652 build_status.getNumber())
653 return buildcache[self.name]
654
638 def asDict(self, request): 655 def asDict(self, request):
656 if not hasattr(request, 'requestdata'):
657 request.requestdata = {}
658 if 'buildcache' not in request.requestdata:
659 # buildcache is used to cache build information across multiple
660 # invocations of SlaveJsonResource. It should be set to an empty
661 # collections.defaultdict(dict).
662 request.requestdata['buildcache'] = collections.defaultdict(dict)
663
664 # Tracks which builders have been stored in the buildcache.
665 request.requestdata['buildercache'] = set()
666
iannucci 2013/06/30 08:16:16 I think this whole block could be: if not hasattr
Mike Stip (use stip instead) 2013/06/30 08:29:54 twisted doesn't seem to have a place to stash appl
639 results = self.slave_status.asDict() 667 results = self.slave_status.asDict()
640 # Enhance it by adding more informations. 668 # Enhance it by adding more informations.
iannucci 2013/06/30 08:16:16 depluaralize information while you're at it :)
641 results['builders'] = {} 669 results['builders'] = self.getSlaveBuildMap(
642 for builderName in self.getBuilders(): 670 request.requestdata['buildcache'],
643 builds = [] 671 request.requestdata['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 672 return results
654 673
655 674
656 class SlavesJsonResource(JsonResource): 675 class SlavesJsonResource(JsonResource):
657 help = """List the registered slaves. 676 help = """List the registered slaves.
658 """ 677 """
659 pageTitle = 'Slaves' 678 pageTitle = 'Slaves'
660 679
661 def __init__(self, status): 680 def __init__(self, status):
662 JsonResource.__init__(self, status) 681 JsonResource.__init__(self, status)
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 if not builder: 757 if not builder:
739 return 758 return
740 EXAMPLES = EXAMPLES.replace('<A_BUILDER>', builder.getName()) 759 EXAMPLES = EXAMPLES.replace('<A_BUILDER>', builder.getName())
741 build = builder.getBuild(-1) 760 build = builder.getBuild(-1)
742 if build: 761 if build:
743 EXAMPLES = EXAMPLES.replace('<A_BUILD>', str(build.getNumber())) 762 EXAMPLES = EXAMPLES.replace('<A_BUILD>', str(build.getNumber()))
744 if builder.slavenames: 763 if builder.slavenames:
745 EXAMPLES = EXAMPLES.replace('<A_SLAVE>', builder.slavenames[0]) 764 EXAMPLES = EXAMPLES.replace('<A_SLAVE>', builder.slavenames[0])
746 765
747 # vim: set ts=4 sts=4 sw=4 et: 766 # vim: set ts=4 sts=4 sw=4 et:
OLDNEW
« third_party/buildbot_8_4p1/README.chromium ('K') | « third_party/buildbot_8_4p1/README.chromium ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698