| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 for option_name in required: | 78 for option_name in required: |
| 79 if getattr(options, option_name) is None: | 79 if getattr(options, option_name) is None: |
| 80 parser.error('--%s is required' % option_name.replace('_', '-')) | 80 parser.error('--%s is required' % option_name.replace('_', '-')) |
| 81 | 81 |
| 82 def WriteJson(obj, path, only_if_changed=False): | 82 def WriteJson(obj, path, only_if_changed=False): |
| 83 old_dump = None | 83 old_dump = None |
| 84 if os.path.exists(path): | 84 if os.path.exists(path): |
| 85 with open(path, 'r') as oldfile: | 85 with open(path, 'r') as oldfile: |
| 86 old_dump = oldfile.read() | 86 old_dump = oldfile.read() |
| 87 | 87 |
| 88 new_dump = json.dumps(obj) | 88 new_dump = json.dumps(obj, sort_keys=True, indent=2, separators=(',', ': ')) |
| 89 | 89 |
| 90 if not only_if_changed or old_dump != new_dump: | 90 if not only_if_changed or old_dump != new_dump: |
| 91 with open(path, 'w') as outfile: | 91 with open(path, 'w') as outfile: |
| 92 outfile.write(new_dump) | 92 outfile.write(new_dump) |
| 93 | 93 |
| 94 def ReadJson(path): | 94 def ReadJson(path): |
| 95 with open(path, 'r') as jsonfile: | 95 with open(path, 'r') as jsonfile: |
| 96 return json.load(jsonfile) | 96 return json.load(jsonfile) |
| 97 | 97 |
| 98 | 98 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 | 202 |
| 203 | 203 |
| 204 def PrintWarning(message): | 204 def PrintWarning(message): |
| 205 print 'WARNING: ' + message | 205 print 'WARNING: ' + message |
| 206 | 206 |
| 207 | 207 |
| 208 def PrintBigWarning(message): | 208 def PrintBigWarning(message): |
| 209 print '***** ' * 8 | 209 print '***** ' * 8 |
| 210 PrintWarning(message) | 210 PrintWarning(message) |
| 211 print '***** ' * 8 | 211 print '***** ' * 8 |
| OLD | NEW |