Changeset 2656
- Timestamp:
- 28/06/07 11:01:47 (14 years ago)
- Location:
- TI05-delivery/ows_framework/trunk/ows_wps/ows_wps
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TI05-delivery/ows_framework/trunk/ows_wps/ows_wps/execute.py
r2651 r2656 5 5 """ 6 6 Classes modelling the WPS 0.4 Execute package. 7 8 WPS 0.4 contains 3 separate data structures for representing output options: 9 1. ProcessDescription/ProcessOutputs/OutputDescription describes possible 10 formats for an output. 11 2. Execute(Response)/OutputDefinitions/OutputDefinition describes the 12 selected format for an output. 13 3. ExecuteResponse/ProcessOutputs/IOValue describes the actual output. 14 15 Of these only OutputDescription is modelled directly (in the 16 process_description module). The framework maps the 17 ExecuteStatus.inputs and ExecuteStatus.outputs dictionaries onto these 18 structures. 7 19 8 20 """ … … 15 27 ExecuteResponse that are under the control of the process. Other 16 28 parts are handled by the framework. 29 30 The inputs and outputs dictionary should share keys with the 31 description.inputs/outputs attributes respectively. 17 32 18 33 @ivar status 19 @type status: One of ACCEPTED, STARTED, SUCCEEDED34 @type status: One of PENDING, ACCEPTED, STARTED, SUCCEEDED, FAILED 20 35 @ivar statusMessage: This is the message put in the Status XML element 21 36 @type statusMessage: str 22 37 @ivar percentComplete 23 38 @type percentComplete: int or None 39 24 40 @ivar inputs 25 @type inputs: Iterable of IOValueobjects41 @type inputs: dictionary mapping input identifiers to python objects 26 42 @ivar outputs 27 @type outputs: Iterable of IOValueobjects43 @type outputs: dictionary mapping output identifiers to python objects 28 44 29 @note: Failed processes are caught as exceptions by the framework. 45 @ivar exceptionReport 46 @type exceptionReport: ExceptionReport if self.status=self.FAILED else None 30 47 31 48 """ 49 PENDING = 0 32 50 ACCEPTED = 1 33 51 STARTED = 2 34 52 SUCCEEDED = 3 53 FAILED = 4 35 54 36 55 def __init__(self, inputs=[], outputs=[], statusMessage=''): 37 self.status = self. ACCEPTED56 self.status = self.PENDING 38 57 self.statusMessage = statusMessage 39 58 self.percentComplete = None 40 59 self.inputs = inputs 41 60 self.outputs = outputs 61 self.exceptionReport = None 42 62 43 class IOValue(BasicIdentification): 44 """ 45 A simplified model of WPS IOValue. Only format 63 def setOutputs(self, **outputs): 64 """ 65 Ensure the keys in outputs match self.description.outputs and 66 set self.outputs accordingly. 46 67 47 """ 48 NotImplemented 49 68 """ 69 for k in outputs: 70 if k in self.description.outputs: 71 self.outputs[k] = outputs[k] 72 else: 73 raise ValueError("Output %s not in description" % k) -
TI05-delivery/ows_framework/trunk/ows_wps/ows_wps/process.py
r2651 r2656 8 8 """ 9 9 10 from ows_wps.execute import ExecuteStatus 11 from ows_common.exceptions import OwsError 12 from ows_wps.process_description import ProcessDescription 13 10 14 class Process(object): 11 15 """ 12 16 Process objects are instantiated with configuration options from the 13 17 environment and then the execute() method is called to perform the process. 14 15 @ivar description: Describes all process inputs and outputs using 16 ows_common and process_description packages. 17 @type description: A ProcessDescription object. 18 19 Subclasses implement specific processes. They should suply 20 Process.description to describe the process and implement the 21 run() method. 22 23 @cvar description: Describes the process implemented in this class. 24 @type description: ProcessDescription 25 @ivar status: describes the execute request and execution status 26 @type status: ExecuteStatus 27 @ivar context: describes the environment in which the process is executed. 28 This will provide filesystem hooks, etc. 29 """ 30 31 description = NotImplemented 32 33 def __init__(self, status, context): 34 """ 35 Initialise a process. The instance communicates through the status 36 object. Process parameters are extracted from status and the outputs 37 are referenced by the status object. 38 39 """ 40 self.status = status 41 self.context = context 42 43 self.status.status = status.ACCEPTED 44 45 46 def execute(self): 47 """ 48 Execute the process. This is called by the framework. The default 49 implementation passes self.inputs to self.run() as keyword arguments, 50 trapping any ows exceptions. 51 52 """ 53 try: 54 outputs = self.run(**self.status.inputs) 55 except OwsError, e: 56 self.status = self.status.FAILED 57 self.exceptionReport = e.report 58 else: 59 # Set the status outputs 60 self.status.setOutputs(**outputs) 61 62 63 def run(self, **inputs): 64 """ 65 Main process execution function. Override in subclasses. 66 67 By default this method is passed self.status.inputs as it's keyword 68 arguments. It should return a dictionary of outputs. 69 70 """ 71 raise NotImplementedError 72 73 74 #---------------------------------------------------------------------------- 75 76 from ows_wps.process_description import LiteralDomain 77 78 class FloatDomain(LiteralDomain): 79 def load(self, text): 80 return float(text) 81 82 class ExampleProcess(Process): 83 """ 84 Suply sum, difference and product of 2 floats. 18 85 19 86 """ 87 88 description = ProcessDescription( 89 identifier='ExampleProcess', 90 titles = ['Example of a very simple process'], 91 abstracts = ['Take two input and return the sum, difference ' 92 'and product'], 93 inputs = {'x': FloatDomain('1.2'), 94 'y': FloatDomain('6.5')}, 95 outputs = {'sum': FloatDomain(), 'diff': FloatDomain(), 96 'product': FloatDomain()} 97 ) 98 99 def run(self, x, y): 100 return dict(sum=x+y, diff=x-y, product=x*y) 101 -
TI05-delivery/ows_framework/trunk/ows_wps/ows_wps/process_description.py
r2651 r2656 6 6 Classes modelling WPS 0.4 process description. 7 7 8 The WPS 0.4 classes WPSDescription and ProcessBrief are very similar to 9 OWS Common 1.1.0 BasicIdentification therefore we inherit from this instead. 10 11 Values of Input/OutputDescription 12 --------------------------------- 13 14 InputDescription and OutputDescription elements contain one of 3 types 15 of values: 16 17 1. literal data (LiteralValuesChoice) 18 2. Complex data (SupportedComplexData) 19 3. bounding box data (SupportedCRSs) 20 21 These are modelled using several Domain classes defined here which 22 inherits from ows_common.domain.Domain. The purpose of these classes 23 is to implement conversion between python types and WPS serialisation. 24 25 1. LiteralDomain will instruct the framework to encode the domain as a 26 LiteralValue element. 27 2. ComplexDomain will instruct the framework to encode the domain as a 28 ComplexValue element. 29 3. SupportedCRSDomain will instruct the framework to encode the domain as a 30 SupportedCRSs element. 31 8 32 """ 9 33 10 34 from ows_common.data_identification import BasicIdentification 11 from ows_common.domain import PossibleValues 35 from ows_common.domain import Domain 36 from elementtree import ElementTree as ET 37 38 #---------------------------------------------------------------------------- 39 40 class WPSDomain(Domain): 41 """ 42 Defines the interface for (de)serialising input/output options. 43 44 """ 45 def load(self, text): 46 """ 47 Load the value into a python object. 48 49 """ 50 return text 51 52 def dump(self, obj): 53 """ 54 Serialise the value to a form suitable for embedding in XML. 55 56 """ 57 return str(obj) 58 59 60 class LiteralDomain(WPSDomain): 61 pass 62 63 64 class SupportedCRSDomain(WPSDomain): 65 pass 66 67 68 class ComplexDomain(WPSDomain): 69 def ows_load(self, text): 70 return ET.XML(text) 71 def ows_dump(self, obj): 72 return ET.tostring(obj) 73 74 75 #---------------------------------------------------------------------------- 12 76 13 77 class ProcessDescription(BasicIdentification): 14 78 """ 15 @ivar processVersion 16 @type processVersion: str or None 17 @ivar processInputs 18 @type processInputs: iterable of InputDescription objects 19 @ivar processOutputs 20 @type processOutputs: iterable of OutputDescription objects 79 @ivar version 80 @type version: str or None 81 @ivar inputs 82 @type inputs: dictionary mapping input identifiers to InputDescription 83 objects 84 @ivar outputs 85 @type outputs: dictionary mapping output identifiers to WPSDomain objects 21 86 22 87 @note: storeSupported and statusSupported are policies set by the server. 23 88 24 89 """ 25 def __init__(self, processInputs, processOutputs, processVersion=None,90 def __init__(self, inputs, outputs, version=None, 26 91 **kwargs): 27 92 super(ProcessDescription, self).__init__(**kwargs) 28 93 29 self. processVersion = processVersion30 self. processInputs = processInputs31 self. processOutputs = processOutputs94 self.version = version 95 self.inputs = processInputs 96 self.outputs = processOutputs 32 97 33 98 … … 38 103 @ivar maxOccurs 39 104 @type maxOccurs: int or None 40 @ivar inputFormChoice 41 @type inputFormChoice: A PossibleValues or SupportedCRSs object 42 43 @note: ComplexData isn't supported 105 @ivar inputFormChoice: specifies the valid values for this option. 106 @type inputFormChoice: WPSDomain 44 107 45 108 """ … … 55 118 class OutputDescription(BasicIdentification): 56 119 """ 57 @ivar outputFormChoice 58 @type outputFormChoice: A PossibleValues or SupportedCRSs object 59 60 @note: ComplexData isn't supported 120 @ivar outputFormChoice: specifies the valid format for this option. 121 @type outputFormChoice: WPSDomain 61 122 62 123 """ … … 66 127 self.outputFormChoice = outputFormChoice 67 128 68 69 class SupportedCRSs(object):70 """71 @ivar CRSs: URIs of supported CRSs72 @type CRSs: iterable of str73 @ivar defaultCRS74 @type defaultCRS: str75 76 """77 def __init__(self, defaultCRS, CRSs=[]):78 self.defaultCRS = defaultCRS79 self.CRSs = CRSs
Note: See TracChangeset
for help on using the changeset viewer.