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

Add --symlink_repo option for creating symlinks from sql command #4

Merged
merged 11 commits into from
Aug 28, 2023
Next Next commit
Add --symlink_repo option for creating symlinks from sql command
will-moore committed Aug 16, 2023
commit d2014f8aceabfe3bb1ce3e39782b37984b37a705
23 changes: 20 additions & 3 deletions src/omero_mkngff/__init__.py
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import os
from argparse import Namespace
from pathlib import Path
from typing import Generator, Tuple
@@ -154,6 +155,11 @@ def _configure(self, parser: Parser) -> None:
"--secret", help="DB UUID for protecting SQL statements", default="TBD"
)
sql.add_argument("--zarr_name", help="Nicer name for zarr directory if desired")
sql.add_argument(
"--symlink_repo",
help=("Create symlinks from Fileset to symlink_target using"
"this ManagedRepo path, e.g. /data/OMERO/ManagedRepository")
)
sql.add_argument("fileset_id", type=int)
sql.add_argument("symlink_target")
sql.set_defaults(func=self.sql)
@@ -191,9 +197,20 @@ def sql(self, args: Namespace) -> None:
self.ctx.die(401, f"Symlink target does not exist: {args.symlink_target}")
return

zarr_name = args.zarr_name
if not zarr_name:
zarr_name = symlink_path.name
# create *_converted/path/to/zarr directory containing symlink to data
if args.symlink_repo:
prefix_dir = os.path.join(args.symlink_repo, prefix_path)
if not os.path.exists(prefix_dir):
self.ctx.die(402, f"Fileset dir does not exist: {prefix_dir}")
symlink_dir = os.path.join(prefix_dir, f"{prefix_name}_converted", symlink_path.parent)
os.makedirs(symlink_dir, exist_ok=True)

symlink_source = os.path.join(symlink_dir, symlink_path.name)
target_is_directory = os.path.isdir(args.symlink_target)
self.ctx.err(
f"Creating symlink {symlink_source} -> {args.symlink_target}"
)
os.symlink(args.symlink_target, symlink_source, target_is_directory)

rows = []
for row_path, row_name, row_mime in self.walk(symlink_path):