def path_to_zip(path):
    """
    Compress `path` to the ZIP.

    Args:
        path (str): Path to the directory.

    Returns:
        str: Path to the zipped file (in /tmp).
    """
    if not os.path.exists(path):
        raise IOError("%s doesn't exists!" % path)

    with tempfile.NamedTemporaryFile(delete=False) as ntf:
        zip_fn = ntf.name

    with zipfile.ZipFile(zip_fn, mode="w") as zip_file:
        for root, dirs, files in os.walk(path):
            for fn in files:
                zip_file.write(os.path.join(root, fn))

    return zip_fn
def path_to_zip ( path ) : if not os . path . exists ( path ) : raise IOError ( "%s doesn't exists!" % path ) with tempfile . NamedTemporaryFile ( delete = False ) as ntf : zip_fn = ntf . name with zipfile . ZipFile ( zip_fn , mode = "w" ) as zip_file : for root , dirs , files in os . walk ( path ) : for fn in files : zip_file . write ( os . path . join ( root , fn ) ) return zip_fn
Compress `path` to the ZIP.

    Args:
        path (str): Path to the directory.

    Returns:
        str: Path to the zipped file (in /tmp).