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 fileset folder creation #427

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
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", help="Adding 'Fileset_xxxx' folder in the download path", default="False")
Copy link
Member

Choose a reason for hiding this comment

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

I think here you want to use the "--insert_fileset_folder" action="store_true" instead of default="False"
Then you can check with simply if args.insert_fileset_folder:

e.g. see examples at

"--everyone", action="store_true",

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.lower() == "true":
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