We're Hiring!

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

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

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

Postby graemeb » Mon Jun 03, 2013 7:06 pm

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)?
graemeb
 
Posts: 2
Joined: Mon Jun 03, 2013 5:47 pm

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

Postby wmoore » Tue Jun 04, 2013 7:28 am

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.
User avatar
wmoore
Team Member
 
Posts: 674
Joined: Mon May 18, 2009 12:46 pm

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

Postby graemeb » Tue Jun 04, 2013 2:06 pm

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
graemeb
 
Posts: 2
Joined: Mon Jun 03, 2013 5:47 pm

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

Postby sbesson » Tue Jun 04, 2013 8:49 pm

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
User avatar
sbesson
Team Member
 
Posts: 421
Joined: Tue Feb 28, 2012 7:20 pm


Return to Developer Discussion

Who is online

Users browsing this forum: Google [Bot] and 1 guest