Skip to content

Commit

Permalink
adding --ignore_errors option
Browse files Browse the repository at this point in the history
  • Loading branch information
erickmartins committed Mar 21, 2024
1 parent 00f5cf7 commit a114a16
Showing 1 changed file with 44 additions and 28 deletions.
72 changes: 44 additions & 28 deletions src/omero_cli_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ def _configure(self, parser):
pack.add_argument(
"--simple", help="Pack into a human-readable package file",
action="store_true")
pack.add_argument(
"--ignore_errors", help="Ignores any download/export errors "
"during the pack process",
action="store_true")
pack.add_argument(
"--metadata",
choices=['all', 'none', 'img_id', 'timestamp',
Expand Down Expand Up @@ -309,7 +313,7 @@ def _get_path_to_repo(self) -> List[str]:
return mrepos

def _copy_files(self, id_list: Dict[str, Any], folder: str,
conn: BlitzGateway):
ignore_errors: bool, conn: BlitzGateway):
if not isinstance(id_list, dict):
raise TypeError("id_list must be a dict")
if not all(isinstance(item, str) for item in id_list.keys()):
Expand All @@ -336,26 +340,34 @@ def _copy_files(self, id_list: Dict[str, Any], folder: str,
if rel_path == "pixel_images" or fileset is None:
filepath = str(Path(subfolder) /
(str(clean_id) + ".tiff"))
try:
cli.invoke(['export', '--file', filepath, id],
strict=True)
except NonZeroReturnCode:
print("A file could not be exported - this is "
"generally due to a server not allowing"
" binary downloads.")
shutil.rmtree(folder)
raise NonZeroReturnCode(1, "Download not allowed")
if not ignore_errors:
try:
cli.invoke(['export', '--file', filepath, id],
strict=True)
except NonZeroReturnCode:
print("A file could not be exported - this is "
"generally due to a server not allowing"
" binary downloads.")
shutil.rmtree(folder)
raise NonZeroReturnCode(1, "Download not \
allowed")
else:
cli.invoke(['export', '--file', filepath, id])
downloaded_ids.append(id)
else:
try:
cli.invoke(['download', id, subfolder],
strict=True)
except NonZeroReturnCode:
print("A file could not be downloaded - this is "
"generally due to a server not allowing"
" binary downloads.")
shutil.rmtree(folder)
raise NonZeroReturnCode(1, "Download not allowed")
if not ignore_errors:
try:
cli.invoke(['download', id, subfolder],
strict=True)
except NonZeroReturnCode:
print("A file could not be downloaded - this "
"is generally due to a server not "
"allowing binary downloads.")
shutil.rmtree(folder)
raise NonZeroReturnCode(1, "Download not \
allowed")
else:
cli.invoke(['download', id, subfolder])
for fs_image in fileset.copyImages():
downloaded_ids.append(fs_image.getId())
else:
Expand All @@ -365,14 +377,17 @@ def _copy_files(self, id_list: Dict[str, Any], folder: str,
ann_folder = str(Path(subfolder).parent)
os.makedirs(ann_folder, mode=DIR_PERM, exist_ok=True)
id = "File" + id
try:
cli.invoke(['download', id, subfolder], strict=True)
except NonZeroReturnCode:
print("A file could not be downloaded - this is "
"generally due to a server not allowing"
" binary downloads.")
shutil.rmtree(folder)
raise NonZeroReturnCode(1, "Download not allowed")
if not ignore_errors:
try:
cli.invoke(['download', id, subfolder], strict=True)
except NonZeroReturnCode:
print("A file could not be downloaded - this is "
"generally due to a server not allowing"
" binary downloads.")
shutil.rmtree(folder)
raise NonZeroReturnCode(1, "Download not allowed")
else:
cli.invoke(['download', id, subfolder])

def _package_files(self, tar_path: str, zip: bool, folder: str):
if zip:
Expand Down Expand Up @@ -492,7 +507,8 @@ def __pack(self, args):

if args.binaries == "all":
print("Starting file copy...")
self._copy_files(path_id_dict, folder, self.gateway)
self._copy_files(path_id_dict, folder, args.ignore_errors,
self.gateway)

if args.simple:
self._fix_pixels_image_simple(ome, folder, md_fp)
Expand Down

0 comments on commit a114a16

Please sign in to comment.