#!/usr/bin/env python # # Copyright 2013 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import json import sys from string import Template _HTML_TEMPLATE = """ Click to change an applied policy.
""" def _GenerateGraph(json_data): policies = list(json_data['policies']) default_policy = "l2" if default_policy not in policies: default_policy = policies[0] policies = "".join(map(lambda x: '
  • '+x+'
  • ', policies)) all_data = {} for policy in json_data['policies']: legends = list(json_data['policies'][policy]['legends']) legends = ['second'] + legends[legends.index('FROM_HERE_FOR_TOTAL') + 1: legends.index('UNTIL_HERE_FOR_TOTAL')] data = [] for snapshot in json_data['policies'][policy]['snapshots']: data.append([0] * len(legends)) for k, v in snapshot.iteritems(): if k in legends: data[-1][legends.index(k)] = v all_data[policy] = [legends] + data print Template(_HTML_TEMPLATE).safe_substitute( {'POLICIES': policies, 'DEF_POLICY': default_policy, 'ALL_DATA': json.dumps(all_data)}) def main(argv): _GenerateGraph(json.load(file(argv[1], 'r'))) if __name__ == '__main__': sys.exit(main(sys.argv))