1#!/usr/bin/python 2 3 4''' 5Copyright 2013 Google Inc. 6 7Use of this source code is governed by a BSD-style license that can be 8found in the LICENSE file. 9''' 10 11''' 12Rewrites a JSON file to use Python's standard JSON pretty-print format, 13so that subsequent runs of rebaseline.py will generate useful diffs 14(only the actual checksum differences will show up as diffs, not obscured 15by format differences). 16 17Should not modify the JSON contents in any meaningful way. 18''' 19 20 21# System-level imports 22from __future__ import print_function 23import argparse 24import os 25import sys 26 27 28# Imports from within Skia 29# 30# We need to add the 'gm' directory, so that we can import gm_json.py within 31# that directory. That script allows us to parse the actual-results.json file 32# written out by the GM tool. 33# Make sure that the 'gm' dir is in the PYTHONPATH, but add it at the *end* 34# so any dirs that are already in the PYTHONPATH will be preferred. 35# 36# This assumes that the 'gm' directory has been checked out as a sibling of 37# the 'tools' directory containing this script, which will be the case if 38# 'trunk' was checked out as a single unit. 39GM_DIRECTORY = os.path.realpath( 40 os.path.join(os.path.dirname(os.path.dirname(__file__)), 'gm')) 41if GM_DIRECTORY not in sys.path: 42 sys.path.append(GM_DIRECTORY) 43import gm_json 44 45def Reformat(filename): 46 print('Reformatting file %s...' % filename) 47 gm_json.WriteToFile(gm_json.LoadFromFile(filename), filename) 48 49def _Main(): 50 parser = argparse.ArgumentParser(description='Reformat JSON files in-place.') 51 parser.add_argument('filenames', metavar='FILENAME', nargs='+', 52 help='file to reformat') 53 args = parser.parse_args() 54 for filename in args.filenames: 55 Reformat(filename) 56 sys.exit(0) 57 58if __name__ == '__main__': 59 _Main() 60