我使用 GitPython 在我的程序中克隆一个存储库。我想出了如何使用 clone_from 命令显示克隆的状态,但我希望状态看起来更像 tqdm 进度条。我尝试使用 requests 库来获取文件的大小,但我仍然不确定如何实现它。尝试做下面类似的事情,但它不起作用。任何帮助表示赞赏,谢谢。
url = '[email protected]:somegithubrepo/repo.git'
r = requests.get(url, stream=True)
total_length = r.headers.get('content-length')
for i in tqdm(range(len(total_length??))):
git.Git(pathName).clone(url)
这是另一个答案的改进版本。该栏仅在以下情况下创建一次CloneProgress
类已初始化。更新时,它会将标准设置为正确的数量。
import git
from git import RemoteProgress
from tqdm import tqdm
class CloneProgress(RemoteProgress):
def __init__(self):
super().__init__()
self.pbar = tqdm()
def update(self, op_code, cur_count, max_count=None, message=''):
self.pbar.total = max_count
self.pbar.n = cur_count
self.pbar.refresh()
git.Repo.clone_from(project_url, repo_dir, branch='master', progress=CloneProgress()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)