Skip to content

Commit

Permalink
Merge pull request #12 from will-moore/clientpath
Browse files Browse the repository at this point in the history
Add clientpath to Filesets
  • Loading branch information
joshmoore authored Oct 31, 2023
2 parents 90c4dde + 2469f6d commit e874ca3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/omero_mkngff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
insert into filesetentry
(id, {DETAILS1}, fileset, originalfile, fileset_index, clientpath)
values (nextval('seq_filesetentry'), {DETAILS2},
new_fileset, new_file, i-1, 'unknown');
new_fileset, new_file, i-1, info[i][4]);
end loop;
Expand Down Expand Up @@ -134,7 +134,7 @@
commit;
"""

ROW = """ ['{PATH}', '{NAME}', '{MIME}']"""
ROW = """ ['{PATH}', '{NAME}', '{MIME}', '{CLIENTPATH}']"""


class MkngffControl(BaseControl):
Expand All @@ -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(
"--clientpath",
help=("Base path to create clientpath/path/to/img.zarr/")
)
sql.add_argument("fileset_id", type=int)
sql.add_argument("symlink_target")
sql.set_defaults(func=self.sql)
Expand Down Expand Up @@ -193,6 +197,12 @@ def sql(self, args: Namespace) -> None:
# Need a file to set path/name on pixels table BioFormats uses for setId()
setid_target = None
for row_path, row_name, row_mime in self.walk(symlink_path):
row_clientpath = "unknown"
if args.clientpath:
# zarr_path is relative URL from .zarr /to/file/
zarr_path = str(row_path).replace(args.symlink_target, '')
row_clientpath = f"{args.clientpath}{zarr_path}/{row_name}"

# remove common path to shorten
row_path = str(row_path).replace(f"{symlink_path.parent}", "")
if str(row_path).startswith("/"):
Expand All @@ -206,6 +216,7 @@ def sql(self, args: Namespace) -> None:
PATH=f"{row_full_path}/",
NAME=row_name,
MIME=row_mime,
CLIENTPATH=row_clientpath,
)
)

Expand Down Expand Up @@ -287,7 +298,6 @@ def walk(self, path: Path) -> Generator[Tuple[Path, str, str], None, None]:
else:
is_array = (p / ".zarray").exists()
if is_array or (p / ".zgroup").exists():
yield (p.parent, p.name, "Directory")
# If array, don't recursively check sub-dirs
if is_array:
yield (p, ".zarray", "application/octet-stream")
Expand Down

0 comments on commit e874ca3

Please sign in to comment.