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

Shortern paths and symlinks #6

Merged
merged 4 commits into from
Sep 25, 2023
Merged
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
11 changes: 7 additions & 4 deletions src/omero_mkngff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from omero.cli import BaseControl, Parser
from omero.sys import ParametersI

SUFFIX = "mkngff"
HELP = """Plugin to swap OMERO filesets with NGFF

CLI plugin used to swap an existing OMERO fileset with
Expand Down Expand Up @@ -197,7 +198,7 @@ def sql(self, args: Namespace) -> None:
self.ctx.die(401, f"Symlink target does not exist: {args.symlink_target}")
return

# create *_converted/path/to/zarr directory containing symlink to data
# create *_SUFFIX/path/to/zarr directory containing symlink to data
if args.symlink_repo:
prefix_dir = os.path.join(args.symlink_repo, prefix)
self.ctx.err(f"Checking for prefix_dir {prefix_dir}")
Expand All @@ -206,7 +207,7 @@ def sql(self, args: Namespace) -> None:
symlink_container = f"{symlink_path.parent}"
if symlink_container.startswith("/"):
symlink_container = symlink_container[1:] # remove "/" from start
symlink_dir = os.path.join(f"{prefix_dir}_converted", symlink_container)
symlink_dir = f"{prefix_dir}_{SUFFIX}"
self.ctx.err(f"Creating dir at {symlink_dir}")
os.makedirs(symlink_dir, exist_ok=True)

Expand All @@ -219,11 +220,13 @@ def sql(self, args: Namespace) -> None:

rows = []
for row_path, row_name, row_mime in self.walk(symlink_path):
# remove common path to shorten
row_path = str(row_path).replace(f"{symlink_path.parent}", "")
if str(row_path).startswith("/"):
row_path = str(row_path)[1:] # remove "/" from start
rows.append(
ROW.format(
PATH=f"{prefix_path}/{prefix_name}_converted/{row_path}/",
PATH=f"{prefix_path}/{prefix_name}_{SUFFIX}/{row_path}/",
NAME=row_name,
MIME=row_mime,
)
Expand All @@ -232,7 +235,7 @@ def sql(self, args: Namespace) -> None:
self.ctx.out(
TEMPLATE.format(
OLD_FILESET=args.fileset_id,
PREFIX=f"{prefix_path}/{prefix_name}_converted/",
PREFIX=f"{prefix_path}/{prefix_name}_{SUFFIX}/",
ROWS=",\n".join(rows),
REPO=self.get_uuid(args),
UUID=args.secret,
Expand Down