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

Unified Diff: tools/metrics/actions/extract_actions.py

Issue 933103002: Revert of Add pretty printing for rappor.xml (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/metrics/common/models.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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))
« no previous file with comments | « no previous file | tools/metrics/common/models.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698