Hi Josh,
I tried to take what you provided and use it in the script I posted above to import (see below).
However, the stderr I get seems to indicate the import hasn't worked.
- Code: Select all
2018-06-20 23:49:29,034 216 [ main] INFO ome.formats.importer.ImportConfig - OMERO Version: 5.4.7-ice36-SNAPSHOT
2018-06-20 23:49:29,045 227 [ main] INFO ome.formats.importer.ImportConfig - Bioformats version: 5.8.2 revision: 07ecd9a5d239985f8ae57462c12124c2fa5ccd9b date: 18 April 2018
2018-06-20 23:49:29,075 257 [ main] INFO formats.importer.cli.CommandLineImporter - Log levels -- Bio-Formats: ERROR OMERO.importer: INFO
2018-06-20 23:49:29,349 531 [ main] INFO ome.formats.importer.ImportCandidates - Depth: 4 Metadata Level: MINIMUM
2018-06-20 23:49:29,396 578 [ main] INFO ome.formats.importer.ImportCandidates - 1 file(s) parsed into 1 group(s) with 1 call(s) to setId in 45ms. (47ms total) [0 unknowns]
Usage: importer-cli [OPTION]... [path [path ...]]...
or: importer-cli [OPTION]... -
...
Also, when I try to
- Code: Select all
client.setOutput("Message", rstring("Import complete"))
at the end
of the script, I see
- Code: Select all
omero.ClientError: No session available
in stderr, suggesting that
using the CLI has closed my session?
Script (run it on a Dataset)
- Code: Select all
import omero.scripts as scripts
from omero.gateway import BlitzGateway
import omero
import omero.cli
from omero.rtypes import rlong, rstring
def import_image(conn, scriptParams):
dataset = conn.getObject("Dataset", scriptParams["IDs"][0])
# Create test image to import
image = list(dataset.listChildren())[0]
pil_image = image.renderImage(0, 0)
image_name = "test_import.png"
pil_image.save(image_name)
# import via cli
client = conn.c
cmd = "import %s -d %s" % (image_name, dataset.id)
print cmd
cli = omero.cli.CLI()
cli.loadplugins()
cli.set_client(client)
cli.invoke(cmd)
def runAsScript():
"""
The main entry point of the script, as called by the client via the
scripting service, passing the required parameters.
"""
dataTypes = [rstring('Dataset')]
client = scripts.client(
'Import_CLI_Test.py',
"""Testing import via CLI from script""",
scripts.String(
"Data_Type", optional=False, grouping="1",
description="Choose source of images (only Dataset supported)",
values=dataTypes, default="Dataset"),
scripts.List(
"IDs", optional=False, grouping="2",
description="Dataset ID").ofType(rlong(0)),
)
try:
scriptParams = client.getInputs(unwrap=True)
print scriptParams
conn = BlitzGateway(client_obj=client)
import_image(conn, scriptParams)
client.setOutput("Message", rstring("Import complete"))
finally:
client.closeSession()
if __name__ == "__main__":
runAsScript()