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

Unified Diff: tools/reformat-json.py

Issue 19289011: add reformat-json.py script (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: comments_only 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/reformat-json.py
===================================================================
--- tools/reformat-json.py (revision 0)
+++ tools/reformat-json.py (revision 0)
@@ -0,0 +1,55 @@
+#!/usr/bin/python
+
+'''
+Copyright 2013 Google Inc.
+
+Use of this source code is governed by a BSD-style license that can be
+found in the LICENSE file.
+'''
+
+'''
+Rewrites a JSON file to use Python's standard JSON pretty-print format,
+so that subsequent runs of rebaseline.py will generate useful diffs
+(only the actual checksum differences will show up as diffs, not obscured
+by format differences).
+
+Should not modify the JSON contents in any meaningful way.
+'''
+
+# System-level imports
+import argparse
+import os
+import sys
+
+# Imports from within Skia
+#
+# We need to add the 'gm' directory, so that we can import gm_json.py within
+# that directory. That script allows us to parse the actual-results.json file
+# written out by the GM tool.
+# Make sure that the 'gm' dir is in the PYTHONPATH, but add it at the *end*
+# so any dirs that are already in the PYTHONPATH will be preferred.
+#
+# This assumes that the 'gm' directory has been checked out as a sibling of
+# the 'tools' directory containing this script, which will be the case if
+# 'trunk' was checked out as a single unit.
+GM_DIRECTORY = os.path.realpath(
+ os.path.join(os.path.dirname(os.path.dirname(__file__)), 'gm'))
+if GM_DIRECTORY not in sys.path:
+ sys.path.append(GM_DIRECTORY)
+import gm_json
+
+def Reformat(filename):
+ print 'Reformatting file %s...' % filename
+ gm_json.WriteToFile(gm_json.LoadFromFile(filename), filename)
+
+def _Main():
+ parser = argparse.ArgumentParser(description='Reformat JSON files in-place.')
+ parser.add_argument('filenames', metavar='FILENAME', nargs='+',
+ help='file to reformat')
+ args = parser.parse_args()
+ for filename in args.filenames:
+ Reformat(filename)
+ sys.exit(0)
+
+if __name__ == '__main__':
+ _Main()
Property changes on: tools/reformat-json.py
___________________________________________________________________
Added: svn:executable
+ *
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698