We're Hiring!

cannot download archived file

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.

Re: cannot download archived file

Postby jmoore » Tue Feb 10, 2015 7:59 am

ebbwdan wrote:One more question. When the script completes - I get an 'Error' link in the client the contents of which seems to be the output from the CLI. Is there a way to stop that happening?


Anything that goes to stderr will be assumed to be error output by the clients. You can redirect the stderr to a file using "---errs" (that's three hyphens).

Also, is there an easy OMERO way to get the ID of the newly imported image?


The ID of the Pixels object is returned on stdout. You can redirect it with "---file" (again 3) and then slurp it back in. For example, if you're using the CLI:
Code: Select all
bin/omero hql -q --style=plain "select i.id from Pixels p join p.image as i where p.id  = $(cat import.out)" | cut -f2 -d,
1

though this would be slightly easier in pure Python. Note: the "-q" argument can also be passed to the import to reduce stderr.

Cheers,
~Josh
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: cannot download archived file

Postby ebbwdan » Tue Feb 17, 2015 6:06 am

Hi Josh, Will and Sebastien,

I'm still having some trouble with the CLI. I have the following function in my script for importing:

Code: Select all
def do_import(conn, session, filename, dataset=None, project=None):

    group = conn.getGroupFromContext()
   
    sessionId = session['ID']
    cli = omero.cli.CLI()
    cli.loadplugins()
    cli.invoke(["sessions", "login", "-s", "localhost", "-k", "%s" % sessionId], strict=True)
#     cli.invoke(["login", "%s@localhost" % user.getName(), "-w", "omero", "-C"], strict=True)
#     cli.invoke(["sessions", "group", group.getName()], strict=True)
    import_args = ["import"]
    import_args.append(filename)
    errlog = input_dir + "/stderr.txt"
    import_args.extend(["---errs",errlog])
    outlog = input_dir + "/stdout.txt"
    import_args.extend(["---file",outlog])
    print import_args
    cli.invoke(import_args, strict=True)
   
    newImg = get_new_image(conn)
    return newImg


If I login to the session I get am getting an EOF error at the final cli.invoke() call:

Code: Select all
cli.invoke(import_args, strict=True)


and the following appearing in stdout:

Previously logged in to localhost:4064 as root
Server: [localhost]


If I login using username and password (instead of session) it works every time but I can't use this on our production server (or can I?). Either way if I include the

Code: Select all
cli.invoke(["sessions", "group", group.getName()], strict=True)


line I get an EOF error at this point.

I know that I missed something somewhere but I just can't see it!

I have everything else in my work flow sorted (thanks a million for your help!) and a couple of scripts which are dependent on this last step working.

All the best,

Dan.
ebbwdan
 
Posts: 61
Joined: Wed Aug 29, 2012 4:46 am

Re: cannot download archived file

Postby ebbwdan » Tue Feb 17, 2015 6:49 am

Hi again,

Just a quick follow up. I seem to be able to make the session login work on my vm now. I figured maybe it was an issue with the script failing and the session not being closed. I ran the script successfully by using the user credentials (so session closed) and then ran using the session and it worked.

However, using the session to login on my prod server continues to fail.

Cheers,

Dan.
ebbwdan
 
Posts: 61
Joined: Wed Aug 29, 2012 4:46 am

Re: cannot download archived file

Postby ebbwdan » Tue Feb 17, 2015 7:04 am

Hi again,

Sorry for the bombardment! Got it working - had to also pass hostname and username to the import command after logging in to the session.

So after running:

Code: Select all
cli.invoke(["sessions", "login", "-s", "localhost", "-k", "%s" % sessionId], strict=True)


I ran something like:

Code: Select all
cli.invoke(["import",filename, "-s", "localhost", "-u", "%s" % user.getName(), "---errs", stderr, "---file", stdout])


All the best,

Dan.
ebbwdan
 
Posts: 61
Joined: Wed Aug 29, 2012 4:46 am

Re: cannot download archived file

Postby sbesson » Tue Feb 17, 2015 9:38 am

Hi Dan,

glad to hear you got things working. As a side note, since the `import` plugin supports the same connection arguments as the `sessions` plugin, you should be able to do the import transaction using the session key in one call:

Code: Select all
    cli = omero.cli.CLI()
    cli.loadplugins()
    import_args = ["import", "-s", "localhost", "-k", "%s" % sessionId]
    import_args += ["---errs", stderr, "---file", stdout, filename]
    cli.invoke(import_args, strict=True)


Best,
Sebastien
User avatar
sbesson
Team Member
 
Posts: 421
Joined: Tue Feb 28, 2012 7:20 pm

Previous

Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 1 guest