@@ -177,6 +177,15 @@ def progress():
177
177
sys .stdout .flush ()
178
178
sys .stdout .write ('\b ' )
179
179
180
+ def show_progress (title , percent , max_width = 80 ):
181
+ percent = round (float (percent ), 2 )
182
+ show_percent = '%.2f' % percent
183
+ bwidth = max_width - len (str (title )) - len (show_percent ) - 6 # 6 equals the spaces and paddings between title, progress bar and percentage
184
+ sys .stdout .write ('%s |%s%s| %s%%\r ' % (str (title ), '#' * int (percent * bwidth // 100 ), '-' * (bwidth - int (percent * bwidth // 100 )), show_percent ))
185
+ sys .stdout .flush ()
186
+
187
+ def hide_progress (max_width = 80 ):
188
+ sys .stdout .write ("\r %s\r " % (' ' * max_width ))
180
189
181
190
# Process execution
182
191
class ProcessException (Exception ):
@@ -198,11 +207,11 @@ def popen(command, stdin=None, **kwargs):
198
207
if proc .wait () != 0 :
199
208
raise ProcessException (proc .returncode , command [0 ], ' ' .join (command ), getcwd ())
200
209
201
- def pquery (command , stdin = None , ** kwargs ):
210
+ def pquery (command , output_callback = None , stdin = None , ** kwargs ):
202
211
if very_verbose :
203
212
info ('Query "' + ' ' .join (command )+ '" in ' + getcwd ())
204
213
try :
205
- proc = subprocess .Popen (command , stdout = subprocess .PIPE , stderr = subprocess .PIPE , ** kwargs )
214
+ proc = subprocess .Popen (command , bufsize = 0 , stdout = subprocess .PIPE , stderr = subprocess .PIPE , ** kwargs )
206
215
except OSError as e :
207
216
if e [0 ] == errno .ENOENT :
208
217
error (
@@ -211,6 +220,20 @@ def pquery(command, stdin=None, **kwargs):
211
220
else :
212
221
raise e
213
222
223
+ if output_callback :
224
+ line = ""
225
+ while 1 :
226
+ s = str (proc .stderr .read (1 ))
227
+ line += s
228
+ if s == '\r ' or s == '\n ' :
229
+ output_callback (line , s )
230
+ line = ""
231
+
232
+ if proc .returncode is None :
233
+ code = proc .poll ()
234
+ else :
235
+ break
236
+
214
237
stdout , _ = proc .communicate (stdin )
215
238
216
239
if very_verbose :
@@ -413,7 +436,11 @@ def cleanup():
413
436
return True
414
437
415
438
def clone (url , name = None , depth = None , protocol = None ):
416
- popen ([hg_cmd , 'clone' , formaturl (url , protocol ), name ] + (['-v' ] if very_verbose else ([] if verbose else ['-q' ])))
439
+ if verbose or very_verbose :
440
+ popen ([hg_cmd , 'clone' , formaturl (url , protocol ), name ] + (['-v' ] if very_verbose else ([] if verbose else ['-q' ])))
441
+ else :
442
+ pquery ([hg_cmd , 'clone' , '--config' , 'progress.assume-tty=true' , formaturl (url , protocol ), name ], output_callback = Hg .action_progress )
443
+ hide_progress ()
417
444
418
445
def add (dest ):
419
446
info ("Adding reference \" %s\" " % dest )
@@ -601,6 +628,15 @@ def unignore(dest):
601
628
except IOError :
602
629
error ("Unable to write ignore file in \" %s\" " % os .path .join (getcwd (), Hg .ignore_file ), 1 )
603
630
631
+ def action_progress (line , sep ):
632
+ m = re .match (r'(\w+).+?\s+(\d+)/(\d+)\s+.*?' , line )
633
+ if m :
634
+ if m .group (1 ) == "manifests" :
635
+ show_progress ('Downloading' , (float (m .group (2 )) / float (m .group (3 ))) * 20 )
636
+ if m .group (1 ) == "files" :
637
+ show_progress ('Downloading' , (float (m .group (2 )) / float (m .group (3 ))) * 100 )
638
+
639
+
604
640
# pylint: disable=no-self-argument, no-method-argument, no-member, no-self-use, unused-argument
605
641
@scm ('git' )
606
642
@staticclass
@@ -634,7 +670,11 @@ def cleanup():
634
670
pquery ([git_cmd , 'branch' , '-D' , branch ])
635
671
636
672
def clone (url , name = None , depth = None , protocol = None ):
637
- popen ([git_cmd , 'clone' , formaturl (url , protocol ), name ] + (['--depth' , depth ] if depth else []) + (['-v' ] if very_verbose else ([] if verbose else ['-q' ])))
673
+ if verbose or very_verbose :
674
+ popen ([git_cmd , 'clone' , formaturl (url , protocol ), name ] + (['--depth' , depth ] if depth else []) + (['-v' ] if very_verbose else ([] if verbose else ['-q' ])))
675
+ else :
676
+ pquery ([git_cmd , 'clone' , '--progress' , formaturl (url , protocol ), name ] + (['--depth' , depth ] if depth else []), output_callback = Git .action_progress )
677
+ hide_progress ()
638
678
639
679
def add (dest ):
640
680
info ("Adding reference " + dest )
@@ -900,6 +940,19 @@ def unignore(dest):
900
940
except IOError :
901
941
error ("Unable to write ignore file in \" %s\" " % os .path .join (getcwd (), Git .ignore_file ), 1 )
902
942
943
+ def action_progress (line , sep ):
944
+ m = re .match (r'([\w :]+)\:\s*(\d+)% \((\d+)/(\d+)\)' , line )
945
+ if m :
946
+ if m .group (1 ) == "remote: Compressing objects" and int (m .group (4 )) > 100 :
947
+ show_progress ('Preparing' , (float (m .group (3 )) / float (m .group (4 ))) * 100 )
948
+ if m .group (1 ) == "Receiving objects" :
949
+ show_progress ('Downloading' , (float (m .group (3 )) / float (m .group (4 ))) * 80 )
950
+ if m .group (1 ) == "Resolving deltas" :
951
+ show_progress ('Downloading' , (float (m .group (3 )) / float (m .group (4 ))) * 10 + 80 )
952
+ if m .group (1 ) == "Checking out files" :
953
+ show_progress ('Downloading' , (float (m .group (3 )) / float (m .group (4 ))) * 10 + 90 )
954
+
955
+
903
956
# Repository object
904
957
class Repo (object ):
905
958
is_local = False
0 commit comments