python使用gitpython操作git远端显示git clone进度条

7 篇文章 0 订阅

安装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))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值