コード例 #1
0
ファイル: utils.py プロジェクト: nexB/deltacode
def align_trees(a_files, b_files):
    """
    Given two sequences of File objects 'a' and 'b', return a tuple of
    two integers that represent the number path segments to remove
    respectively from a File path in 'a' or a File path in 'b' to obtain the
    equal paths for two files that are the same in 'a' and 'b'.
    """
    # we need to find one uniquly named file that exists in 'a' and 'b'.
    a_names = defaultdict(list)
    for a_file in a_files:
        a_names[a_file.name].append(a_file)
    a_uniques = {k: v[0] for k, v in a_names.items() if len(v) == 1}

    b_names = defaultdict(list)
    for b_file in b_files:
        b_names[b_file.name].append(b_file)
    b_uniques = {k: v[0] for k, v in b_names.items() if len(v) == 1}

    candidate_found = False
    for a_name, a_unique in a_uniques.items():
        if a_name not in b_uniques:
            continue
        b_unique = b_uniques.get(a_name)
        if a_unique and a_unique.sha1 == b_unique.sha1:
            candidate_found = True
            break

    if not candidate_found:
        raise AlignmentException
    if a_unique.path == b_unique.path:
        return 0, 0

    common_suffix, common_segments = paths.common_path_suffix(
        a_unique.path, b_unique.path)
    a_segments = len(paths.split(a_unique.path))
    b_segments = len(paths.split(b_unique.path))

    return a_segments - common_segments, b_segments - common_segments
コード例 #2
0
 def test_common_path_suffix_two_root(self):
     test = paths.common_path_suffix('/', '/')
     assert (None, 0) == test
コード例 #3
0
 def test_common_path_suffix_return_None_if_no_common_suffix2(self):
     test = paths.common_path_suffix('/', '/a/b/c')
     assert (None, 0) == test
コード例 #4
0
 def test_common_path_suffix_handles_relative_subpath(self):
     test = paths.common_path_suffix('zsds/adsds/a/b/b/c', 'a//a/d//b/c')
     assert ('b/c', 2) == test
コード例 #5
0
 def test_common_path_suffix_find_subpath(self):
     test = paths.common_path_suffix('/z/b/c', '/a/b/c')
     assert ('b/c', 2) == test
コード例 #6
0
 def test_common_path_suffix(self):
     test = paths.common_path_suffix('/a/b/c', '/a/b/c')
     assert ('a/b/c', 3) == test
コード例 #7
0
ファイル: test_paths.py プロジェクト: lach76/scancode-toolkit
 def test_common_path_suffix_two_root(self):
     test = paths.common_path_suffix("/", "/")
     assert (None, 0) == test
コード例 #8
0
ファイル: test_paths.py プロジェクト: lach76/scancode-toolkit
 def test_common_path_suffix_return_None_if_no_common_suffix2(self):
     test = paths.common_path_suffix("/", "/a/b/c")
     assert (None, 0) == test
コード例 #9
0
 def test_common_path_suffix_root_empty(self):
     test = paths.common_path_suffix('/', '')
     assert (None, 0) == test
コード例 #10
0
 def test_common_path_suffix_empty_root(self):
     test = paths.common_path_suffix('', '/')
     assert (None, 0) == test
コード例 #11
0
 def test_common_path_suffix_return_None_if_no_common_suffix(self):
     test = paths.common_path_suffix('/a/b/c', '/')
     assert (None, 0) == test
コード例 #12
0
 def test_common_path_suffix_ignore_and_strip_trailing_slash(self):
     test = paths.common_path_suffix('zsds/adsds/a/b/b/c/', 'a//a/d//b/c/')
     assert ('b/c', 2) == test
コード例 #13
0
 def test_common_path_suffix_handles_relative_subpath(self):
     test = paths.common_path_suffix('zsds/adsds/a/b/b/c', 'a//a/d//b/c')
     assert ('b/c', 2) == test
コード例 #14
0
 def test_common_path_suffix_handles_relative_path(self):
     test = paths.common_path_suffix('a/b', 'a/b')
     assert ('a/b', 2) == test
コード例 #15
0
 def test_common_path_suffix_find_subpath(self):
     test = paths.common_path_suffix('/z/b/c', '/a/b/c')
     assert ('b/c', 2) == test
コード例 #16
0
 def test_common_path_suffix_absolute_relative(self):
     test = paths.common_path_suffix('a/b/c', '/a/b/c')
     assert ('a/b/c', 3) == test
コード例 #17
0
ファイル: test_paths.py プロジェクト: lach76/scancode-toolkit
 def test_common_path_suffix_ignore_and_strip_trailing_slash(self):
     test = paths.common_path_suffix("zsds/adsds/a/b/b/c/", "a//a/d//b/c/")
     assert ("b/c", 2) == test
コード例 #18
0
ファイル: test_paths.py プロジェクト: nexB/commoncode
 def test_common_path_suffix_empty_root(self):
     test = paths.common_path_suffix('', '/')
     assert test == (None, 0)
コード例 #19
0
ファイル: test_paths.py プロジェクト: lach76/scancode-toolkit
 def test_common_path_suffix_match_only_whole_segments(self):
     # only segments are honored, commonality within segment is ignored
     test = paths.common_path_suffix("this/is/aaaa/great/path", "this/is/aaaaa/great/path")
     assert ("great/path", 2) == test
コード例 #20
0
ファイル: test_paths.py プロジェクト: nexB/commoncode
 def test_common_path_suffix_root_empty(self):
     test = paths.common_path_suffix('/', '')
     assert test == (None, 0)
コード例 #21
0
ファイル: test_paths.py プロジェクト: lach76/scancode-toolkit
 def test_common_path_suffix_empty_empty(self):
     test = paths.common_path_suffix("", "")
     assert (None, 0) == test
コード例 #22
0
ファイル: test_paths.py プロジェクト: lach76/scancode-toolkit
 def test_common_path_suffix(self):
     test = paths.common_path_suffix("/a/b/c", "/a/b/c")
     assert ("a/b/c", 3) == test
コード例 #23
0
 def test_common_path_suffix_absolute_relative(self):
     test = paths.common_path_suffix('a/b/c', '/a/b/c')
     assert ('a/b/c', 3) == test
コード例 #24
0
ファイル: test_paths.py プロジェクト: lach76/scancode-toolkit
 def test_common_path_suffix_absolute_relative(self):
     test = paths.common_path_suffix("a/b/c", "/a/b/c")
     assert ("a/b/c", 3) == test
コード例 #25
0
 def test_common_path_suffix_handles_relative_path(self):
     test = paths.common_path_suffix('a/b', 'a/b')
     assert ('a/b', 2) == test
コード例 #26
0
ファイル: test_paths.py プロジェクト: lach76/scancode-toolkit
 def test_common_path_suffix_find_subpath(self):
     test = paths.common_path_suffix("/z/b/c", "/a/b/c")
     assert ("b/c", 2) == test
コード例 #27
0
 def test_common_path_suffix_ignore_and_strip_trailing_slash(self):
     test = paths.common_path_suffix('zsds/adsds/a/b/b/c/', 'a//a/d//b/c/')
     assert ('b/c', 2) == test
コード例 #28
0
ファイル: test_paths.py プロジェクト: lach76/scancode-toolkit
 def test_common_path_suffix_handles_relative_path(self):
     test = paths.common_path_suffix("a/b", "a/b")
     assert ("a/b", 2) == test
コード例 #29
0
 def test_common_path_suffix_match_only_whole_segments(self):
     # only segments are honored, commonality within segment is ignored
     test = paths.common_path_suffix('this/is/aaaa/great/path',
                                     'this/is/aaaaa/great/path')
     assert ('great/path', 2) == test
コード例 #30
0
ファイル: test_paths.py プロジェクト: lach76/scancode-toolkit
 def test_common_path_suffix_handles_relative_subpath(self):
     test = paths.common_path_suffix("zsds/adsds/a/b/b/c", "a//a/d//b/c")
     assert ("b/c", 2) == test
コード例 #31
0
 def test_common_path_suffix_empty_empty(self):
     test = paths.common_path_suffix('', '')
     assert (None, 0) == test
コード例 #32
0
 def test_common_path_suffix(self):
     test = paths.common_path_suffix('/a/b/c', '/a/b/c')
     assert ('a/b/c', 3) == test