Skip to content

Commit

Permalink
changes cli argument to
Browse files Browse the repository at this point in the history
  • Loading branch information
glyg committed Dec 11, 2023
1 parent 4e2fbb5 commit 2d1e011
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
28 changes: 18 additions & 10 deletions src/omero_cli_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,20 @@
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
omero transfer pack --zip Image:123 transfer_pack.zip
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.
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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]
Expand All @@ -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)

Expand All @@ -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...")
Expand Down
4 changes: 2 additions & 2 deletions test/integration/test_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2d1e011

Please sign in to comment.