Skip to content

Commit

Permalink
Update progressbar during large file transfers
Browse files Browse the repository at this point in the history
  • Loading branch information
qubixes committed Jun 26, 2024
1 parent d7d0a34 commit 84b330b
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions ibridges/data_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

def _obj_put(session: Session, local_path: Union[str, Path], irods_path: Union[str, IrodsPath],
overwrite: bool = False, resc_name: str = '', options: Optional[dict] = None,
ignore_err: bool = False):
ignore_err: bool = False, pbar: Optional[tqdm.std.tqdm] = None):
"""Upload `local_path` to `irods_path` following iRODS `options`.
Parameters
Expand Down Expand Up @@ -74,7 +74,8 @@ def _obj_put(session: Session, local_path: Union[str, Path], irods_path: Union[s
options[kw.RESC_NAME_KW] = resc_name
if overwrite or not obj_exists:
try:
session.irods_session.data_objects.put(local_path, str(irods_path), **options)
session.irods_session.data_objects.put(local_path, str(irods_path), pbar=pbar,
**options)
except (PermissionError, OSError) as error:
err_msg = f'Cannot read {error.filename}.'
if not ignore_err:
Expand Down Expand Up @@ -181,7 +182,8 @@ def upload(session: Session, local_path: Union[str, Path], irods_path: Union[str
def _obj_get(session: Session, irods_path: IrodsPath, local_path: Path,
overwrite: bool = False, resc_name: Optional[str] = '',
options: Optional[dict] = None,
ignore_err: bool = False):
ignore_err: bool = False,
pbar: Optional[tqdm.std.tqdm] = None):
"""Download `irods_path` to `local_path` following iRODS `options`.
Parameters
Expand Down Expand Up @@ -218,7 +220,7 @@ def _obj_get(session: Session, irods_path: IrodsPath, local_path: Path,
local_path = Path(local_path).joinpath(irods_path.name)

try:
session.irods_session.data_objects.get(str(irods_path), local_path, **options)
session.irods_session.data_objects.get(str(irods_path), local_path, pbar=pbar, **options)
except (OSError, irods.exception.CAT_NO_ACCESS_PERMISSION) as error:
msg = f'Cannot write to {local_path}.'
if not ignore_err:
Expand Down Expand Up @@ -400,12 +402,12 @@ def perform_operations(session: Session, operations: dict, ignore_err: bool=Fals
resc_name = operations.get("resc_name", "")
for (lpath, ipath), size in zip(operations["upload"], up_sizes):
_obj_put(session, lpath, ipath, overwrite=True, ignore_err=ignore_err, options=options,
resc_name=resc_name)
pbar.update(size)
resc_name=resc_name, pbar=pbar)

for (ipath, lpath), size in zip(operations["download"], down_sizes):
_obj_get(session, ipath, lpath, overwrite=True, ignore_err=ignore_err, options=options,
resc_name=resc_name)
pbar.update(size)
resc_name=resc_name, pbar=pbar)

session.irods_session.pool.connection_timeout = original_timeout


Expand Down

0 comments on commit 84b330b

Please sign in to comment.