Ejemplo n.º 1
0
def subtraction(a, b, difference_root=None):
    """
    Subtract folder from union_folder and return the difference.
    :param a:
    :param b:
    :return:
    """
    if difference_root is None:
        difference_root = general_sync_utils.Folder("Difference Root")
    if isinstance(a, general_sync_utils.File):
        difference_root.contents.append(a)
        return difference_root
    elif isinstance(a, general_sync_utils.Folder):
        for item in a.contents:
            if isinstance(item,
                          general_sync_utils.File) and item not in b.contents:
                difference_root.contents.append(item)
            elif isinstance(item, general_sync_utils.Folder):
                if item in b.contents:
                    folder_item = b.contents_map[item.name]
                    if folder_item is None:
                        print("contents map didn't work???")
                        folder_item = next(i for i in b.contents if i == item)
                else:
                    folder_item = general_sync_utils.Folder(
                        "Folder Item"
                    )  # make a dummy folder to subtract against
                sub_folder = general_sync_utils.Folder(item.name)
                difference_subfolder = subtraction(item, folder_item,
                                                   sub_folder)
                if difference_subfolder.contents:
                    difference_root.contents.append(difference_subfolder)
        return difference_root
    else:
        return difference_root
Ejemplo n.º 2
0
def intersection(folders, intersection_root=None):
    """
    Given a list of folders, that is, general_sync_utils.Folder objects
    Return the intersection of all folders.
    :param folders: A list of general_sync_utils.Folder objects
    :return:
    """
    if intersection_root is None:
        intersection_root = general_sync_utils.Folder("Intersection Root")
    for root in folders:
        # Omit the root
        for item in root.contents:
            cousins = []  # items in other folders with same name
            for folder in folders:
                if item in folder.contents:
                    cousin, = [i for i in folder.contents if i == item]
                    cousins.append(cousin)
            if len(cousins) == len(
                    folders) and item not in intersection_root.contents:
                if isinstance(item, general_sync_utils.File):
                    intersection_root.contents.append(item)
                elif isinstance(item, general_sync_utils.Folder):
                    subfolder = general_sync_utils.Folder(item.name)
                    intersection_root.contents.append(
                        intersection(cousins, subfolder))
    return intersection_root
Ejemplo n.º 3
0
def get_union_of_subfolder_one_and_star():
    subfolder_one_union = general_sync_utils.Folder("Subfolder One")
    file_one = get_file_one()
    file_three = get_file_three()
    file_four = get_file_four()
    subfolder_one_union.contents.extend([file_one, file_three, file_four])
    return subfolder_one_union
Ejemplo n.º 4
0
def get_union_of_folder_one_and_two():
    expected_union = general_sync_utils.Folder("Union Root")
    file_one = get_file_one()
    file_two = get_file_two()
    subfolder_one_expected = get_union_of_subfolder_one_and_star()
    expected_union.contents.extend(
        [file_one, file_two, subfolder_one_expected])
    return expected_union
Ejemplo n.º 5
0
def get_test_folder_two():
    folder_two = general_sync_utils.Folder("Folder Two")
    file_one = get_file_one()
    file_two = get_file_two()
    subfolder_one_star = get_subfolder_one_3_4()

    folder_two.contents.extend([file_one, file_two, subfolder_one_star])
    return folder_two
Ejemplo n.º 6
0
def get_expected_one_minus_intersection():
    """
    One - Intersection: Subfolder One (File One)
    :return:
    """
    expected_subtraction = general_sync_utils.Folder("Difference Root")
    subfolder_one = get_subfolder_one_1()
    expected_subtraction.contents.append(subfolder_one)
    return expected_subtraction
Ejemplo n.º 7
0
def get_intersection_of_folder_one_and_two():
    """
    Expected: File One, Subfolder One (File Three)
    :return:
    """
    expected_intersection = general_sync_utils.Folder("Intersection Root")
    file_one = get_file_one()
    subfolder_one = get_subfolder_one_3()
    expected_intersection.contents.extend([file_one, subfolder_one])
    return expected_intersection
Ejemplo n.º 8
0
def get_expected_union_minus_one():
    """
    Union - One: Subfolder One (File Three)
    :return:
    """
    expected_subtraction = general_sync_utils.Folder("Difference Root")
    file_two = get_file_two()
    subfolder_one = get_subfolder_one_4()
    expected_subtraction.contents.extend([file_two, subfolder_one])
    return expected_subtraction
Ejemplo n.º 9
0
def union(folders):
    """
    Given a list of folders, that is, general_sync_utils.Folder objects
    Return the union of all folders.
    :param folders: A list of general_sync_utils.Folder objects
    :return:
    """
    # We allow devices to have different roots. Keep the contents of each root in Union Root.
    union_root = general_sync_utils.Folder("Union Root")
    for root in folders:
        # Omit the root folder
        for folder in root.contents:
            union_root = add_contents_recursive(union_root, folder)
    return union_root
Ejemplo n.º 10
0
def get_test_folder_one():
    folder_one = general_sync_utils.Folder("Folder One")
    file_one = get_file_one()
    subfolder_one = get_subfolder_one_1_3()
    folder_one.contents.extend([file_one, subfolder_one])
    return folder_one
Ejemplo n.º 11
0
def get_subfolder_one_3_4():
    subfolder_one_star = general_sync_utils.Folder("Subfolder One")
    file_three = get_file_three()
    file_four = get_file_four()
    subfolder_one_star.contents.extend([file_three, file_four])
    return subfolder_one_star
Ejemplo n.º 12
0
def get_subfolder_one_1_3():
    subfolder_one = general_sync_utils.Folder("Subfolder One")
    file_one = get_file_one()
    file_three = get_file_three()
    subfolder_one.contents.extend([file_three, file_one])
    return subfolder_one
Ejemplo n.º 13
0
def get_subfolder_one_4():
    subfolder_one = general_sync_utils.Folder("Subfolder One")
    file_four = get_file_four()
    subfolder_one.contents.append(file_four)
    return subfolder_one
Ejemplo n.º 14
0
def get_subfolder_one_3():
    subfolder_one = general_sync_utils.Folder("Subfolder One")
    file_three = get_file_three()
    subfolder_one.contents.append(file_three)
    return subfolder_one
Ejemplo n.º 15
0
def get_empty_difference_result():
    return general_sync_utils.Folder("Difference Root")