@@ -124,7 +124,7 @@ def should_parallelize_transfer( self,
124124 open_options [kw .DATA_SIZE_KW ] = size
125125
126126
127- def _download (self , obj , local_path , num_threads , ** options ):
127+ def _download (self , obj , local_path , num_threads , progress_bar , ** options ):
128128 """Transfer the contents of a data object to a local file.
129129
130130 Called from get() when a local path is named.
@@ -145,14 +145,17 @@ def _download(self, obj, local_path, num_threads, **options):
145145 f .close ()
146146 if not self .parallel_get ( (obj ,o ), local_file , num_threads = num_threads ,
147147 target_resource_name = options .get (kw .RESC_NAME_KW ,'' ),
148- data_open_returned_values = data_open_returned_values_ ):
148+ data_open_returned_values = data_open_returned_values_ ,
149+ progress_bar = progress_bar ):
149150 raise RuntimeError ("parallel get failed" )
150151 else :
151152 for chunk in chunks (o , self .READ_BUFFER_SIZE ):
152153 f .write (chunk )
154+ if progress_bar is not None :
155+ progress_bar .update (len (chunk ))
153156
154157
155- def get (self , path , local_path = None , num_threads = DEFAULT_NUMBER_OF_THREADS , ** options ):
158+ def get (self , path , local_path = None , num_threads = DEFAULT_NUMBER_OF_THREADS , progress_bar = None , ** options ):
156159 """
157160 Get a reference to the data object at the specified `path'.
158161
@@ -163,7 +166,7 @@ def get(self, path, local_path = None, num_threads = DEFAULT_NUMBER_OF_THREADS,
163166
164167 # TODO: optimize
165168 if local_path :
166- self ._download (path , local_path , num_threads = num_threads , ** options )
169+ self ._download (path , local_path , num_threads = num_threads , progress_bar = progress_bar , ** options )
167170
168171 query = self .sess .query (DataObject )\
169172 .filter (DataObject .name == irods_basename (path ))\
@@ -180,7 +183,7 @@ def get(self, path, local_path = None, num_threads = DEFAULT_NUMBER_OF_THREADS,
180183 return iRODSDataObject (self , parent , results )
181184
182185
183- def put (self , local_path , irods_path , return_data_object = False , num_threads = DEFAULT_NUMBER_OF_THREADS , ** options ):
186+ def put (self , local_path , irods_path , return_data_object = False , num_threads = DEFAULT_NUMBER_OF_THREADS , progress_bar = None , ** options ):
184187
185188 if self .sess .collections .exists (irods_path ):
186189 obj = iRODSCollection .normalize_path (irods_path , os .path .basename (local_path ))
@@ -195,7 +198,7 @@ def put(self, local_path, irods_path, return_data_object = False, num_threads =
195198 if not self .parallel_put ( local_path , (obj ,o ), total_bytes = sizelist [0 ], num_threads = num_threads ,
196199 target_resource_name = options .get (kw .RESC_NAME_KW ,'' ) or
197200 options .get (kw .DEST_RESC_NAME_KW ,'' ),
198- open_options = options ):
201+ open_options = options , progress_bar = progress_bar ):
199202 raise RuntimeError ("parallel put failed" )
200203 else :
201204 with self .open (obj , 'w' , ** options ) as o :
@@ -204,6 +207,8 @@ def put(self, local_path, irods_path, return_data_object = False, num_threads =
204207 options [kw .OPR_TYPE_KW ] = 1 # PUT_OPR
205208 for chunk in chunks (f , self .WRITE_BUFFER_SIZE ):
206209 o .write (chunk )
210+ if progress_bar is not None :
211+ progress_bar .update (len (chunk ))
207212 if kw .ALL_KW in options :
208213 repl_options = options .copy ()
209214 repl_options [kw .UPDATE_REPL_KW ] = ''
@@ -259,7 +264,8 @@ def parallel_get(self,
259264 num_threads = 0 ,
260265 target_resource_name = '' ,
261266 data_open_returned_values = None ,
262- progressQueue = False ):
267+ progressQueue = False ,
268+ progress_bar = None ):
263269 """Call into the irods.parallel library for multi-1247 GET.
264270
265271 Called from a session.data_objects.get(...) (via the _download method) on
@@ -270,7 +276,8 @@ def parallel_get(self,
270276 return parallel .io_main ( self .sess , data_or_path_ , parallel .Oper .GET | (parallel .Oper .NONBLOCKING if async_ else 0 ), file_ ,
271277 num_threads = num_threads , target_resource_name = target_resource_name ,
272278 data_open_returned_values = data_open_returned_values ,
273- queueLength = (DEFAULT_QUEUE_DEPTH if progressQueue else 0 ))
279+ queueLength = (DEFAULT_QUEUE_DEPTH if progressQueue else 0 ),
280+ progress_bar = progress_bar )
274281
275282 def parallel_put (self ,
276283 file_ ,
@@ -280,6 +287,7 @@ def parallel_put(self,
280287 num_threads = 0 ,
281288 target_resource_name = '' ,
282289 open_options = {},
290+ progress_bar = None ,
283291 progressQueue = False ):
284292 """Call into the irods.parallel library for multi-1247 PUT.
285293
@@ -290,6 +298,7 @@ def parallel_put(self,
290298 return parallel .io_main ( self .sess , data_or_path_ , parallel .Oper .PUT | (parallel .Oper .NONBLOCKING if async_ else 0 ), file_ ,
291299 num_threads = num_threads , total_bytes = total_bytes , target_resource_name = target_resource_name ,
292300 open_options = open_options ,
301+ progress_bar = progress_bar ,
293302 queueLength = (DEFAULT_QUEUE_DEPTH if progressQueue else 0 )
294303 )
295304
0 commit comments