openmicroscopy/openmicroscopy — pull request #1324 by joshmoore (2013-06-30 19:24:35+00:00)
Title: Jython scripts (See #918)

As a first candidate for non-Python scripts, this branch adds support for `*.jy` scripts to be placed under the `dist/lib/scripts` directory. At the moment, there is are no helper methods or libraries like there are for Python (see `OmeroPy/src/omero/scripts.py`) but the logic is otherwise quite straight-forward. An example script which could possibly be added to http://github.com/ome/scripts with some cleaning up is:

```
#!/usr/bin/env jython

"""
Example Jython script which can be dropped into
dist/lib/scripts in order to test multiple script
types.
"""

import omero

def get_params():
in1 = omero.grid.Param()
in1.optional = False
in1.prototype = omero.rtypes.rint(0)
in1.description = "Some arbitrary integer"

out1 = omero.grid.Param()
out1.optional = True
out1.prototype = omero.rtypes.rint(0)
out1.description = "Always 0"

params = omero.grid.JobParams()
params.name = "A.jy"
params.version = "0.0.1"
params.description = "An example Jython script"
params.inputs = {"in1": in1}
params.outputs = {"out1": out1}
params.stdoutFormat = "text/plain"
params.stderrFormat = "text/plain"

return omero.rtypes.rinternal(params)

c = omero.client()
try:
c.createSession().detachOnDestroy()
parse = c.getProperty("omero.scripts.parse")
if len(parse) > 0:
# Parsing. See OmeroPy/src/omero/scripts.py
# for the Python implementation.
# =========================================
c.setOutput("omero.scripts.parse", get_params())
raise Exception("Parsing") # Return code ignored.
else:
# Perform job
# =========================================
print "Found in1: ", c.getInput("in1")
print "Setting out1 to 0..."
c.setOutput("out1", omero.rtypes.rint(0))

finally:
c.__del__()
```

One possible next step for wrapping ImageJ plugins would be to auto-generate Jython files, but this would not allow using the ImageJ launcher. If the Jython scripts do not suffice, then we'll need to make the file ending (or mimetype?) to launcher mapping configurable. That commit can easily be added to this PR.