Chromium Code Reviews| Index: appengine/findit/crash/crash_util.py |
| diff --git a/appengine/findit/crash/crash_util.py b/appengine/findit/crash/crash_util.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..80f80470953625deacfebf99d0df88aa7f696da5 |
| --- /dev/null |
| +++ b/appengine/findit/crash/crash_util.py |
| @@ -0,0 +1,43 @@ |
| +# Copyright 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +from collections import defaultdict |
| + |
| + |
| +def IsSameFilePath(path1, path2): |
|
Martin Barbella
2016/04/19 22:21:28
With the style change below, these look a bit awkw
Sharu Jiang
2016/04/20 18:54:24
Done.
|
| + """Determines if two paths represent same path. |
| + |
| + Compares the name of the folders in the path (by split('/')), and checks |
| + if they match either more than 3 or min of path lengths. |
| + |
| + Args: |
| + path1 (str): First path. |
| + path2 (str): Second path to compare. |
| + |
| + Returns: |
| + Boolean, True if it they are thought to be a same path, False otherwise. |
| + """ |
| + # TODO(katesonia): Think of better way to determine whether 2 paths are the |
| + # same or not. |
| + path_parts_1 = path1.lower().split('/') |
| + path_parts_2 = path2.lower().split('/') |
| + |
| + if path_parts_1[-1] != path_parts_2[-1]: |
| + return False |
| + |
| + def _GetPathPartsCount(path_parts): |
| + path_parts_count = defaultdict(int) |
| + |
| + for path_part in path_parts: |
| + path_parts_count[path_part] += 1 |
| + |
| + return path_parts_count |
| + |
| + parts_count_1 = _GetPathPartsCount(path_parts_1) |
| + parts_count_2 = _GetPathPartsCount(path_parts_2) |
| + |
| + total_same_parts = sum([min(parts_count_1[part], parts_count_2[part]) for |
|
Martin Barbella
2016/04/19 22:21:28
This is complicated enough that it warrants a comm
Sharu Jiang
2016/04/20 18:54:24
Done.
|
| + part in parts_count_1 if part in path_parts_2]) |
| + |
| + return total_same_parts >= (min(3, min(len(path_parts_1), len(path_parts_2)))) |