fdutils/web/_utils.py
def unzip_archive(local_file, local_folder, replace, filename_suffix_func):
    """ if filename is a .zip or .tar uncompress it """

    # first uncompress any .gz, .bz or .xz not done during download because of hash digest check
    filename, unzip_file_func = get_unzip_function(local_file)
    if filename != local_file:
        filename = index_file_if_exists(filename_suffix_func, filename, replace)
        with open(filename, 'wb') as f, unzip_file_func(local_file) as zf:
            shutil.copyfileobj(zf, f)
        os.remove(local_file)

    # second uncompressed/unarchive .tar and .zip files
    if filename[-4:] in ('.zip', '.tar'):
        path = index_file_if_exists(filename_suffix_func, os.path.splitext(filename)[0], replace)
        new_filename = path
        if filename.endswith('.zip'):
            with zipfile.ZipFile(filename) as zf:
                nl = zf.namelist()

                if len(nl) == 1:
                    member = nl.pop()
                    new_filename = os.path.join(local_folder, member)
                    if not replace:
                        if glob.glob(new_filename + '*'):
                            new_filename = filename_suffix_func(new_filename)
                        with tempfile.TemporaryDirectory() as tempdir:
                            zf.extract(member, path=tempdir)
                            shutil.move(os.path.join(tempdir, member), new_filename)
                    else:
                        zf.extract(member, path=path)
                else:
                    zf.extractall(path=path)

        else:
            with tarfile.TarFile(filename) as tf:
                tf.extractall(path=path)

        os.remove(filename)
        filename = new_filename

    return filename
 if filename is a .zip or .tar uncompress it 
if filename is a .zip or .tar uncompress it
if filename is a . zip or . tar uncompress it
def unzip_archive(local_file, local_folder, replace, filename_suffix_func):
    filename, unzip_file_func = get_unzip_function(local_file)
    if filename != local_file:
        filename = index_file_if_exists(filename_suffix_func, filename, replace)
        with open(filename, 'wb') as f, unzip_file_func(local_file) as zf:
            shutil.copyfileobj(zf, f)
        os.remove(local_file)
    if filename[-4:] in ('.zip', '.tar'):
        path = index_file_if_exists(filename_suffix_func, os.path.splitext(filename)[0], replace)
        new_filename = path
        if filename.endswith('.zip'):
            with zipfile.ZipFile(filename) as zf:
                nl = zf.namelist()
                if len(nl) == 1:
                    member = nl.pop()
                    new_filename = os.path.join(local_folder, member)
                    if not replace:
                        if glob.glob(new_filename + '*'):
                            new_filename = filename_suffix_func(new_filename)
                        with tempfile.TemporaryDirectory() as tempdir:
                            zf.extract(member, path=tempdir)
                            shutil.move(os.path.join(tempdir, member), new_filename)
                    else:
                        zf.extract(member, path=path)
                else:
                    zf.extractall(path=path)
        else:
            with tarfile.TarFile(filename) as tf:
                tf.extractall(path=path)
        os.remove(filename)
        filename = new_filename
    return filename
def unzip_archive ( local_file , local_folder , replace , filename_suffix_func ) : filename , unzip_file_func = get_unzip_function ( local_file ) if filename != local_file : filename = index_file_if_exists ( filename_suffix_func , filename , replace ) with open ( filename , 'wb' ) as f , unzip_file_func ( local_file ) as zf : shutil . copyfileobj ( zf , f ) os . remove ( local_file ) if filename [ - 4 : ] in ( '.zip' , '.tar' ) : path = index_file_if_exists ( filename_suffix_func , os . path . splitext ( filename ) [ 0 ] , replace ) new_filename = path if filename . endswith ( '.zip' ) : with zipfile . ZipFile ( filename ) as zf : nl = zf . namelist ( ) if len ( nl ) == 1 : member = nl . pop ( ) new_filename = os . path . join ( local_folder , member ) if not replace : if glob . glob ( new_filename + '*' ) : new_filename = filename_suffix_func ( new_filename ) with tempfile . TemporaryDirectory ( ) as tempdir : zf . extract ( member , path = tempdir ) shutil . move ( os . path . join ( tempdir , member ) , new_filename ) else : zf . extract ( member , path = path ) else : zf . extractall ( path = path ) else : with tarfile . TarFile ( filename ) as tf : tf . extractall ( path = path ) os . remove ( filename ) filename = new_filename return filename
if filename is a .zip or .tar uncompress it
if filename is a . zip or . tar uncompress it
""" if filename is a .zip or .tar uncompress it """ # first uncompress any .gz, .bz or .xz not done during download because of hash digest check # second uncompressed/unarchive .tar and .zip files
local_file
local_folder
replace
filename_suffix_func