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

Unified Diff: appengine/findit/crash/project.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 side-by-side diff with in-line comments
Download patch
Index: appengine/findit/crash/project.py
diff --git a/appengine/findit/crash/project.py b/appengine/findit/crash/project.py
new file mode 100644
index 0000000000000000000000000000000000000000..032bd3996b9d76f7d5b960930c2e20b9b30a475d
--- /dev/null
+++ b/appengine/findit/crash/project.py
@@ -0,0 +1,90 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
chanli 2017/01/26 21:31:06 Nit: 2017
Sharu Jiang 2017/01/27 03:20:42 Done.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from collections import namedtuple
+import re
+
+from libs.gitiles.diff import ChangeType
+
+
+# TODO(http://crbug.com/659346): write the coverage tests.
+class Project(namedtuple('Project',
+ ['name', 'path_regexs', 'function_regexs',
+ 'host_directories'])): # pragma: no cover
+ """A representation of a "project".
+
+ For example: 'android_os', 'clank' or 'chromium'. Notably, a project knows
+ how to identify itself. Hence, given a stack frame, file path or dependency
+ path or whatever, we ask the ``Project`` whether it matches that frame,
+ CL, etc."""
+ __slots__ = ()
+
+ def __new__(cls, name, path_regexs=None,
+ function_regexs=None, host_directories=None):
+ path_regexs = [re.compile(path_regex) for path_regex in
+ path_regexs] if path_regexs else None
chanli 2017/01/26 21:31:06 how about else []? same for function_regexs. so in
Sharu Jiang 2017/01/27 03:20:42 Done.
+ function_regexs = [re.compile(function_regex) for function_regex in
+ function_regexs] if function_regexs else None
+
+ return super(cls, Project).__new__(
+ cls, name, path_regexs, function_regexs, host_directories)
+
+ def MatchesStackFrame(self, frame):
+ """Returns true if this component matches the frame."""
+ for path_regex in self.path_regexs or []:
+ if path_regex.match(frame.raw_file_path):
+ return True
+
+ for function_regex in self.function_regexs or []:
+ if function_regex.match(frame.function):
+ print frame.function, function_regex.pattern
chanli 2017/01/26 21:31:06 Nit:remove this
Sharu Jiang 2017/01/27 03:20:42 Done.
+ return True
+
+ if not self.host_directories:
+ return False
chanli 2017/01/26 21:31:06 This can be removed if you use for host_directory
Sharu Jiang 2017/01/27 03:20:42 Done.
+
+ for host_directory in self.host_directories:
+ if frame.dep_path.startswith(host_directory):
+ return True
+
+ return False
+
+ def MatchesTouchedFile(self, dep_path, touched_file):
+ """Returns true if this component matches file path."""
+ # TODO(ymzhang): use component of new path as default. RENAME might
+ # need to return two (old path new path may have different components)
+ if touched_file.change_type == ChangeType.DELETE:
+ path = touched_file.old_path
+ else:
+ path = touched_file.new_path
+
+ path = dep_path + path
+ for path_regex in self.path_regexs or []:
+ if path_regex.match(path):
+ return True
+
+ for host_directory in self.host_directories or []:
+ if dep_path.startswith(host_directory):
+ return True
+
+ return False
+
+ def GetName(self, dep_path):
chanli 2017/01/26 21:31:07 Based on returned value, it's not just project's n
Sharu Jiang 2017/01/27 03:20:42 Right, should add more doc about that.
+ """Returns the project name from a dep path."""
+ if 'chromium' not in self.name:
+ return self.name
+
+ if not dep_path:
+ return None
+
+ for host_directory in self.host_directories or []:
+ if dep_path.startswith(host_directory):
+ path = dep_path[len(host_directory):]
+ if not path:
+ return self.name
+
+ return '%s-%s' % (self.name, path.split('/')[0].lower())
+
+ # Unknown path, return the whole path as project name.
+ return '%s-%s' % (self.name, '_'.join(dep_path.split('/')))

Powered by Google App Engine
This is Rietveld 408576698