【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 @   这个菠萝好咸  阅读(42)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
点击右上角即可分享
微信分享提示