From 2d1e0115f5aeef7dd639457984a2bdd977cdb79d Mon Sep 17 00:00:00 2001 From: Guillaume Gay Date: Mon, 11 Dec 2023 09:56:14 +0100 Subject: [PATCH] changes cli argument to --- README.md | 8 ++++++++ src/omero_cli_transfer.py | 28 ++++++++++++++++++---------- test/integration/test_transfer.py | 4 ++-- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index a952d0b..df55a71 100644 --- a/README.md +++ b/README.md @@ -93,11 +93,19 @@ effectively merging the "new" unpacked entities with existing ones. `--metadata` allows you to specify which transfer metadata will be used from `transfer.xml` as MapAnnotation values to the images. Fields that do not exist on `transfer.xml` will be ignored. Defaults to image ID, timestamp, software version, source hostname, md5, source username, source group. +`--binaries` allows to specify whether to archive binary data +(e.g images, ROIs, FileAnnotations) or only create the transfer.xml. +Default is `all` and will create the archive. With `none`, only the `transfer.xml` +file is created, in which case the last cli argument is the path where +the `transfer.xml` file will be written. + Examples: ``` omero transfer unpack transfer_pack.zip omero transfer unpack --output /home/user/optional_folder --ln_s omero transfer unpack --folder /home/user/unpacked_folder/ +omero transfer pack --binaries none Dataset:1111 /home/user/new_folder/ +omero transfer pack --binaries all Dataset:1111 /home/user/new_folder/new_pack.tar ``` ## `omero transfer prepare` diff --git a/src/omero_cli_transfer.py b/src/omero_cli_transfer.py index 49ff3ee..181ded6 100644 --- a/src/omero_cli_transfer.py +++ b/src/omero_cli_transfer.py @@ -85,9 +85,11 @@ orig_group`), other options are `none`, `img_id`, `timestamp`, `software`, `version`, `md5`, `hostname`, `db_id`, `orig_user`, `orig_group`. ---metadata_only creates the transfer.xml file but does not copy data -or generate an archive. The last cli argument is the path where -the `transfer.xml` file will be written +--binaries allows to specify whether to archive binary data +(e.g images, ROIs, FileAnnotations) or only create the transfer.xml. +Default is `all` and will create the archive. WIth `none`, only the `transfer.xml` +file is created, in which case the last cli argument is the path where +the `transfer.xml` file will be written. Examples: omero transfer pack Image:123 transfer_pack.tar @@ -95,6 +97,8 @@ omero transfer pack Dataset:1111 /home/user/new_folder/new_pack.tar omero transfer pack 999 tarfile.tar # equivalent to Project:999 omero transfer pack 1 transfer_pack.tar --metadata img_id version db_id +omero transfer pack --binaries none Dataset:1111 /home/user/new_folder/ +omero transfer pack --binaries all Dataset:1111 /home/user/new_folder/new_pack.tar """) UNPACK_HELP = ("""Unpacks a transfer packet into an OMERO hierarchy. @@ -226,8 +230,12 @@ def _configure(self, parser): ) pack.add_argument("filepath", type=str, help=file_help) pack.add_argument( - "--metadata_only", - help="Only generate the xml file, don't create the archive", + "--binaries", + choices=["all", "none"], + default="all", + help="With `--binaries none`, only generate the metadata file " + "(transfer.xml or ro-crate-metadata.json). " + "With `--binaries all` (the default), pixel data and annotation are saved.", action="store_true") file_help = ("Path to where the zip file is saved") @@ -402,8 +410,8 @@ def __pack(self, args): raise ValueError("Single plate or screen cannot be " "packaged in human-readable format") - if args.metadata_only and args.simple: - raise ValueError("The --metadata_only and --simple options are " + if args.binaries == "all" and args.simple: + raise ValueError("The `--binaries all` and `--simple` options are " "incompatible") if isinstance(args.object, Image): @@ -432,7 +440,7 @@ def __pack(self, args): " permissions for current user.") print("Populating xml...") tar_path = Path(args.filepath) - if not args.metadata_only: + if args.binaries == "all": folder = str(tar_path) + "_folder" else: folder = os.path.splitext(tar_path)[0] @@ -452,7 +460,7 @@ def __pack(self, args): args.figure, self.metadata) - if not args.metadata_only: + if args.binaries == "all": print("Starting file copy...") self._copy_files(path_id_dict, folder, self.gateway) @@ -466,7 +474,7 @@ def __pack(self, args): print(f"Creating RO-Crate metadata at {md_fp}.") populate_rocrate(src_datatype, ome, os.path.splitext(tar_path)[0], path_id_dict, folder) - elif not args.metadata_only: + elif args.binaries == "all": self._package_files(os.path.splitext(tar_path)[0], args.zip, folder) print("Cleaning up...") diff --git a/test/integration/test_transfer.py b/test/integration/test_transfer.py index e8feaa0..677ff56 100644 --- a/test/integration/test_transfer.py +++ b/test/integration/test_transfer.py @@ -196,13 +196,13 @@ def test_pack_metadata_only(self, target_name, tmpdir): elif target_name == "plateid" or target_name == "screenid": self.create_plate(target_name=target_name) target = getattr(self, target_name) - args = self.args + ["pack", target, "--metadata_only", + args = self.args + ["pack", target, "--binaries", "none", str(tmpdir)] self.cli.invoke(args, strict=True) assert os.path.exists(str(tmpdir / 'transfer.xml')) assert os.path.getsize(str(tmpdir / 'transfer.xml')) > 0 - args = self.args + ["pack", target, "--metadata_only", "--simple", + args = self.args + ["pack", target, "--binaries", "none", "--simple", str(tmpdir)] with pytest.raises(ValueError): self.cli.invoke(args, strict=True)