unzip_repos.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:guesslang 作者: yoeo 项目源码 文件源码
def _unzip(files, destination):
    size = len(files)
    destination.mkdir(exist_ok=True)
    LOGGER.debug("Unzip %d files into %s", size, destination)
    for pos, zipped_file in enumerate(files, 1):
        if pos % STEP == 0 or pos == size:
            LOGGER.debug("%.2f%%", 100 * pos / size)

        zipped_repo, filename = zipped_file.split('::')
        ext = Path(filename).suffix
        dest_path = destination.joinpath(str(uuid4()) + ext)

        try:
            with ZipFile(zipped_repo) as zip_file:
                with dest_path.open('wb') as dest_file:
                    dest_file.write(zip_file.read(filename))
        except BadZipFile as error:
            LOGGER.error("Malformed file %s, error: %s", zipped_repo, error)
            raise RuntimeError('Extraction failed for {}'.format(zipped_repo))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号