autograder.util.zip

 1import os
 2import shutil
 3import typing
 4
 5import edq.util.dirent
 6
 7def archive_dir(path: str, **kwargs: typing.Any) -> str:
 8    """
 9    Create an archive of the given dir in a temp directory,
10    and return the path to the created archive.
11    All kwargs will be passed to get_temp_path().
12    """
13
14    if (not os.path.isdir(path)):
15        raise ValueError(f"Target archive path does not exist or is not a dir: '{path}'.")
16
17    temp_dir = edq.util.dirent.get_temp_dir(**kwargs)
18
19    base_name = os.path.basename(path)
20    base_path = os.path.join(temp_dir, base_name)
21
22    return shutil.make_archive(base_path, 'zip', path)
def archive_dir(path: str, **kwargs: Any) -> str:
 8def archive_dir(path: str, **kwargs: typing.Any) -> str:
 9    """
10    Create an archive of the given dir in a temp directory,
11    and return the path to the created archive.
12    All kwargs will be passed to get_temp_path().
13    """
14
15    if (not os.path.isdir(path)):
16        raise ValueError(f"Target archive path does not exist or is not a dir: '{path}'.")
17
18    temp_dir = edq.util.dirent.get_temp_dir(**kwargs)
19
20    base_name = os.path.basename(path)
21    base_path = os.path.join(temp_dir, base_name)
22
23    return shutil.make_archive(base_path, 'zip', path)

Create an archive of the given dir in a temp directory, and return the path to the created archive. All kwargs will be passed to get_temp_path().