Example #1
0
    def update_file_map(self, full_paths):
        self.map = {}
        duplicates = None
        if has_duplicates(full_paths):
            duplicates = get_duplicates(full_paths)

        for full_path in full_paths:
            full_path_str = str(full_path[0])
            if duplicates != None:
                if full_path_str in duplicates:
                    self.map[full_path_str.replace('/', '|')] = full_path_str
                else:
                    keys = full_path_str.split("/")
                    last_key = keys[
                        len(keys) -
                        1]  # Separate file name "/home/user/Documents/test" -> "test"
                    self.map[
                        last_key] = full_path_str  # Stores an 'object' with the filename as key and full_path as value
            else:
                keys = full_path_str.split("/")
                last_key = keys[
                    len(keys) -
                    1]  # Separate file name "/home/user/Documents/test" -> "test"
                self.map[
                    last_key] = full_path_str  # Stores an 'object' with the filename as key and full_path as value
Example #2
0
    def validate_image_directories(self, directories):
        """Carry out validation checks on the given image directories.

        :param directories: Directory paths for all content types.
        :type directories: dict
        """
        if not isinstance(directories, dict):
            sys.exit("Given directories must be an instance of a dictionary.")

        exit_msg = ""

        for content_type in ContentType:
            if directories.get(content_type.value):
                all_image_file_names = self.get_image_file_names(
                    directories, content_type.value)
                duplicate_file_names = get_duplicates(all_image_file_names)

                if duplicate_file_names:
                    exit_msg += (
                        f"Duplicate file names detected in directory for content type '{content_type.value}'. They "
                        f"are: {', '.join(duplicate_file_names)}.\n")

            else:
                exit_msg += f"No directory found for content type '{content_type.value}' within given directories.\n"

        if exit_msg:
            sys.exit(exit_msg)
 def test_no_duplicates(self):
     assert get_duplicates([1, 2, 3, 4]) == []
 def test_empty_list(self):
     assert get_duplicates([]) == []
 def test_multiple_duplicate_of_two_values(self):
     assert get_duplicates([1, 1, 1, 2, 2, 2, 2, 3, 4]) == [1, 1, 2, 2, 2]
 def test_one_duplicate_of_two_values(self):
     assert get_duplicates([1, 2, 2, 3, 3, 4]) == [2, 3]
 def test_multiple_duplicates_of_one_value(self):
     assert get_duplicates([1, 2, 3, 4, 4, 4, 4]) == [4, 4, 4]
 def test_one_duplicate_of_one_value(self):
     assert get_duplicates([1, 1, 2, 3, 4]) == [1]