#!/usr/bin/env python # Copyright (C) 2011 Google Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following disclaimer # in the documentation and/or other materials provided with the # distribution. # * Neither the name of Google Inc. nor the names of its # contributors may be used to endorse or promote products derived from # this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import webapp2 from google.appengine.api import memcache import json from models import Builder from models import Branch from models import Platform from models import Test class ManifestHandler(webapp2.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'text/plain; charset=utf-8'; cache = memcache.get('manifest') if cache: self.response.out.write(cache) return test_map = {} platform_id_map = {} branch_id_map = {} for test in Test.all(): branch_ids = [Branch.get(branch_key).id for branch_key in test.branches] platform_ids = [Platform.get(platform_key).id for platform_key in test.platforms] test_map[test.id] = { 'name': test.name, 'branchIds': branch_ids, 'platformIds': platform_ids, } for platform_id in platform_ids: platform_id_map.setdefault(platform_id, {'tests': [], 'branches': []}) platform_id_map[platform_id]['tests'].append(test.id) platform_id_map[platform_id]['branches'] += branch_ids for branch_id in branch_ids: branch_id_map.setdefault(branch_id, {'tests': [], 'platforms': []}) branch_id_map[branch_id]['tests'].append(test.id) branch_id_map[branch_id]['platforms'] += platform_ids platform_map = {} for platform in Platform.all(): if platform.id not in platform_id_map: continue platform_map[platform.id] = { 'name': platform.name, 'testIds': list(set(platform_id_map[platform.id]['tests'])), 'branchIds': list(set(platform_id_map[platform.id]['branches'])), } branch_map = {} for branch in Branch.all(): if branch.id not in branch_id_map: continue branch_map[branch.id] = { 'name': branch.name, 'testIds': list(set(branch_id_map[branch.id]['tests'])), 'platformIds': list(set(branch_id_map[branch.id]['platforms'])), } result = json.dumps({'testMap': test_map, 'platformMap': platform_map, 'branchMap': branch_map}) self.response.out.write(result) memcache.add('manifest', result)