Package omero :: Module scripts
[hide private]
[frames] | no frames]

Source Code for Module omero.scripts

  1  #!/usr/bin/env python 
  2  """ 
  3     Scripting types 
  4         - Classes: 
  5             - Type        --  Top of parameter type hierarchy 
  6             - Long        -- 
  7             - String      -- 
  8             - Bool        -- 
  9   
 10         - Functions: 
 11             - client      -- Produces an omero.client object with given input/output constraints. 
 12   
 13     Copyright 2008 Glencoe Software, Inc. All rights reserved. 
 14     Use is subject to license terms supplied in LICENSE.txt 
 15   
 16  """ 
 17   
 18  import exceptions, omero 
 19  from omero.rtypes import * 
 20   
21 -class Type:
22 - def __init__(self, name, optional = False, out = False):
23 self.name = name 24 self.type = None 25 self.optional = optional 26 self._in = True 27 self._out = out
28 - def out(self):
29 self._in = False 30 self._out = True 31 return self
32 - def inout(self):
33 self._in = True 34 self._out = True 35 return self
36 - def optional(self):
37 self.optional = True 38 return self
39
40 -class Long(Type):
41 - def __init__(self, name, optional = False, out = False):
42 Type.__init__(self, name, optional, out) 43 self.type = rlong(0)
44 -class String(Type):
45 - def __init__(self, name, optional = False, out = False):
46 Type.__init__(self, name, optional, out) 47 self.type = rstring("")
48 -class Bool(Type):
49 - def __init__(self, name, optional = False, out = False):
50 Type.__init__(self, name, optional, out) 51 self.type = rbool(False)
52 -class Point(Type):
53 - def __init__(self, name, optional = False, out = False):
54 Type.__init__(self, name, optional, out) 55 self.type = rinternal(omero.Point())
56 -class Plane(Type):
57 - def __init__(self, name, optional = False, out = False):
58 Type.__init__(self, name, optional, out) 59 self.type = rinternal(omero.Plane())
60 -class Set(Type):
61 - def __init__(self, name, optional = False, out = False, *contents):
62 Type.__init__(self, name, optional, out) 63 self.type = rset(contents)
64 -class Map(Type):
65 - def __init__(self, name, optional = False, out = False, **contents):
66 Type.__init__(self, name, optional, out) 67 self.type = rmap(contents)
68
69 -class ParseExit(exceptions.Exception):
70 """ 71 Raised when this script should just parse parameters and return. 72 """ 73
74 - def __init__(self, params):
75 exceptions.Exception.__init__(self) 76 self.params = params
77
78 -def client(name, description = None, *args, **kwargs):
79 """ 80 Entry point for all script engine scripts. 81 82 Typical usage consists of:: 83 84 client = omero.scripts.client("name","description", \ 85 omero.scripts.Long("name"),...) 86 87 where the returned client is created via the empty constructor to omero.client 88 using only --Ice.Config or ICE_CONFIG, and the function arguments are taken 89 as metdata about the current script. With this information, all script 90 consumers should be able to determine the required types for execution. 91 92 Possible types are all subclasses of omero.scripts.Type 93 94 To change the omero.model.Format of the stdout and stderr produced by 95 this script, use the constructor arguments:: 96 97 client = omero.scripts.client(..., \ 98 stdoutFormat = "text/plain", 99 stderrFormat = "text/plain") 100 101 If you would like to prevent stdout and/or stderr from being 102 uploaded, set the corresponding value to None. If you would like 103 to overwrite the value with another file, use 104 client.setOutput(). Though it is possible to attach any RType to 105 "stdout" or "stderr", there is an assumption that the value will 106 be an robject(OriginalFileI()) 107 108 Providing your own client is possible via the kwarg "client = ...", 109 but be careful since this may break usage with the rest of the 110 scripting framework. The client should not have a session, and 111 must be configured for the argumentless version of createSession() 112 """ 113 114 # Checking kwargs 115 if not kwargs.has_key("stdoutFormat"): 116 kwargs["stdoutFormat"]="text/plain" 117 if not kwargs.has_key("stderrFormat"): 118 kwargs["stderrFormat"]="text/plain" 119 if not kwargs.has_key("client"): 120 kwargs["client"] = omero.client() 121 122 c = kwargs["client"] 123 c.params = omero.grid.JobParams() 124 c.params.name = name 125 c.params.description = description 126 c.params.inputs = {} 127 c.params.outputs = {} 128 c.params.stdoutFormat = kwargs["stdoutFormat"] 129 c.params.stderrFormat = kwargs["stderrFormat"] 130 for p in args: 131 param = omero.grid.Param() 132 param.name = p.name 133 param.optional = p.optional 134 param.prototype = p.type 135 if p._in: 136 c.params.inputs[p.name] = param 137 if p._out: 138 c.params.outputs[p.name] = param 139 140 c.createSession().detachOnDestroy() 141 handleParse(c) # May throw 142 return c
143
144 -def handleParse(c):
145 if len(c.getProperty("omero.scripts.parse")) > 0: # TODO Add to omero/Constants.ice 146 c.setOutput("omero.scripts.parse", rinternal(c.params)) 147 raise ParseExit(c.params)
148