[ome-users] omero scripts: getting hostname and port to server from BaseClient
Carnë Draug
carandraug+dev at gmail.com
Thu Sep 18 19:23:56 BST 2014
On 8 September 2014 10:55, Josh Moore <josh at glencoesoftware.com> wrote:
> Hi Carnë,
>
> On Sep 4, 2014, at 7:26 PM, Carnë Draug wrote:
>
>> I am trying to get the hostname (or IP address) and port of the omero server
>> from an omero script so I can import images back into the server using the
>> following:
>>
>> cli = omero.cli.CLI()
>> cli.loadplugins()
>> cli.invoke(["-s", hostname, "-k", port, "import", filepath])
>>
>> However, I'm struggling to get the correct hostname. The best I've managed was
>> the following:
>>
>>>>> client.getRouter(client.getCommunicator())
>> OMERO.Glacier2/router -t -e 1.0:tcp -h 129.67.77.159 -p 4063
>>
>> and while I can easily parse that string to get the value for "-h", will this
>> one day break when it becomes "--host", "--hostname", or something else? Is
>> there a sanctioned method that gives the correct hostname that a client
>> somewhere in the grid should use when importing images?
>
>
> You can actually use these strings directly by passing them to the client constructor:
>
>
> import omero
> import omero.cli
> import omero.scripts
>
> c = omero.scripts.client("test.py")
> h = c.getRouter(c.getCommunicator())
>
> copy = omero.client(["--Ice.Default.Router=%s" % h])
> copy.createSession("root", "XXX")
> try:
> cli = omero.cli.CLI()
> cli.loadplugins()
> # https://trac.openmicroscopy.org.uk/ome/ticket/12388
> cli._client = copy
> cli.invoke(["hql", "select e from Experimenter e where e.omeName = 'root'"])
> finally:
> copy.__del__()
>
>
> NB: https://trac.openmicroscopy.org.uk/ome/ticket/12388 proposes to improve the
> `cli._client = copy`.
>
>
> At the same time, though, the environment variable "ICE_CONFIG" is set for the entire process, so there should be no need to set any property:
>
> import omero
> import omero.cli
> import omero.scripts
>
> c = omero.scripts.client("test.py")
>
> copy = omero.client()
> copy.createSession()
> try:
> cli = omero.cli.CLI()
> cli.loadplugins()
> cli._client = copy
> ...
> finally:
> copy.__del__()
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?
This works great as long as I do it via the command-line. This tiny script
works great:
import omero
import omero.cli
c = omero.client (host = "localhost")
c.createSession (username = "username", password = "password")
cli = omero.cli.CLI()
cli.loadplugins()
cli._client = c
cli.invoke(["import", path_to_image_file])
However, it fails as soon as I try to use it as an omero script. For a
short example, the following omero script:
import omero.scripts
import omero.cli
c = omero.scripts.client("test.py")
copy = c.createClient(secure = True)
cli = omero.cli.CLI()
cli.loadplugins()
cli._client = copy
cli.invoke(["import", path_to_image_file])
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.
> P.S. while working on this script, I saw that createClient(secure=False)
> does not work from scripts which is likely related to your issue of not
> being able to find the hostname.
I tried with "secure=True" and still did not succeed.
Carnë
More information about the ome-users
mailing list