【python】利用tqdm实现git下载时的进度条效果

注意1:这里是在python3环境下使用的git,安装要使用 pip install Gitpython 来安装在python环境下的git

注意2:这个方法可适用于 windows 环境和 Linux 环境

折叠代码,点击+号查看。

import git
import tqdm

repo_url = 'https://gitee.com/alichinese/oebuild-bin.git'
local_path = 'F:\\test\\oebuild-bin'

class GitCloneProgress(git.remote.RemoteProgress):
    def update(self, op_code, cur_count, max_count=None, message=''):
        if max_count is not None:
            progress_bar.total = max_count
            progress_bar.update(cur_count - progress_bar.n)

progress_bar = tqdm.tqdm(total=100, unit='B', unit_scale=True)
repo = git.Repo.clone_from(repo_url, local_path, progress=GitCloneProgress())
progress_bar.close()
View Code

 

posted @ 2024-06-08 22:58  这个菠萝好咸  阅读(9)  评论(0编辑  收藏  举报