Index: tools/metrics/actions/extract_actions.py |
diff --git a/tools/metrics/actions/extract_actions.py b/tools/metrics/actions/extract_actions.py |
index dde900ac444b9329e11250cb16cfc3f813ae0f9a..94dcf225a976b6da9564813e46954c6b83af7868 100755 |
--- a/tools/metrics/actions/extract_actions.py |
+++ b/tools/metrics/actions/extract_actions.py |
@@ -819,7 +819,14 @@ |
return print_style.GetPrintStyle().PrettyPrintNode(doc) |
-def UpdateXml(original_xml): |
+def main(argv): |
+ presubmit = ('--presubmit' in argv) |
+ actions_xml_path = os.path.join(path_utils.ScriptDir(), 'actions.xml') |
+ |
+ # Save the original file content. |
+ with open(actions_xml_path, 'rb') as f: |
+ original_xml = f.read() |
+ |
actions, actions_dict, comment_nodes = ParseActionFile(original_xml) |
AddComputedActions(actions) |
@@ -841,12 +848,30 @@ |
AddExtensionActions(actions) |
AddHistoryPageActions(actions) |
- return PrettyPrint(actions, actions_dict, comment_nodes) |
- |
- |
-def main(argv): |
- presubmit_util.DoPresubmitMain(argv, 'actions.xml', 'actions.old.xml', |
- 'extract_actions.py', UpdateXml) |
+ pretty = PrettyPrint(actions, actions_dict, comment_nodes) |
+ if original_xml == pretty: |
+ print 'actions.xml is correctly pretty-printed.' |
+ sys.exit(0) |
+ if presubmit: |
+ logging.info('actions.xml is not formatted correctly; run ' |
+ 'extract_actions.py to fix.') |
+ sys.exit(1) |
+ |
+ # Prompt user to consent on the change. |
+ if not diff_util.PromptUserToAcceptDiff( |
+ original_xml, pretty, 'Is the new version acceptable?'): |
+ logging.error('Aborting') |
+ sys.exit(1) |
+ |
+ print 'Creating backup file: actions.old.xml.' |
+ shutil.move(actions_xml_path, 'actions.old.xml') |
+ |
+ with open(actions_xml_path, 'wb') as f: |
+ f.write(pretty) |
+ print ('Updated %s. Don\'t forget to add it to your changelist' % |
+ actions_xml_path) |
+ return 0 |
+ |
if '__main__' == __name__: |
sys.exit(main(sys.argv)) |