| 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 UpdateXml(original_xml): | 822 def main(argv): |
| 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 |
| 823 actions, actions_dict, comment_nodes = ParseActionFile(original_xml) | 830 actions, actions_dict, comment_nodes = ParseActionFile(original_xml) |
| 824 | 831 |
| 825 AddComputedActions(actions) | 832 AddComputedActions(actions) |
| 826 # TODO(fmantek): bring back webkit editor actions. | 833 # TODO(fmantek): bring back webkit editor actions. |
| 827 # AddWebKitEditorActions(actions) | 834 # AddWebKitEditorActions(actions) |
| 828 AddAboutFlagsActions(actions) | 835 AddAboutFlagsActions(actions) |
| 829 AddWebUIActions(actions) | 836 AddWebUIActions(actions) |
| 830 | 837 |
| 831 AddLiteralActions(actions) | 838 AddLiteralActions(actions) |
| 832 | 839 |
| 833 # print "Scanned {0} number of files".format(number_of_files_total) | 840 # print "Scanned {0} number of files".format(number_of_files_total) |
| 834 # print "Found {0} entries".format(len(actions)) | 841 # print "Found {0} entries".format(len(actions)) |
| 835 | 842 |
| 836 AddAndroidActions(actions) | 843 AddAndroidActions(actions) |
| 837 AddAutomaticResetBannerActions(actions) | 844 AddAutomaticResetBannerActions(actions) |
| 838 AddBookmarkManagerActions(actions) | 845 AddBookmarkManagerActions(actions) |
| 839 AddChromeOSActions(actions) | 846 AddChromeOSActions(actions) |
| 840 AddClosedSourceActions(actions) | 847 AddClosedSourceActions(actions) |
| 841 AddExtensionActions(actions) | 848 AddExtensionActions(actions) |
| 842 AddHistoryPageActions(actions) | 849 AddHistoryPageActions(actions) |
| 843 | 850 |
| 844 return PrettyPrint(actions, actions_dict, comment_nodes) | 851 pretty = PrettyPrint(actions, actions_dict, comment_nodes) |
| 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) |
| 845 | 859 |
| 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) |
| 846 | 865 |
| 847 def main(argv): | 866 print 'Creating backup file: actions.old.xml.' |
| 848 presubmit_util.DoPresubmitMain(argv, 'actions.xml', 'actions.old.xml', | 867 shutil.move(actions_xml_path, 'actions.old.xml') |
| 849 'extract_actions.py', UpdateXml) | 868 |
| 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 |
| 850 | 875 |
| 851 if '__main__' == __name__: | 876 if '__main__' == __name__: |
| 852 sys.exit(main(sys.argv)) | 877 sys.exit(main(sys.argv)) |
| OLD | NEW |