[ome-devel] command line importer
Josh Moore
josh at glencoesoftware.com
Wed May 18 18:36:21 BST 2011
On May 18, 2011, at 6:58 PM, Will Moore wrote:
> Hi Chris,
>
> I didn't write this, and I'm not too familiar with the code, but this is something we use in our Python testing framework to import images.
> components/tools/OmeroPy/test/integration/libraray.py
To explain that test code: the ids of any imported Pixels (not Images) will be written to stderr, one per line. You can either pass the "---errs" (note the three hyphens) argument to have it written to a file, or you can use popen.communicate() as is done below. You can also use the omero.cli classes in-process without a call to Popen. For example in http://git.openmicroscopy.org/src/develop/components/tools/OmeroFS/fsDropBoxMonitorClient.py (line 581):
cli = omero.cli.CLI()
cli.loadplugins()
cmd = ["-s", self.host, "-p", str(self.port), "-k", key, "import"]
cmd.extend([str("---errs=%s"%t), str("---file=%s"%to), "--"])
cmd.extend(shlex.split(self.importArgs))
cmd.append(fileName)
logging.debug("cli.invoke(%s)" % cmd)
cli.invoke(cmd)
retCode = cli.rv
but you should be aware that there was previously a bug in omero/cli.py (#4749) making it unsafe to have multiple CLI instances in a single Python interpreter working on different sessions.
Cheers,
~Josh
> def import_image(self, filename = None):
> if filename is None:
> filename = self.OmeroPy / ".." / ".." / ".." / "components" / "common" / "test" / "tinyTest.d3d.dv"
>
> server = self.client.getProperty("omero.host")
> port = self.client.getProperty("omero.port")
> key = self.client.getSessionId()
>
> # Search up until we find "OmeroPy"
> dist_dir = self.OmeroPy / ".." / ".." / ".." / "dist"
> args = ["python"]
> args.append(str(path(".") / "bin" / "omero"))
> args.extend(["-s", server, "-k", key, "-p", port, "import", filename])
> popen = subprocess.Popen(args, cwd=str(dist_dir), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
> out, err = popen.communicate()
> rc = popen.wait()
> if rc != 0:
> raise exceptions.Exception("import failed: [%r] %s\n%s" % (args, rc, err))
> pix_ids = []
> for x in out.split("\n"):
> if x and x.find("Created") < 0 and x.find("#") < 0:
> try: # if the line has an image ID...
> imageId = str(long(x.strip()))
> pix_ids.append(imageId)
> except: pass
> return pix_ids
>
>
> Hopefully you can work out what you need from this.
>
> Will.
>
> On 18 May 2011, at 17:16, Wood, Christopher wrote:
>
>> Also, when I use the command line importer (using the python subprocess module), is there a good way to get the image id?
>>
>> Thanks again.
>> Chris
>>
>> From: ome-devel-bounces at lists.openmicroscopy.org.uk [mailto:ome-devel-bounces at lists.openmicroscopy.org.uk] On Behalf Of Wood, Christopher
>> Sent: Wednesday, May 18, 2011 11:10 AM
>> To: ome-devel at lists.openmicroscopy.org.uk
>> Subject: [ome-devel] command line importer
>>
>> Hi,
>>
>> Is there an option for the command line importer to archive the imported file(s) (so the originals can be downloaded later)?
>>
>> Thanks
>> Chris
>>
>> --
More information about the ome-devel
mailing list