From 20a4bc273dc9e8d2ddcf58669799c63049ffec15 Mon Sep 17 00:00:00 2001 From: William Moore Date: Tue, 31 Oct 2023 15:39:36 +0000 Subject: [PATCH 1/5] Add bfoptions command --- README.rst | 12 +++++++--- src/omero_mkngff/__init__.py | 43 +++++++++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/README.rst b/README.rst index ffbabc7..1f3fd1d 100644 --- a/README.rst +++ b/README.rst @@ -25,16 +25,22 @@ specified Fileset ID: :: - $ omero mkngff sql --symlink_repo /OMERO/ManagedRepository --secret=secret 1234 /path/to/fileset.zarr > myNgff.sql + $ omero mkngff sql --symlink_repo /OMERO/ManagedRepository --secret=secret --bfoptions 1234 /path/to/fileset.zarr > myNgff.sql $ psql -U omero -d idr -h $DBHOST -f myNgff.sql -To ONLY perform the symlink creation: +To ONLY perform the symlink creation (and optionally create fileset.zarr.bfoptions) :: - $ omero mkngff symlink /OMERO/ManagedRepository 1234 /path/to/fileset.zarr + $ omero mkngff symlink /OMERO/ManagedRepository 1234 /path/to/fileset.zarr --bfoptions +To ONLY create fileset.zarr.bfoptions + +:: + + $ omero mkngff bfoptions /OMERO/ManagedRepository 1234 /path/to/fileset.zarr + Requirements ============ diff --git a/src/omero_mkngff/__init__.py b/src/omero_mkngff/__init__.py index fc5a5b1..8d92161 100644 --- a/src/omero_mkngff/__init__.py +++ b/src/omero_mkngff/__init__.py @@ -155,6 +155,10 @@ def _configure(self, parser: Parser) -> None: help=("Create symlinks from Fileset to symlink_target using" "this ManagedRepo path, e.g. /data/OMERO/ManagedRepository") ) + sql.add_argument( + "--bfoptions", action="store_true", + help=("Create data.zarr.bfoptions file if --symlink_repo has been provided") + ) sql.add_argument( "--clientpath", help=("Base path to create clientpath/path/to/img.zarr/") @@ -171,8 +175,16 @@ def _configure(self, parser: Parser) -> None: "this ManagedRepo path, e.g. /data/OMERO/ManagedRepository")) symlink.add_argument("fileset_id", type=int) symlink.add_argument("symlink_target") + symlink.add_argument("--bfoptions", action="store_true", help="Create data.zarr.bfoptions file") symlink.set_defaults(func=self.symlink) + bfoptions = sub.add_parser("bfoptions", help="Create data.zarr.bfoptions in Fileset") + bfoptions.add_argument("symlink_repo", help=( + "The ManagedRepo path, e.g. /data/OMERO/ManagedRepository")) + bfoptions.add_argument("fileset_id", type=int) + bfoptions.add_argument("symlink_target") + bfoptions.set_defaults(func=self.bfoptions) + def setup(self, args: Namespace) -> None: self.ctx.out(SETUP) @@ -188,7 +200,7 @@ def sql(self, args: Namespace) -> None: # If symlink dir exists, we assume that this fileset has been processed -> skip... if args.symlink_repo: - symlink_dir = self.get_symlink_dir(args.symlink_repo, prefix, symlink_path) + symlink_dir = self.get_symlink_dir(args.symlink_repo, prefix) if os.path.exists(symlink_dir): self.ctx.err(f"Symlink dir exists at {symlink_dir} - skipping sql output") return @@ -238,11 +250,20 @@ def sql(self, args: Namespace) -> None: # Finally create *_SUFFIX/ directory containing symlink to data if args.symlink_repo: self.create_symlink(args.symlink_repo, prefix, symlink_path, args.symlink_target) + if args.bfoptions: + self.write_bfoptions(args.symlink_repo, prefix, symlink_path) + + def bfoptions(self, args: Namespace) -> None: + prefix = self.get_prefix(args) + symlink_path = Path(args.symlink_target) + self.write_bfoptions(args.symlink_repo, prefix, symlink_path) def symlink(self, args: Namespace) -> None: prefix = self.get_prefix(args) symlink_path = Path(args.symlink_target) self.create_symlink(args.symlink_repo, prefix, symlink_path, args.symlink_target) + if args.bfoptions: + self.write_bfoptions(args.symlink_repo, prefix, symlink_path) def get_prefix(self, args): @@ -266,19 +287,25 @@ def get_prefix(self, args): return prefix - def get_symlink_dir(self, symlink_repo, prefix, symlink_path): + def get_symlink_dir(self, symlink_repo, prefix): prefix_dir = os.path.join(symlink_repo, prefix) self.ctx.err(f"Checking for prefix_dir {prefix_dir}") - if not os.path.exists(prefix_dir): - self.ctx.die(402, f"Fileset dir does not exist: {prefix_dir}") - symlink_container = f"{symlink_path.parent}" - if symlink_container.startswith("/"): - symlink_container = symlink_container[1:] # remove "/" from start + # if not os.path.exists(prefix_dir): + # self.ctx.die(402, f"Fileset dir does not exist: {prefix_dir}") symlink_dir = f"{prefix_dir}_{SUFFIX}" return symlink_dir + def write_bfoptions(self, managed_repo, fsprefix, file_path): + mkngff_dir = self.get_symlink_dir(managed_repo, fsprefix) + # os.makedirs(mkngff_dir, exist_ok=True) + zarr_path = os.path.join(mkngff_dir, file_path.name) + bfoptions_path = f"{zarr_path}.bfoptions" + print("WRITE bfoptions to", bfoptions_path) + # with open(bfoptions_path, "w") as f: + # f.write("omezarr.list_pixels=false") + def create_symlink(self, symlink_repo, prefix, symlink_path, symlink_target): - symlink_dir = self.get_symlink_dir(symlink_repo, prefix, symlink_path) + symlink_dir = self.get_symlink_dir(symlink_repo, prefix) self.ctx.err(f"Creating dir at {symlink_dir}") os.makedirs(symlink_dir, exist_ok=True) From 7dc8222c0822c7a7f422cb8c46e9f7a9a53c9541 Mon Sep 17 00:00:00 2001 From: William Moore Date: Tue, 31 Oct 2023 15:49:18 +0000 Subject: [PATCH 2/5] cleanup args and un-comment to fix previous commit --- src/omero_mkngff/__init__.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/omero_mkngff/__init__.py b/src/omero_mkngff/__init__.py index 8d92161..119c6a1 100644 --- a/src/omero_mkngff/__init__.py +++ b/src/omero_mkngff/__init__.py @@ -249,21 +249,19 @@ def sql(self, args: Namespace) -> None: # Finally create *_SUFFIX/ directory containing symlink to data if args.symlink_repo: - self.create_symlink(args.symlink_repo, prefix, symlink_path, args.symlink_target) + self.create_symlink(args.symlink_repo, prefix, args.symlink_target) if args.bfoptions: - self.write_bfoptions(args.symlink_repo, prefix, symlink_path) + self.write_bfoptions(args.symlink_repo, prefix, args.symlink_target) def bfoptions(self, args: Namespace) -> None: prefix = self.get_prefix(args) - symlink_path = Path(args.symlink_target) - self.write_bfoptions(args.symlink_repo, prefix, symlink_path) + self.write_bfoptions(args.symlink_repo, prefix, args.symlink_target) def symlink(self, args: Namespace) -> None: prefix = self.get_prefix(args) - symlink_path = Path(args.symlink_target) - self.create_symlink(args.symlink_repo, prefix, symlink_path, args.symlink_target) + self.create_symlink(args.symlink_repo, prefix, args.symlink_target) if args.bfoptions: - self.write_bfoptions(args.symlink_repo, prefix, symlink_path) + self.write_bfoptions(args.symlink_repo, prefix, args.symlink_target) def get_prefix(self, args): @@ -290,21 +288,23 @@ def get_prefix(self, args): def get_symlink_dir(self, symlink_repo, prefix): prefix_dir = os.path.join(symlink_repo, prefix) self.ctx.err(f"Checking for prefix_dir {prefix_dir}") - # if not os.path.exists(prefix_dir): - # self.ctx.die(402, f"Fileset dir does not exist: {prefix_dir}") + if not os.path.exists(prefix_dir): + self.ctx.die(402, f"Fileset dir does not exist: {prefix_dir}") symlink_dir = f"{prefix_dir}_{SUFFIX}" return symlink_dir - def write_bfoptions(self, managed_repo, fsprefix, file_path): + def write_bfoptions(self, managed_repo, fsprefix, symlink_target): + file_path = Path(symlink_target) mkngff_dir = self.get_symlink_dir(managed_repo, fsprefix) # os.makedirs(mkngff_dir, exist_ok=True) zarr_path = os.path.join(mkngff_dir, file_path.name) bfoptions_path = f"{zarr_path}.bfoptions" - print("WRITE bfoptions to", bfoptions_path) - # with open(bfoptions_path, "w") as f: - # f.write("omezarr.list_pixels=false") + self.ctx.err("write bfoptions to: %s" % bfoptions_path) + with open(bfoptions_path, "w") as f: + f.write("omezarr.list_pixels=false") - def create_symlink(self, symlink_repo, prefix, symlink_path, symlink_target): + def create_symlink(self, symlink_repo, prefix, symlink_target): + symlink_path = Path(symlink_target) symlink_dir = self.get_symlink_dir(symlink_repo, prefix) self.ctx.err(f"Creating dir at {symlink_dir}") os.makedirs(symlink_dir, exist_ok=True) From f4b8dd4f99aff7f6c6a29dfb57dfe8fcdc543e44 Mon Sep 17 00:00:00 2001 From: William Moore Date: Tue, 5 Dec 2023 22:05:54 +0000 Subject: [PATCH 3/5] add omezarr.quick_read=true to bfoptions default content --- src/omero_mkngff/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/omero_mkngff/__init__.py b/src/omero_mkngff/__init__.py index 119c6a1..90afa65 100644 --- a/src/omero_mkngff/__init__.py +++ b/src/omero_mkngff/__init__.py @@ -302,6 +302,7 @@ def write_bfoptions(self, managed_repo, fsprefix, symlink_target): self.ctx.err("write bfoptions to: %s" % bfoptions_path) with open(bfoptions_path, "w") as f: f.write("omezarr.list_pixels=false") + f.write("omezarr.quick_read=true") def create_symlink(self, symlink_repo, prefix, symlink_target): symlink_path = Path(symlink_target) From 95ffa65c1715fa4e051b819b2d2ff66b5804c75c Mon Sep 17 00:00:00 2001 From: William Moore Date: Tue, 5 Dec 2023 23:05:27 +0000 Subject: [PATCH 4/5] Use writelines() --- src/omero_mkngff/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/omero_mkngff/__init__.py b/src/omero_mkngff/__init__.py index 90afa65..e97e85e 100644 --- a/src/omero_mkngff/__init__.py +++ b/src/omero_mkngff/__init__.py @@ -301,8 +301,8 @@ def write_bfoptions(self, managed_repo, fsprefix, symlink_target): bfoptions_path = f"{zarr_path}.bfoptions" self.ctx.err("write bfoptions to: %s" % bfoptions_path) with open(bfoptions_path, "w") as f: - f.write("omezarr.list_pixels=false") - f.write("omezarr.quick_read=true") + f.writelines(["omezarr.list_pixels=false", + "omezarr.quick_read=true"]) def create_symlink(self, symlink_repo, prefix, symlink_target): symlink_path = Path(symlink_target) From b5373338ec2b8aa766609c66c54beac29d8a3644 Mon Sep 17 00:00:00 2001 From: William Moore Date: Tue, 5 Dec 2023 23:13:59 +0000 Subject: [PATCH 5/5] Fix new-line in bfoptions --- src/omero_mkngff/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/omero_mkngff/__init__.py b/src/omero_mkngff/__init__.py index e97e85e..f34c7c6 100644 --- a/src/omero_mkngff/__init__.py +++ b/src/omero_mkngff/__init__.py @@ -302,7 +302,7 @@ def write_bfoptions(self, managed_repo, fsprefix, symlink_target): self.ctx.err("write bfoptions to: %s" % bfoptions_path) with open(bfoptions_path, "w") as f: f.writelines(["omezarr.list_pixels=false", - "omezarr.quick_read=true"]) + "\nomezarr.quick_read=true"]) def create_symlink(self, symlink_repo, prefix, symlink_target): symlink_path = Path(symlink_target)