| OLD | NEW |
| (Empty) | |
| 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 |
| 3 # found in the LICENSE file. |
| 4 |
| 5 from collections import defaultdict |
| 6 |
| 7 |
| 8 def IsSameFilePath(path_1, path_2): |
| 9 """Determines if two paths represent same path. |
| 10 |
| 11 Compares the name of the folders in the path (by split('/')), and checks |
| 12 if they match either more than 3 or min of path lengths. |
| 13 |
| 14 Args: |
| 15 path_1 (str): First path. |
| 16 path_2 (str): Second path to compare. |
| 17 |
| 18 Returns: |
| 19 Boolean, True if it they are thought to be a same path, False otherwise. |
| 20 """ |
| 21 # TODO(katesonia): Think of better way to determine whether 2 paths are the |
| 22 # same or not. |
| 23 path_parts_1 = path_1.lower().split('/') |
| 24 path_parts_2 = path_2.lower().split('/') |
| 25 |
| 26 if path_parts_1[-1] != path_parts_2[-1]: |
| 27 return False |
| 28 |
| 29 def _GetPathPartsCount(path_parts): |
| 30 path_parts_count = defaultdict(int) |
| 31 |
| 32 for path_part in path_parts: |
| 33 path_parts_count[path_part] += 1 |
| 34 |
| 35 return path_parts_count |
| 36 |
| 37 parts_count_1 = _GetPathPartsCount(path_parts_1) |
| 38 parts_count_2 = _GetPathPartsCount(path_parts_2) |
| 39 |
| 40 # Get number of same path parts between path_1 and path_2. For example: |
| 41 # a/b/b/b/f.cc and a/b/b/c/d/f.cc have 4 path parts the same in total. |
| 42 total_same_parts = sum([min(parts_count_1[part], parts_count_2[part]) for |
| 43 part in parts_count_1 if part in path_parts_2]) |
| 44 |
| 45 return total_same_parts >= (min(3, min(len(path_parts_1), len(path_parts_2)))) |
| OLD | NEW |