| OLD | NEW | 
|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 os | 5 import os | 
| 6 import sys | 6 import sys | 
| 7 import logging | 7 import logging | 
| 8 import shutil | 8 import shutil | 
| 9 | 9 | 
| 10 import diff_util | 10 import diff_util | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
| 40 | 40 | 
| 41   # Save the original file content. | 41   # Save the original file content. | 
| 42   logging.info('Loading %s...', os.path.relpath(xml_path)) | 42   logging.info('Loading %s...', os.path.relpath(xml_path)) | 
| 43   with open(xml_path, 'rb') as f: | 43   with open(xml_path, 'rb') as f: | 
| 44     original_xml = f.read() | 44     original_xml = f.read() | 
| 45 | 45 | 
| 46   # Check there are no CR ('\r') characters in the file. | 46   # Check there are no CR ('\r') characters in the file. | 
| 47   if '\r' in original_xml: | 47   if '\r' in original_xml: | 
| 48     logging.error('DOS-style line endings (CR characters) detected - these are ' | 48     logging.error('DOS-style line endings (CR characters) detected - these are ' | 
| 49                   'not allowed. Please run dos2unix %s', original_filename) | 49                   'not allowed. Please run dos2unix %s', original_filename) | 
| 50     return 1 | 50     sys.exit(1) | 
| 51 | 51 | 
| 52   try: | 52   try: | 
| 53     pretty = prettyFn(original_xml) | 53     pretty = prettyFn(original_xml) | 
| 54   except Error: | 54   except Error: | 
| 55     logging.error('Aborting parsing due to fatal errors.') | 55     logging.error('Aborting parsing due to fatal errors.') | 
| 56     return 1 | 56     sys.exit(1) | 
| 57 | 57 | 
| 58   if original_xml == pretty: | 58   if original_xml == pretty: | 
| 59     logging.info('%s is correctly pretty-printed.', original_filename) | 59     logging.info('%s is correctly pretty-printed.', original_filename) | 
| 60     return 0 | 60     sys.exit(0) | 
| 61   if presubmit: | 61   if presubmit: | 
| 62     logging.error('%s is not formatted correctly; run %s to fix.', | 62     logging.error('%s is not formatted correctly; run %s to fix.', | 
| 63                   original_filename, script_name) | 63                   original_filename, script_name) | 
| 64     return 1 | 64     sys.exit(1) | 
| 65 | 65 | 
| 66   # Prompt user to consent on the change. | 66   # Prompt user to consent on the change. | 
| 67   if not diff_util.PromptUserToAcceptDiff( | 67   if not diff_util.PromptUserToAcceptDiff( | 
| 68       original_xml, pretty, 'Is the new version acceptable?'): | 68       original_xml, pretty, 'Is the new version acceptable?'): | 
| 69     logging.error('Diff not accepted. Aborting.') | 69     logging.error('Diff not accepted. Aborting.') | 
| 70     return 1 | 70     sys.exit(1) | 
| 71 | 71 | 
| 72   logging.info('Creating backup file: %s', backup_filename) | 72   logging.info('Creating backup file: %s', backup_filename) | 
| 73   shutil.move(xml_path, os.path.join(xml_dir, backup_filename)) | 73   shutil.move(xml_path, os.path.join(xml_dir, backup_filename)) | 
| 74 | 74 | 
| 75   with open(xml_path, 'wb') as f: | 75   with open(xml_path, 'wb') as f: | 
| 76     f.write(pretty) | 76     f.write(pretty) | 
| 77   logging.info('Updated %s. Don\'t forget to add it to your changelist', | 77   logging.info('Updated %s. Don\'t forget to add it to your changelist', | 
| 78                xml_path) | 78                xml_path) | 
| 79   return 0 | 79   sys.exit(0) | 
| OLD | NEW | 
|---|