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