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

Side by Side Diff: appengine/findit/crash/component.py

Issue 2657913002: [Predator] Add ``Project`` class and ``ClassifySuspect`` method to project and component classifier (Closed)
Patch Set: . Created 3 years, 11 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 unified diff | Download patch
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from collections import namedtuple 5 from collections import namedtuple
6 import re 6 import re
7 7
8 from libs.gitiles.diff import ChangeType
9
8 10
9 # TODO(http://crbug.com/659346): write the coverage tests. 11 # TODO(http://crbug.com/659346): write the coverage tests.
10 class Component(namedtuple('Component', 12 class Component(namedtuple('Component',
11 ['component_name', 'path_regex', 'function_regex'])): # pragma: no cover 13 ['component_name', 'path_regex', 'function_regex'])): # pragma: no cover
12 """A representation of a "component" in Chromium. 14 """A representation of a "component" in Chromium.
13 15
14 For example: 'Blink>DOM' or 'Blink>HTML'. Notably, a component knows 16 For example: 'Blink>DOM' or 'Blink>HTML'. Notably, a component knows
15 how to identify itself. Hence, given a stack frame or change list 17 how to identify itself. Hence, given a stack frame or change list
16 or whatever, we ask the Component whether it matches that frame, 18 or whatever, we ask the Component whether it matches that frame,
17 CL, etc.""" 19 CL, etc."""
18 __slots__ = () 20 __slots__ = ()
19 21
20 def __new__(cls, component_name, path_regex, function_regex=None): 22 def __new__(cls, component_name, path_regex, function_regex=None):
21 return super(cls, Component).__new__(cls, 23 return super(cls, Component).__new__(cls,
22 component_name, 24 component_name,
23 re.compile(path_regex), 25 re.compile(path_regex),
24 re.compile(function_regex) if function_regex else None) 26 re.compile(function_regex) if function_regex else None)
25 27
26
27 def MatchesStackFrame(self, frame): 28 def MatchesStackFrame(self, frame):
28 """Returns true if this component matches the frame.""" 29 """Returns true if this component matches the frame."""
29 if not self.path_regex.match(frame.dep_path + frame.file_path): 30 if not self.path_regex.match(frame.dep_path + frame.file_path):
30 return False 31 return False
31 32
32 # We interpret function_regex=None to mean the regex that matches 33 # We interpret function_regex=None to mean the regex that matches
33 # everything. 34 # everything.
34 if not self.function_regex: 35 if not self.function_regex:
35 return True 36 return True
36 return self.function_regex.match(frame.function) 37 return self.function_regex.match(frame.function)
37 38
38 def MatchesFile(self, file_path): 39 def MatchesTouchedFile(self, dep_path, touched_file):
chanli 2017/01/26 21:31:06 This function is similar to MatchesTouchedFile in
Sharu Jiang 2017/01/27 03:20:42 Since the ``Project`` and ``Component`` are 2 fund
39 """Returns true if this component matches file path.""" 40 """Returns true if the touched file belongs to this component."""
40 return self.path_regex.match(file_path) 41 # TODO(ymzhang): use component of new path as default. RENAME might
42 # need to return two (old path new path may have different components)
43 if touched_file.change_type == ChangeType.DELETE:
44 path = touched_file.old_path
45 else:
46 path = touched_file.new_path
47
48 if self.path_regex.match(dep_path + path):
49 return True
50
51 return False
OLDNEW
« no previous file with comments | « no previous file | appengine/findit/crash/component_classifier.py » ('j') | appengine/findit/crash/component_classifier.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698