[ome-users] omero scripts: getting hostname and port to server from BaseClient

Carnë Draug carandraug+dev at gmail.com
Mon Sep 22 17:40:20 BST 2014


On 19 September 2014 16:50, Josh Moore <josh at glencoesoftware.com> wrote:
>
> On Sep 18, 2014, at 8:23 PM, Carnë Draug wrote:
>
>> On 8 September 2014 10:55, Josh Moore <josh at glencoesoftware.com> wrote:
>>> Hi Carnë,
>
> Hi Carnë,
>
>>> On Sep 4, 2014, at 7:26 PM, Carnë Draug wrote:
>>
>> If I understood correctly, I should not have to pass any of the session
>> information (UUID or server hostname) in the arguments to invoke() when
>> using omero.cli.CLI.  It should be enough to set `_client' to a valid omero
>> session. Is this correct?
>
> Yup.
>
>> This works great as long as I do it via the command-line. This tiny script
>> works great:
>>
> ...
>>
>> However, it fails as soon as I try to use it as an omero script.  For a
>> short example, the following omero script:
>>
> ...
>>
>> will still fail with the following error:
>>
>>    Usage:  importer-cli [OPTION]... [path [path ...]]...
>>      or:   importer-cli [OPTION]... -
>>
>>    [...]
>>
>>    Session arguments:
>>    Mandatory arguments for creating a session are 1- either the OMERO server
>>    hostname, username and password or 2- the OMERO server hostname and a
>>    valid session key.
>>
>
> Sorry, Carnë. In my excitement for having found a "real" way to pass the arguments,
> I forgot that import.py internally uses the "omero.host" setting, so I just propagated
> your problem down the line.
>
> We'll need to fix this so that "omero.host" can either be reliably used or is completely
> unnecessary, but for the moment you can do the parsing you were looking for with:
>
>
>   router = copy.getProperty("Ice.Default.Router")
>   router = copy.getCommunicator().stringToProxy(router)
>   for endpoint in router.ice_getEndpoints():
>       host = endpoint.getInfo().host
>   print "Using", host
>   copy.ic.getProperties().setProperty("omero.host", host)

This works great thank you. It also fixes the issue I was having about
having the session UUID displayed on the list of processes during the
import.

Just for future reference to others facing the same issue, here's a
complete example of image file import as an omero script:

    import omero.scripts
    import omero.cli

    client = omero.scripts.client("test.py")

    router = client.getProperty("Ice.Default.Router")
    router = client.getCommunicator().stringToProxy(router)
    for endpoint in router.ice_getEndpoints():
      client.ic.getProperties().setProperty("omero.host",
endpoint.getInfo().host)
      break
    else:
      raise Exception("no host configuration found")

    cli = omero.cli.CLI()
    cli.loadplugins()
    cli._client = c.createClient(secure = True)
    cli.invoke(["import", path_to_image_file])


Carnë



More information about the ome-users mailing list