[ome-devel] OME python binding
Aleksandra Tarkowska
A.Tarkowska at dundee.ac.uk
Fri Sep 26 13:38:31 BST 2014
Hi Yanling
As Carne mentioned you can invoke import process via python script.
Similar test is available on
https://github.com/openmicroscopy/openmicroscopy/blob/develop/components/to
ols/OmeroPy/test/integration/library.py#L187
args.extend(["-s", server, "-k", key, "-p", port, "import", "--"])
Allows you to pass all parameters you normally pass via bin/omero import Š
For more details refer to --help.
Can I ask why you just simply cannot use dropbox to do that work
automatically for you?
Did you see
http://www.openmicroscopy.org/site/support/omero5/sysadmins/dropbox.html
Kind regards
Ola
On 26/09/2014 12:48, "Carnë Draug" <carandraug+dev at gmail.com> wrote:
>On Thu, 25 Sep 2014 13:31:53 -0400, Yanling Liu <vrnova at gmail.com> wrote:
>> Hi,
>>
>> I was able to use the CLI import (bin/omero import) to import
>> images into OMERO. My question is that if OMERO python binding has
>> similar capability? Can I write a little python script and call OMERO
>> import function to upload some images to OMERO?
>>
>> What I mean is if there's python binding to the import function,
>> rather than doing system call in python script to call bin/omero.
>
>You can do something like the following:
>
> import omero
> import omero.cli
>
> client = omero.client (host = server_ip_or_hostname)
> client.createSession (username = "username", password = "password")
>
> cli = omero.cli.CLI()
> cli.loadplugins()
> cli._client = client.createClient(secure = True)
> cli.invoke(["import", path_to_image_file])
>
>Note that you need to create a copy of the client when setting `_client`
>because that session will be closed after the image import.
>
>To find out the ID of the image you imported, you will need to get
>this call STDOUT. I have routinely [1] been doing the following (note
>that this imports a single file but should be easy to adjust for
>multiple files):
>
>
> cli = omero.cli.CLI()
> cli.loadplugins()
> cli._client = self.client.createClient(secure = True)
> cmd = [
> "import",
> "--debug", "ERROR",
> ]
> if self.datasetID:
> cmd.extend(["-d", str(self.datasetID)])
> if self.child_name:
> cmd.extend(["-n", self.child_name])
>
> cid = None
> with tempfile.NamedTemporaryFile(suffix=".stdout") as stdout:
> cmd.extend([
> "---errs", os.devnull,
> "---file", stdout.name,
> ])
> cmd.append(self.fout.name)
>
> STDERR = sys.stderr
> try:
> with open(os.devnull, 'w') as DEVNULL:
> sys.stderr = DEVNULL
> cli.invoke(cmd)
> finally:
> sys.stderr = STDERR
> ret_code = cli.rv
> if ret_code == 0:
> ## we only need to read one line or something is very wrong
> cid = int(stdout.readline())
> if not cid:
> raise Exception("unable to get exported image ID")
> else:
> raise Exception("failed to import processed image")
>
> self.child = self.conn.getObject("Image", cid)
>
>
>[1]
>https://github.com/MicronOxford/omero_scripts_processing/blob/40e29af8/ome
>ro_scripts_processing.py#L293
>_______________________________________________
>ome-devel mailing list
>ome-devel at lists.openmicroscopy.org.uk
>http://lists.openmicroscopy.org.uk/mailman/listinfo/ome-devel
The University of Dundee is a registered Scottish Charity, No: SC015096
More information about the ome-devel
mailing list