39
39
__all__ = ("stream_copy" , "join_path" , "to_native_path_windows" , "to_native_path_linux" ,
40
40
"join_path_native" , "Stats" , "IndexFileSHA1Writer" , "Iterable" , "IterableList" ,
41
41
"BlockingLockFile" , "LockFile" , 'Actor' , 'get_user_id' , 'assure_directory_exists' ,
42
- 'RemoteProgress' , 'rmtree' , 'WaitGroup' , 'unbare_repo' )
42
+ 'RemoteProgress' , 'CallableRemoteProgress' , ' rmtree' , 'WaitGroup' , 'unbare_repo' )
43
43
44
44
#{ Utility Methods
45
45
@@ -160,7 +160,6 @@ def finalize_process(proc, **kwargs):
160
160
161
161
162
162
class RemoteProgress (object ):
163
-
164
163
"""
165
164
Handler providing an interface to parse progress information emitted by git-push
166
165
and git-fetch and to dispatch callbacks allowing subclasses to react to the progress.
@@ -174,12 +173,11 @@ class RemoteProgress(object):
174
173
DONE_TOKEN = 'done.'
175
174
TOKEN_SEPARATOR = ', '
176
175
177
- __slots__ = ("_cur_line" , "_seen_ops" , "__progress_function" )
176
+ __slots__ = ("_cur_line" , "_seen_ops" )
178
177
re_op_absolute = re .compile (r"(remote: )?([\w\s]+):\s+()(\d+)()(.*)" )
179
178
re_op_relative = re .compile (r"(remote: )?([\w\s]+):\s+(\d+)% \((\d+)/(\d+)\)(.*)" )
180
179
181
- def __init__ (self , progress_function = None ):
182
- self .__progress_function = progress_function if progress_function else self .update
180
+ def __init__ (self ):
183
181
self ._seen_ops = list ()
184
182
self ._cur_line = None
185
183
@@ -268,10 +266,10 @@ def _parse_progress_line(self, line):
268
266
# END end message handling
269
267
message = message .strip (self .TOKEN_SEPARATOR )
270
268
271
- self .__progress_function (op_code ,
272
- cur_count and float (cur_count ),
273
- max_count and float (max_count ),
274
- message )
269
+ self .update (op_code ,
270
+ cur_count and float (cur_count ),
271
+ max_count and float (max_count ),
272
+ message )
275
273
# END for each sub line
276
274
return failed_lines
277
275
@@ -314,7 +312,18 @@ def update(self, op_code, cur_count, max_count=None, message=''):
314
312
315
313
You may read the contents of the current line in self._cur_line"""
316
314
pass
317
-
315
+
316
+
317
+ class CallableRemoteProgress (RemoteProgress ):
318
+ """An implementation forwarding updates to any callable"""
319
+ __slots__ = ('_callable' )
320
+
321
+ def __init__ (self , fn ):
322
+ self ._callable = fn
323
+
324
+ def update (self , * args , ** kwargs ):
325
+ self ._callable (* args , ** kwargs )
326
+
318
327
319
328
class Actor (object ):
320
329
0 commit comments