-
-
Save eilidh-t/e763dab7d4f3515cc85b0b6ddfb8d9f4 to your computer and use it in GitHub Desktop.
A script to demonstrate an error when attempting to export an image file to a remote OMOERO server.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From e-mail: http://lists.openmicroscopy.org.uk/pipermail/ome-devel/2017-October/004076.html | |
# We upload and run an OMERO.script | |
# that can connect to another remote OMERO server. | |
from omero.gateway import BlitzGateway | |
import omero | |
USERNAME = "root" | |
PASSWORD = "omero" | |
REMOTE_SERVER = "demo.openmicroscopy.org" | |
REMOTE_USER = "" | |
REMOTE_PASS = "" | |
FILE_LOCATION = "/Users/eilidhtroup/omero/ManagedRepository/root_0/2017-10/06/" \ | |
"16-21-46.945/antibiotic_plate.jpg" | |
OMERO_SERVER = "/Users/eilidhtroup/Documents/SynthSysDataManagement/omero/" \ | |
"omeroServer/OMERO.server" | |
# First test if we can connect directly to remote server... | |
c = omero.client(host=REMOTE_SERVER, port=4064) | |
sf = c.createSession(REMOTE_USER, REMOTE_PASS) | |
print c, sf | |
# Upload script and try to connect | |
SCRIPT = """ | |
import omero | |
import omero.scripts as scripts | |
from omero.gateway import BlitzGateway | |
from path import path | |
import sys | |
import subprocess | |
remote_server = '%s' | |
remote_user = '%s' | |
remote_pass = '%s' | |
file_loc = '%s' | |
omero_dist = '%s' | |
client = omero.scripts.client("test_export_remote") | |
c = omero.client(host=remote_server, port=4064, args=["--Ice.Config=/dev/null"]) | |
c.createSession(remote_user, remote_pass) | |
print c | |
conn = BlitzGateway(client_obj=c) | |
for p in conn.getObjects("Project"): | |
print p.id, p.name | |
print "Connected, now to transfer image" | |
key = c.getSessionId() | |
# transfer image to remote omero | |
args = [sys.executable] | |
args.append(str(path(".") / "bin" / "omero")) | |
args.extend(["-s", remote_server, "-k", key, "-p", '4064', "import"]) | |
args.append(file_loc) | |
print "args are" | |
print args | |
# omero_server = os.environ.get('OMERO_SERVER'): # doesn't work from omero script, only from command line. | |
# TODO could get omero_dist as done in def omerodistdir(cls): | |
# from https://github.com/openmicroscopy/openmicroscopy/blob/develop/components/tools/OmeroPy/src/omero/testlib/__init__.py#L277 | |
popen = subprocess.Popen(args, | |
cwd=omero_dist, | |
stdout=subprocess.PIPE, | |
stderr=subprocess.PIPE) | |
out, err = popen.communicate() | |
rc = popen.wait() | |
if rc != 0: | |
raise Exception("import failed:",args, rc, err) | |
pix_ids = [] | |
print "Output" | |
print out | |
""" % (REMOTE_SERVER, REMOTE_USER, REMOTE_PASS, FILE_LOCATION, OMERO_SERVER) | |
conn = BlitzGateway(USERNAME, PASSWORD, host="localhost", port=4064) | |
conn.connect() | |
script_service = conn.getScriptService() | |
sessionId = conn._getSessionId() | |
script_id = script_service.uploadOfficialScript("test%s.py" % sessionId, SCRIPT) | |
proc = script_service.runScript(script_id, {}, None) | |
job = proc.getJob() | |
cb = omero.scripts.ProcessCallbackI(conn.c, proc) | |
try: | |
print "Job %s ready" % job.id.val | |
print "Waiting...." | |
while proc.poll() is None: | |
cb.block(1000) | |
print "Callback received: %s" % cb.block(0) | |
rv = proc.getResults(3) | |
finally: | |
cb.close() | |
# print rv | |
if rv.get('stderr'): | |
print "Error. See file: ", rv.get('stderr').getValue().id.val | |
if rv.get('stdout'): | |
print "Std out. See file: ", rv.get('stdout').getValue().id.val |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment