Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bfoptions #13

Merged
merged 5 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you ever run this without "--bfoptions"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm - good point... probably not! I think we always need the .bfoptions file alongside the symlinks since we currently always exclude the chunks from new Filesets.
So, I guess I'll remove this option from the symlink command then...



To ONLY create fileset.zarr.bfoptions

::

$ omero mkngff bfoptions /OMERO/ManagedRepository 1234 /path/to/fileset.zarr

Requirements
============

Expand Down
48 changes: 38 additions & 10 deletions src/omero_mkngff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
Expand All @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -237,12 +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, args.symlink_target)

def bfoptions(self, args: Namespace) -> None:
prefix = self.get_prefix(args)
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, args.symlink_target)

def get_prefix(self, args):

Expand All @@ -266,19 +285,28 @@ 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
symlink_dir = f"{prefix_dir}_{SUFFIX}"
return symlink_dir

def create_symlink(self, symlink_repo, prefix, symlink_path, symlink_target):
symlink_dir = self.get_symlink_dir(symlink_repo, prefix, symlink_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"
self.ctx.err("write bfoptions to: %s" % bfoptions_path)
with open(bfoptions_path, "w") as f:
f.writelines(["omezarr.list_pixels=false",
"\nomezarr.quick_read=true"])

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)

Expand Down
Loading