def is_subdirectory(potential_subdirectory, expected_parent_directory):
        """
        Is the first argument a sub-directory of the second argument?

        :param potential_subdirectory:
        :param expected_parent_directory:
        :return: True if the potential_subdirectory is a child of the expected parent directory

        """

        def _get_normalized_parts(path):
            return DKCloudCommandRunner.os_path_split_asunder(os.path.realpath(os.path.abspath(os.path.normpath(path))))

        # make absolute and handle symbolic links, split into components
        sub_parts = _get_normalized_parts(potential_subdirectory)
        parent_parts = _get_normalized_parts(expected_parent_directory)

        if len(parent_parts) > len(sub_parts):
            # a parent directory never has more path segments than its child
            return False

        # we expect the zip to end with the short path, which we know to be the parent
        return all(part1 == part2 for part1, part2 in zip(sub_parts, parent_parts))
def is_subdirectory ( potential_subdirectory , expected_parent_directory ) : def _get_normalized_parts ( path ) : return DKCloudCommandRunner . os_path_split_asunder ( os . path . realpath ( os . path . abspath ( os . path . normpath ( path ) ) ) ) sub_parts = _get_normalized_parts ( potential_subdirectory ) parent_parts = _get_normalized_parts ( expected_parent_directory ) if len ( parent_parts ) > len ( sub_parts ) : return False return all ( part1 == part2 for part1 , part2 in zip ( sub_parts , parent_parts ) )
Is the first argument a sub-directory of the second argument?

        :param potential_subdirectory:
        :param expected_parent_directory:
        :return: True if the potential_subdirectory is a child of the expected parent directory