OLD | NEW |
---|---|
(Empty) | |
1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 """Presubmit script for HTML files in . | |
yao
2014/11/12 22:23:21
Finish the sentence plz :)
gayane -on leave until 09-2017
2014/11/15 00:09:09
Done.
| |
5 | |
6 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | |
7 for more details about the presubmit API built into gcl. | |
8 """ | |
9 action_xml_path = '../../../tools/metrics/actions/actions.xml' | |
10 | |
11 def CheckUserActionUpdate(input_api, output_api): | |
12 """Checks if any new user action has been added.""" | |
13 if any('actions.xml' == input_api.os_path.basename(f.LocalPath()) for f in | |
14 input_api.AffectedFiles()): | |
15 # If actions.xml is already included in the changelist, the PRESUBMIT | |
16 # for actions.xml will do a more complete presubmit check. | |
17 return [] | |
18 | |
19 file_filter = lambda f: f.LocalPath().endswith(('.html')) | |
20 action_re = r'(^|\s+)metric\s*=\s*"([^ ]*)"' | |
21 current_actions = None | |
22 for f in input_api.AffectedFiles(file_filter=file_filter): | |
23 for line_num, line in f.ChangedContents(): | |
24 match = input_api.re.search(action_re, line) | |
25 if match: | |
26 # Loads contents in tools/metrics/actions/actions.xml to memory. It's | |
27 # loaded only once. | |
28 if not current_actions: | |
29 with open(action_xml_path) as actions_f: | |
30 current_actions = actions_f.read() | |
31 | |
32 # Search for the matched user action name in |current_actions|. | |
33 action_name = match.group(2) | |
34 action = 'name="{0}"'.format(action_name) | |
35 action_disabled = 'name="{0}_disabled"'.format(action_name) | |
36 action_enabled = 'name="{0}_enabled"'.format(action_name) | |
Alexei Svitkine (slow)
2014/11/12 22:27:00
From extract_actions.py, it looks like the actual
gayane -on leave until 09-2017
2014/11/15 00:09:09
Done.
| |
37 | |
38 if action not in current_actions and\ | |
39 (action_enabled not in current_actions or\ | |
40 action_disabled not in current_actions): | |
yao
2014/11/12 22:23:21
I wonder how fast this is. Could you test?
I rem
Alexei Svitkine (slow)
2014/11/12 22:27:00
I think it would be cleaner to make a helper funct
gayane -on leave until 09-2017
2014/11/15 00:09:09
Done.
gayane -on leave until 09-2017
2014/11/15 00:09:09
I tried to make it a little bit better. Now it wil
| |
41 return [output_api.PresubmitPromptWarning( | |
42 'File %s line %d: %s is missing in ' | |
43 'tools/metrics/actions/actions.xml. Please run ' | |
44 'tools/metrics/actions/extract_actions.py to update.' | |
45 % (f.LocalPath(), line_num, action_name), [])] | |
46 return [] | |
47 | |
Alexei Svitkine (slow)
2014/11/12 22:27:00
Nit: Add an extra line.
gayane -on leave until 09-2017
2014/11/15 00:09:09
Done.
| |
48 def CheckChangeOnUpload(input_api, output_api): | |
49 return CheckUserActionUpdate(input_api, output_api) | |
50 | |
51 | |
52 def CheckChangeOnCommit(input_api, output_api): | |
53 return CheckUserActionUpdate(input_api, output_api) | |
OLD | NEW |