Skip to content

Instantly share code, notes, and snippets.

@sbesson
Created May 25, 2012 13:29
Show Gist options
  • Save sbesson/2788173 to your computer and use it in GitHub Desktop.
Save sbesson/2788173 to your computer and use it in GitHub Desktop.
Test permissions/namespaces for figure scripts
#! /usr/local/bin/python
import omero
from omero.gateway import BlitzGateway
import omero.scripts
def runTests():
# List users to test
users = ["sebastien","test"]
wrongID = omero.rtypes.rlong(-1)
# Create Image ID sets for testing
validImageID = omero.rtypes.rlong(326)
imageIDs = []
imageIDs.append(omero.rtypes.rlist([wrongID]))
imageIDs.append(omero.rtypes.rlist([validImageID]))
imageIDs.append(omero.rtypes.rlist([validImageID,wrongID]))
imageIDs.append(omero.rtypes.rlist([wrongID,validImageID]))
# Create Image ID sets for testing
validDatasetID = omero.rtypes.rlong(201)
datasetIDs = []
datasetIDs.append(omero.rtypes.rlist([wrongID]))
datasetIDs.append(omero.rtypes.rlist([validDatasetID]))
datasetIDs.append(omero.rtypes.rlist([validDatasetID,wrongID]))
datasetIDs.append(omero.rtypes.rlist([wrongID,validDatasetID]))
# Create client
server = "localhost"
client = omero.client(server)
figureScripts = ["Movie_Figure","Movie_ROI_Figure","ROI_Split_Figure","Split_View_Figure",
"Thumbnail_Figure"]
for scriptName in figureScripts:
print "Script: %s\n" % (scriptName)
# Test for all users
for user in users:
try:
# Create BlitzGateway
client.createSession(user,"omero")
conn = BlitzGateway(client_obj=client)
print " User: %s\n" % user
# Test with images sets
for IDs in imageIDs:
runFigureScripts(conn,scriptName,IDs)
# Test with datasets for Thumbnail Figure script
if scriptName is "Thumbnail_Figure":
for IDs in datasetIDs:
runFigureScripts(conn,scriptName,IDs,dataType="Dataset")
finally:
client.closeSession()
def runFigureScripts(conn,scriptName,IDs,dataType="Image"):
# Get sriptID and run it
print " %s(s): %s" % (dataType, printRList(IDs))
scriptService = conn.getScriptService()
scriptID =scriptService.getScriptID("/omero/figure_scripts/"+scriptName +".py")
proc = scriptService.runScript(scriptID, {"IDs": IDs,"Data_Type": omero.rtypes.rstring(dataType)}, None)
try:
cb = omero.scripts.ProcessCallbackI(conn.c, proc)
while not cb.block(1000): # ms.
pass
cb.close()
results = proc.getResults(0) # ms
finally:
proc.close(False)
print " Message: %s" % (results["Message"].val)
if "File_Annotation" in results:
if results["File_Annotation"].val.getNs():
print " Namespace: %s" % results["File_Annotation"].val.getNs().val
print ""
def printRList(rlist):
list = omero.rtypes.unwrap(rlist)
return ', '.join(map(str,list))
if __name__ == "__main__":
runTests()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment