Skip to content

Commit

Permalink
merge master -Dorg -Ssuccess-only: PR 427 (Add fileset folder creation)
Browse files Browse the repository at this point in the history
  • Loading branch information
snoopycrimecop committed Jan 18, 2025
2 parents 5137e5d + ed3c684 commit 9fcb379
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ build
dist/
target/
.DS_Store
.idea
_build
17 changes: 12 additions & 5 deletions src/omero/plugins/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
import sys
import omero
import os
import re
from omero.cli import BaseControl, CLI, ProxyStringType
from omero.rtypes import unwrap
from omero.gateway import BlitzGateway

HELP = """Download a File, Image or Fileset with a specified ID to a target file
Expand Down Expand Up @@ -61,6 +59,8 @@ def _configure(self, parser):
"OriginalFile is assumed if <object>: is omitted.")
parser.add_argument(
"filename", help="Local filename (or path for Fileset) to be saved to. '-' for stdout")
parser.add_argument(
"--insert_fileset_folder", action="store_true", help="Adding 'Fileset_xxxx' folder in the download path")
parser.set_defaults(func=self.__call__)
parser.add_login_arguments()

Expand All @@ -72,24 +72,31 @@ def __call__(self, args):
conn = BlitzGateway(client_obj=client)
conn.SERVICE_OPTS.setOmeroGroup(-1)

if args.insert_fileset_folder:
insert_fileset_folder = True
else:
insert_fileset_folder = False

if dtype == "Fileset":
fileset = self.get_object(conn, dtype, obj.id.val)
self.download_fileset(conn, fileset, args.filename)
self.download_fileset(conn, fileset, args.filename, insert_fileset_folder)
elif dtype == "Image":
image = self.get_object(conn, dtype, obj.id.val)
fileset = image.getFileset()
if fileset is None:
self.ctx.die(602, 'Input image has no associated Fileset')
self.download_fileset(conn, fileset, args.filename)
self.download_fileset(conn, fileset, args.filename, insert_fileset_folder)
else:
orig_file = self.get_file(client.sf, dtype, obj.id.val)
target_file = str(args.filename)
# only expect single file
self.download_file(client, orig_file, target_file)

def download_fileset(self, conn, fileset, dir_path):
def download_fileset(self, conn, fileset, dir_path, insert_fileset_folder=False):
self.ctx.out(f"Fileset: {fileset.id}")
template_prefix = fileset.getTemplatePrefix()
if insert_fileset_folder:
dir_path = os.path.join(dir_path, f"Fileset_{fileset.id}")
for orig_file in fileset.listFiles():
file_path = orig_file.path.replace(template_prefix, "")
target_dir = os.path.join(dir_path, file_path)
Expand Down

0 comments on commit 9fcb379

Please sign in to comment.