Page 1 of 1

scripting image uploads via cli.py CLI.invoke()

PostPosted: Mon Jun 03, 2013 7:06 pm
by graemeb
I am writing a script to process some images and re-upload the results to OMERO. It seemed as though the command line importer available OMERO.server/bin/omero did not have all of the features I wanted (cannot specify dataset), so I wrote a separate importer in python that makes use of both the CLI class in lib/python/omero/cli.py to upload images, and a Blitz gateway connection to attach files, add description etc. The importer calls: cli.invoke(import_args) ; where cli is a CLI instance, and import_args is a list of arguments.

However, when I call my python importer from a shell script (using a session key for authentication), the script stalls: presumably because it is being prompted for confirmation, something like this:-

Server: [servername] <- requires confirmation, although it already has the value
Username: [username] <- requires confirmation, although it already has the value

If I run my importer from a shell prompt and hit enter a couple of times, it manages to use the session key to authenticate and upload the image + attachments no problem. I even tried: echo "\n\n" | my_importer arg1 ... argn ; but no cigar (running a second time does not require confirmations - something about the session is stored in ~/omero ??)

I now realise the CLI class is calling some java code via the import.py plugin, but is there any way to tell the java importer code that this is not an interactive session, and to please just import the image, no questions asked? Or is there an easier way to script image uploads that I am missing?

PS. is this the correct place to post questions, or do you prefer the mailing list(s)?

Re: scripting image uploads via cli.py CLI.invoke()

PostPosted: Tue Jun 04, 2013 7:28 am
by wmoore
Hi Graeme,

Would this work for you (do this before import)

Code: Select all
cli.invoke(["login", "%s@localhost" % user, "-w", "ome", "-C"], strict=True)


This is the approach we use in our auto_import.py script for setting up test data in OMERO: https://github.com/ome/omero-setup/blob ... _import.py

Here we create the Dataset first, then pass the Dataset ID to the CLI importer.

Hope that helps,

Will.

Re: scripting image uploads via cli.py CLI.invoke()

PostPosted: Tue Jun 04, 2013 2:06 pm
by graemeb
Hi Will,

thanks for the reply - yes, that's essentially what I'm doing, and I started from the auto_import.py script you pointed me to before. The only difference is I want to authenticate with a session key, because I want to re-upload results to the dataset of the user that started the job.

So in your case, the script does not require confirmation? (i.e. enter keystrokes) I'll have another play with the different options and see if there's a difference authenticating with user+password versus session key.

Cheers,

Graeme

Re: scripting image uploads via cli.py CLI.invoke()

PostPosted: Tue Jun 04, 2013 8:49 pm
by sbesson
Hi Graeme,

do you have an example of the code that is not working as you would like at the moment? It may help us identifying if this is an paramater issue or a CLI bug. Also which version of the server/CLI are you using?

Cheers,
Sebastien