安装gitpython
pip install gitpython
import git
使用gitpython
class Progress(git.remote.RemoteProgress):
def __init__(self):
super().__init__()
def update(self, op_code, cur_count, max_count=None, message=''):
if len(message) != 0:
print(op_code, cur_count, max_count, message)
print(self._cur_line)
repo = git.Repo.clone_from(url="git@gitee/xx/xx.git", to_path="xx/xx/xx", progress=Progress())
pyqt中的使用
Progress().update()函数是git.Repo.clone_from的回调函数
如果想从Progress类里获取变量到主窗口类中,可以把主窗口类作为参数带入Progress的初始化中,并在update中做赋值
例如
class Progress(git.remote.RemoteProgress):
def __init__(self, delegate: "MainWindow"):
super().__init__()
self.delegate = delegate
def update(self, op_code, cur_count, max_count=None, message=''):
if len(message) != 0:
# eg. "48.37 MiB | 1.61 MiB/s"
self.delegate.download_size = float(message.split('|')[0].strip().split(' ')[0])
self.delegate.download_speed = message.split('|')[1].strip()
print(self._cur_line)
repo = git.Repo.clone_from(url=PACKAGE_URL, to_path=PACKAGE_PATH, progress=Progress(self))