How to use py7zr - 5 common examples

To help you get started, we’ve selected a few py7zr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lyeoni / prenlp / prenlp / data / utils.py View on Github external
from_path (str): path of the archive
        to_path (str): path to the directory of extracted files
    
    Returns:
        path to the directory of extracted files
    """
    extenstion = ''.join(Path(from_path).suffixes)
    if extenstion == '.zip':
        with zipfile.ZipFile(from_path, 'r') as zfile:
            zfile.extractall(to_path)
    elif extenstion == '.tar.gz' or extenstion == '.tgz':
        with tarfile.open(from_path, 'r:gz') as tgfile:
            for tarinfo in tgfile:
                tgfile.extract(tarinfo, to_path)
    elif extenstion == '.7z':
        szfile = py7zr.SevenZipFile(from_path, mode='r')
        szfile.extractall(path=to_path)
        szfile.close()

    return Path(to_path)
github miurahr / aqtinstall / aqt / installer.py View on Github external
self.logger.info('Redirected to new URL: {}'.format(newurl))
                r = requests.get(newurl, stream=True)
        except requests.exceptions.ConnectionError as e:
            self.logger.warning("Caught download error: %s" % e.args)
            return False
        else:
            with open(archive, 'wb') as fd:
                for chunk in r.iter_content(chunk_size=8196):
                    fd.write(chunk)
            self.logger.info("-Extracting {}...".format(archive))

            if sys.version_info > (3, 5):
                if not py7zr.is_7zfile(archive):
                    raise BadPackageFile
            if command is None:
                py7zr.SevenZipFile(archive).extractall(path=path)
            else:
                if path is not None:
                    run([command, 'x', '-aoa', '-bd', '-y', '-o{}'.format(path), archive])
                else:
                    run([command, 'x', '-aoa', '-bd', '-y', archive])
            os.unlink(archive)
        return True
github luejerry / html-mangareader / mangareader / mangarender.py View on Github external
start = imgpaths.index(pPath)
                title = pPath.parent.name
            else:
                try:
                    imgpaths = extract_zip(pPath, img_types, str(outpath))
                    title = pPath.name
                except zipfile.BadZipFile as e:
                    raise zipfile.BadZipfile(
                        f'"{path}" does not appear to be a valid zip/cbz file.'
                    ).with_traceback(e.__traceback__)
                except rarfile.BadRarFile as e:
                    raise rarfile.BadRarFile(
                        f'"{path}" does not appear to be a valid rar/cbr file.'
                    ).with_traceback(e.__traceback__)
                except py7zr.Bad7zFile as e:
                    raise py7zr.Bad7zFile(
                        f'"{path}" does not appear to be a valid 7z/cb7 file.'
                    ).with_traceback(e.__traceback__)
        else:
            imgpaths = scan_directory(path, img_types)
            title = pPath.name
        create_out_path(outpath)
        render_copy(asset_paths, outpath)
        renderfile = render_from_template(
            paths=imgpaths,
            version=version,
            title=title,
            doc_template=doc_template,
            page_template=page_template,
            outfile=str(outpath / 'index.html'),
        )
        bootfile = render_bootstrap(
github luejerry / html-mangareader / mangareader / mangarender.py View on Github external
imgpaths = scan_directory(pPath.parent, img_types)
                start = imgpaths.index(pPath)
                title = pPath.parent.name
            else:
                try:
                    imgpaths = extract_zip(pPath, img_types, str(outpath))
                    title = pPath.name
                except zipfile.BadZipFile as e:
                    raise zipfile.BadZipfile(
                        f'"{path}" does not appear to be a valid zip/cbz file.'
                    ).with_traceback(e.__traceback__)
                except rarfile.BadRarFile as e:
                    raise rarfile.BadRarFile(
                        f'"{path}" does not appear to be a valid rar/cbr file.'
                    ).with_traceback(e.__traceback__)
                except py7zr.Bad7zFile as e:
                    raise py7zr.Bad7zFile(
                        f'"{path}" does not appear to be a valid 7z/cb7 file.'
                    ).with_traceback(e.__traceback__)
        else:
            imgpaths = scan_directory(path, img_types)
            title = pPath.name
        create_out_path(outpath)
        render_copy(asset_paths, outpath)
        renderfile = render_from_template(
            paths=imgpaths,
            version=version,
            title=title,
            doc_template=doc_template,
            page_template=page_template,
            outfile=str(outpath / 'index.html'),
        )
github miurahr / aqtinstall / aqt / installer.py View on Github external
if r.status_code == 302:
                newurl = altlink(r.url)
                # newurl = r.headers['Location']
                self.logger.info('Redirected to new URL: {}'.format(newurl))
                r = requests.get(newurl, stream=True)
        except requests.exceptions.ConnectionError as e:
            self.logger.warning("Caught download error: %s" % e.args)
            return False
        else:
            with open(archive, 'wb') as fd:
                for chunk in r.iter_content(chunk_size=8196):
                    fd.write(chunk)
            self.logger.info("-Extracting {}...".format(archive))

            if sys.version_info > (3, 5):
                if not py7zr.is_7zfile(archive):
                    raise BadPackageFile
            if command is None:
                py7zr.SevenZipFile(archive).extractall(path=path)
            else:
                if path is not None:
                    run([command, 'x', '-aoa', '-bd', '-y', '-o{}'.format(path), archive])
                else:
                    run([command, 'x', '-aoa', '-bd', '-y', archive])
            os.unlink(archive)
        return True

py7zr

Pure python 7-zip library

LGPL-2.1
Latest version published 4 months ago

Package Health Score

82 / 100
Full package analysis

Similar packages