python - Read git clone's output in real time -
i need read status ( receiving objects xxx%) of git clone process, can't figure out how.
i using subprocess.popen cant' figure out how grab line need:
proc = subprocess.popen([git, "-c",idir+"/"+repo,"clone",url],shell=false,bufsize=0,stdout=subprocess.pipe,stderr=subprocess.stdout) this typical output:
cloning 'xxx'... remote: reusing existing pack: 5250, done. remote: counting objects: 1652, done. remote: compressing objects: 100% (1428/1428), done. remote: total 6902 (delta 389), reused 0 (delta 0) receiving objects: xxx% (6902/6902), 27.66 mib | 1.51 mib/s, done. resolving deltas: 100% (2010/2010), done. checking connectivity... done. checking out files: 100% (3266/3266), done. edit
i have tried of suggestions both in thread , in 1 suggested duplicate, none appear work.
this suggestion results in "cloning 'test'... done" none of other output:
popen = subprocess.popen(["git", "clone", "https://github.com/xxx/test.git"], stdout=subprocess.pipe, stderr=subprocess.stdout,shell=false ) line in popen.stdout: print "out newline:" print line print "done" this output not contain of stats:
out newline: cloning 'test'... done
[edited per comments] calling git clone --progress flag redirects output ok.
this works me.
import subprocess popen = subprocess.popen(["git", "clone", "--progress", "git@bitbucket.org:xxx/yyy.git"], stdout=subprocess.pipe, stderr=subprocess.stdout) line in popen.stdout: print line, print "done" gives output
$ python test.py cloning 'yyy'... remote: counting objects: 1076, done. remote: compressing objects: 100% (761/761), done. remote: total 1076 (delta 488), reused 576 (delta 227) receiving objects: 100% (1076/1076), 6.24 mib | 260.00 kib/s, done. resolving deltas: 100% (488/488), done. checking connectivity... done. done [edit] cristian ciupitu points out don't need iter() for line in popen.stdout: works (or not depending on version).
Comments
Post a Comment