OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import contextlib | 5 import contextlib |
6 import fnmatch | 6 import fnmatch |
7 import json | 7 import json |
8 import os | 8 import os |
9 import pipes | 9 import pipes |
10 import shlex | 10 import shlex |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 for option_name in required: | 73 for option_name in required: |
74 if getattr(options, option_name) is None: | 74 if getattr(options, option_name) is None: |
75 parser.error('--%s is required' % option_name.replace('_', '-')) | 75 parser.error('--%s is required' % option_name.replace('_', '-')) |
76 | 76 |
77 def WriteJson(obj, path, only_if_changed=False): | 77 def WriteJson(obj, path, only_if_changed=False): |
78 old_dump = None | 78 old_dump = None |
79 if os.path.exists(path): | 79 if os.path.exists(path): |
80 with open(path, 'r') as oldfile: | 80 with open(path, 'r') as oldfile: |
81 old_dump = oldfile.read() | 81 old_dump = oldfile.read() |
82 | 82 |
83 new_dump = json.dumps(obj) | 83 new_dump = json.dumps(obj, sort_keys=True, indent=2, separators=(',', ': ')) |
84 | 84 |
85 if not only_if_changed or old_dump != new_dump: | 85 if not only_if_changed or old_dump != new_dump: |
86 with open(path, 'w') as outfile: | 86 with open(path, 'w') as outfile: |
87 outfile.write(new_dump) | 87 outfile.write(new_dump) |
88 | 88 |
89 def ReadJson(path): | 89 def ReadJson(path): |
90 with open(path, 'r') as jsonfile: | 90 with open(path, 'r') as jsonfile: |
91 return json.load(jsonfile) | 91 return json.load(jsonfile) |
92 | 92 |
93 | 93 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 188 |
189 | 189 |
190 def PrintWarning(message): | 190 def PrintWarning(message): |
191 print 'WARNING: ' + message | 191 print 'WARNING: ' + message |
192 | 192 |
193 | 193 |
194 def PrintBigWarning(message): | 194 def PrintBigWarning(message): |
195 print '***** ' * 8 | 195 print '***** ' * 8 |
196 PrintWarning(message) | 196 PrintWarning(message) |
197 print '***** ' * 8 | 197 print '***** ' * 8 |
OLD | NEW |