Ignore:
Timestamp:
28/06/07 11:01:47 (12 years ago)
Author:
spascoe
Message:

More flesh on ows_wps. A trivial example process is implemented. Now
we need a process container to run it.

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  
    55""" 
    66Classes modelling the WPS 0.4 Execute package. 
     7 
     8WPS 0.4 contains 3 separate data structures for representing output options: 
     91. ProcessDescription/ProcessOutputs/OutputDescription describes possible 
     10   formats for an output. 
     112. Execute(Response)/OutputDefinitions/OutputDefinition describes the 
     12   selected format for an output. 
     133. ExecuteResponse/ProcessOutputs/IOValue describes the actual output. 
     14 
     15Of these only OutputDescription is modelled directly (in the 
     16process_description module).  The framework maps the 
     17ExecuteStatus.inputs and ExecuteStatus.outputs dictionaries onto these 
     18structures. 
    719 
    820""" 
     
    1527    ExecuteResponse that are under the control of the process.  Other 
    1628    parts are handled by the framework. 
     29 
     30    The inputs and outputs dictionary should share keys with the 
     31    description.inputs/outputs attributes respectively. 
    1732     
    1833    @ivar status 
    19     @type status: One of ACCEPTED, STARTED, SUCCEEDED 
     34    @type status: One of PENDING, ACCEPTED, STARTED, SUCCEEDED, FAILED 
    2035    @ivar statusMessage: This is the message put in the Status XML element 
    2136    @type statusMessage: str 
    2237    @ivar percentComplete 
    2338    @type percentComplete: int or None 
     39 
    2440    @ivar inputs 
    25     @type inputs: Iterable of IOValue objects 
     41    @type inputs: dictionary mapping input identifiers to python objects 
    2642    @ivar outputs 
    27     @type outputs: Iterable of IOValue objects 
     43    @type outputs: dictionary mapping output identifiers to python objects 
    2844 
    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 
    3047 
    3148    """ 
     49    PENDING = 0 
    3250    ACCEPTED = 1 
    3351    STARTED = 2 
    3452    SUCCEEDED = 3 
     53    FAILED = 4 
    3554     
    3655    def __init__(self, inputs=[], outputs=[], statusMessage=''): 
    37         self.status = self.ACCEPTED 
     56        self.status = self.PENDING 
    3857        self.statusMessage = statusMessage 
    3958        self.percentComplete = None 
    4059        self.inputs = inputs 
    4160        self.outputs = outputs 
     61        self.exceptionReport = None 
    4262 
    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. 
    4667 
    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  
    88""" 
    99 
     10from ows_wps.execute import ExecuteStatus 
     11from ows_common.exceptions import OwsError 
     12from ows_wps.process_description import ProcessDescription 
     13 
    1014class Process(object): 
    1115    """ 
    1216    Process objects are instantiated with configuration options from the 
    1317    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 
     76from ows_wps.process_description import LiteralDomain 
     77 
     78class FloatDomain(LiteralDomain): 
     79    def load(self, text): 
     80        return float(text) 
     81 
     82class ExampleProcess(Process): 
     83    """ 
     84    Suply sum, difference and product of 2 floats. 
    1885 
    1986    """ 
     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  
    66Classes modelling WPS 0.4 process description. 
    77 
     8The WPS 0.4 classes WPSDescription and ProcessBrief are very similar to 
     9OWS Common 1.1.0 BasicIdentification therefore we inherit from this instead. 
     10 
     11Values of Input/OutputDescription 
     12--------------------------------- 
     13 
     14InputDescription and OutputDescription elements contain one of 3 types 
     15of values: 
     16 
     171. literal data (LiteralValuesChoice) 
     182. Complex data (SupportedComplexData) 
     193. bounding box data (SupportedCRSs) 
     20 
     21These are modelled using several Domain classes defined here which 
     22inherits from ows_common.domain.Domain.  The purpose of these classes 
     23is to implement conversion between python types and WPS serialisation. 
     24 
     251. LiteralDomain will instruct the framework to encode the domain as a 
     26   LiteralValue element. 
     272. ComplexDomain will instruct the framework to encode the domain as a 
     28   ComplexValue element. 
     293. SupportedCRSDomain will instruct the framework to encode the domain as a 
     30   SupportedCRSs element. 
     31 
    832""" 
    933 
    1034from ows_common.data_identification import BasicIdentification 
    11 from ows_common.domain import PossibleValues 
     35from ows_common.domain import Domain 
     36from elementtree import ElementTree as ET 
     37 
     38#---------------------------------------------------------------------------- 
     39 
     40class 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     
     60class LiteralDomain(WPSDomain): 
     61    pass 
     62 
     63 
     64class SupportedCRSDomain(WPSDomain): 
     65    pass 
     66 
     67 
     68class 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#---------------------------------------------------------------------------- 
    1276 
    1377class ProcessDescription(BasicIdentification): 
    1478    """ 
    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 
    2186 
    2287    @note: storeSupported and statusSupported are policies set by the server. 
    2388 
    2489    """ 
    25     def __init__(self, processInputs, processOutputs, processVersion=None, 
     90    def __init__(self, inputs, outputs, version=None, 
    2691                 **kwargs): 
    2792        super(ProcessDescription, self).__init__(**kwargs) 
    2893 
    29         self.processVersion = processVersion 
    30         self.processInputs = processInputs 
    31         self.processOutputs = processOutputs 
     94        self.version = version 
     95        self.inputs = processInputs 
     96        self.outputs = processOutputs 
    3297 
    3398 
     
    38103    @ivar maxOccurs 
    39104    @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 
    44107 
    45108    """ 
     
    55118class OutputDescription(BasicIdentification): 
    56119    """ 
    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 
    61122 
    62123    """ 
     
    66127        self.outputFormChoice = outputFormChoice 
    67128 
    68  
    69 class SupportedCRSs(object): 
    70     """ 
    71     @ivar CRSs: URIs of supported CRSs 
    72     @type CRSs: iterable of str 
    73     @ivar defaultCRS 
    74     @type defaultCRS: str 
    75  
    76     """ 
    77     def __init__(self, defaultCRS, CRSs=[]): 
    78         self.defaultCRS = defaultCRS 
    79         self.CRSs = CRSs 
Note: See TracChangeset for help on using the changeset viewer.