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

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