OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Extract UserMetrics "actions" strings from the Chrome source. | 7 """Extract UserMetrics "actions" strings from the Chrome source. |
8 | 8 |
9 This program generates the list of known actions we expect to see in the | 9 This program generates the list of known actions we expect to see in the |
10 user behavior logs. It walks the Chrome source, looking for calls to | 10 user behavior logs. It walks the Chrome source, looking for calls to |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
812 doc.appendChild(actions_element) | 812 doc.appendChild(actions_element) |
813 | 813 |
814 # Attach action node based on updated |actions|. | 814 # Attach action node based on updated |actions|. |
815 for action in sorted(actions): | 815 for action in sorted(actions): |
816 actions_element.appendChild( | 816 actions_element.appendChild( |
817 _CreateActionTag(doc, action, actions_dict.get(action, None))) | 817 _CreateActionTag(doc, action, actions_dict.get(action, None))) |
818 | 818 |
819 return print_style.GetPrintStyle().PrettyPrintNode(doc) | 819 return print_style.GetPrintStyle().PrettyPrintNode(doc) |
820 | 820 |
821 | 821 |
822 def main(argv): | 822 def UpdateXml(original_xml): |
823 presubmit = ('--presubmit' in argv) | |
824 actions_xml_path = os.path.join(path_utils.ScriptDir(), 'actions.xml') | |
825 | |
826 # Save the original file content. | |
827 with open(actions_xml_path, 'rb') as f: | |
828 original_xml = f.read() | |
829 | |
830 actions, actions_dict, comment_nodes = ParseActionFile(original_xml) | 823 actions, actions_dict, comment_nodes = ParseActionFile(original_xml) |
831 | 824 |
832 AddComputedActions(actions) | 825 AddComputedActions(actions) |
833 # TODO(fmantek): bring back webkit editor actions. | 826 # TODO(fmantek): bring back webkit editor actions. |
834 # AddWebKitEditorActions(actions) | 827 # AddWebKitEditorActions(actions) |
835 AddAboutFlagsActions(actions) | 828 AddAboutFlagsActions(actions) |
836 AddWebUIActions(actions) | 829 AddWebUIActions(actions) |
837 | 830 |
838 AddLiteralActions(actions) | 831 AddLiteralActions(actions) |
839 | 832 |
840 # print "Scanned {0} number of files".format(number_of_files_total) | 833 # print "Scanned {0} number of files".format(number_of_files_total) |
841 # print "Found {0} entries".format(len(actions)) | 834 # print "Found {0} entries".format(len(actions)) |
842 | 835 |
843 AddAndroidActions(actions) | 836 AddAndroidActions(actions) |
844 AddAutomaticResetBannerActions(actions) | 837 AddAutomaticResetBannerActions(actions) |
845 AddBookmarkManagerActions(actions) | 838 AddBookmarkManagerActions(actions) |
846 AddChromeOSActions(actions) | 839 AddChromeOSActions(actions) |
847 AddClosedSourceActions(actions) | 840 AddClosedSourceActions(actions) |
848 AddExtensionActions(actions) | 841 AddExtensionActions(actions) |
849 AddHistoryPageActions(actions) | 842 AddHistoryPageActions(actions) |
850 | 843 |
851 pretty = PrettyPrint(actions, actions_dict, comment_nodes) | 844 return PrettyPrint(actions, actions_dict, comment_nodes) |
Alexei Svitkine (slow)
2015/02/13 14:36:37
Should the histograms presubmits also be refactore
Steven Holte
2015/02/14 01:11:18
Done.
| |
852 if original_xml == pretty: | |
853 print 'actions.xml is correctly pretty-printed.' | |
854 sys.exit(0) | |
855 if presubmit: | |
856 logging.info('actions.xml is not formatted correctly; run ' | |
857 'extract_actions.py to fix.') | |
858 sys.exit(1) | |
859 | 845 |
860 # Prompt user to consent on the change. | |
861 if not diff_util.PromptUserToAcceptDiff( | |
862 original_xml, pretty, 'Is the new version acceptable?'): | |
863 logging.error('Aborting') | |
864 sys.exit(1) | |
865 | 846 |
866 print 'Creating backup file: actions.old.xml.' | 847 def main(argv): |
867 shutil.move(actions_xml_path, 'actions.old.xml') | 848 presubmit_util.DoPresubmitMain(argv, 'actions.xml', 'actions.old.xml', |
868 | 849 'extract_actions.py', UpdateXml) |
869 with open(actions_xml_path, 'wb') as f: | |
870 f.write(pretty) | |
871 print ('Updated %s. Don\'t forget to add it to your changelist' % | |
872 actions_xml_path) | |
873 return 0 | |
874 | |
875 | 850 |
876 if '__main__' == __name__: | 851 if '__main__' == __name__: |
877 sys.exit(main(sys.argv)) | 852 sys.exit(main(sys.argv)) |
OLD | NEW |