Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save eilidh-t/1ff51ca8e755fa8f186469a2f6ac7911 to your computer and use it in GitHub Desktop.
Save eilidh-t/1ff51ca8e755fa8f186469a2f6ac7911 to your computer and use it in GitHub Desktop.
Tests connecting to a remote OMERO server from within an OMERO.script on a local server.
# 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 = "user"
REMOTE_PASS = "password"
# 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
client = omero.scripts.client("test_connect")
c = omero.client(host='%s', port=4064, args=["--Ice.Config=/dev/null"])
c.createSession('%s', '%s')
print c
conn = BlitzGateway(client_obj=c)
for p in conn.getObjects("Project"):
print p.id, p.name
""" % (REMOTE_SERVER, REMOTE_USER, REMOTE_PASS)
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