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

Side by Side Diff: tools/metrics/actions/extract_actions.py

Issue 719463003: Presubmit checks for user actions intorduced in HTML files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 unified diff | Download patch
OLDNEW
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 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 parser.close() 499 parser.close()
500 500
501 def WalkDirectory(root_path, actions, extensions, callback): 501 def WalkDirectory(root_path, actions, extensions, callback):
502 for path, dirs, files in os.walk(root_path): 502 for path, dirs, files in os.walk(root_path):
503 if '.svn' in dirs: 503 if '.svn' in dirs:
504 dirs.remove('.svn') 504 dirs.remove('.svn')
505 if '.git' in dirs: 505 if '.git' in dirs:
506 dirs.remove('.git') 506 dirs.remove('.git')
507 for file in files: 507 for file in files:
508 ext = os.path.splitext(file)[1] 508 ext = os.path.splitext(file)[1]
509 if ext in extensions: 509 if ext and ext in extensions:
510 callback(os.path.join(path, file), actions) 510 callback(os.path.join(path, file), actions)
511 511
512 def AddLiteralActions(actions): 512 def AddLiteralActions(actions):
513 """Add literal actions specified via calls to UserMetrics functions. 513 """Add literal actions specified via calls to UserMetrics functions.
514 514
515 Arguments: 515 Arguments:
516 actions: set of actions to add to. 516 actions: set of actions to add to.
517 """ 517 """
518 EXTENSIONS = ('.cc', '.mm', '.c', '.m') 518 EXTENSIONS = ('.cc', '.mm', '.c', '.m')
519 519
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 actions_element = doc.createElement('actions') 756 actions_element = doc.createElement('actions')
757 doc.appendChild(actions_element) 757 doc.appendChild(actions_element)
758 758
759 # Attach action node based on updated |actions|. 759 # Attach action node based on updated |actions|.
760 for action in sorted(actions): 760 for action in sorted(actions):
761 actions_element.appendChild( 761 actions_element.appendChild(
762 _CreateActionTag(doc, action, actions_dict.get(action, None))) 762 _CreateActionTag(doc, action, actions_dict.get(action, None)))
763 763
764 return print_style.GetPrintStyle().PrettyPrintNode(doc) 764 return print_style.GetPrintStyle().PrettyPrintNode(doc)
765 765
766
Alexei Svitkine (slow) 2014/11/11 20:36:41 Nit: Revert changes to this file.
gayane -on leave until 09-2017 2014/11/12 22:00:23 I agree I should restore this line, but the other
767 def main(argv): 766 def main(argv):
768 presubmit = ('--presubmit' in argv) 767 presubmit = ('--presubmit' in argv)
769 actions_xml_path = os.path.join(path_utils.ScriptDir(), 'actions.xml') 768 actions_xml_path = os.path.join(path_utils.ScriptDir(), 'actions.xml')
770 769
771 # Save the original file content. 770 # Save the original file content.
772 with open(actions_xml_path, 'rb') as f: 771 with open(actions_xml_path, 'rb') as f:
773 original_xml = f.read() 772 original_xml = f.read()
774 773
775 actions, actions_dict, comment_nodes = ParseActionFile(original_xml) 774 actions, actions_dict, comment_nodes = ParseActionFile(original_xml)
776 775
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 812
814 with open(actions_xml_path, 'wb') as f: 813 with open(actions_xml_path, 'wb') as f:
815 f.write(pretty) 814 f.write(pretty)
816 print ('Updated %s. Don\'t forget to add it to your changelist' % 815 print ('Updated %s. Don\'t forget to add it to your changelist' %
817 actions_xml_path) 816 actions_xml_path)
818 return 0 817 return 0
819 818
820 819
821 if '__main__' == __name__: 820 if '__main__' == __name__:
822 sys.exit(main(sys.argv)) 821 sys.exit(main(sys.argv))
OLDNEW
« chrome/browser/resources/PRESUBMIT.py ('K') | « chrome/browser/resources/PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698