[Pywps-commits] r476 - in trunk: . doc pywps pywps/Templates pywps/Templates/inc pywps/WPS pywps/etc pywps/processes3

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Apr 23 16:03:56 CEST 2008


Author: jachym
Date: 2008-04-23 16:03:56 +0200 (Wed, 23 Apr 2008)
New Revision: 476

Added:
   trunk/pywps/Templates/inc/Execute_Data_Inputs.tmpl
Removed:
   trunk/pywps/Templates/inc/Execute_Data.tmpl
Modified:
   trunk/doc/wps_execute_request-rawdataoutput.xml
   trunk/pywps/InAndOutputs.py
   trunk/pywps/Process.py
   trunk/pywps/Templates/Execute.tmpl
   trunk/pywps/WPS/DescribeProcess.py
   trunk/pywps/WPS/Execute.py
   trunk/pywps/WPS/Request.py
   trunk/pywps/etc/pywps.cfg
   trunk/pywps/processes3/buffer.py
   trunk/wps3.py
Log:
execute fast usable

Modified: trunk/doc/wps_execute_request-rawdataoutput.xml
===================================================================
--- trunk/doc/wps_execute_request-rawdataoutput.xml	2008-04-17 13:05:01 UTC (rev 475)
+++ trunk/doc/wps_execute_request-rawdataoutput.xml	2008-04-23 14:03:56 UTC (rev 476)
@@ -11,8 +11,7 @@
 			RawDataOutput=[BufferedPolygon]
 
 -->
-<wps:Execute service="WPS" version="1.0.0" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0
-..\wpsExecute_request.xsd">
+<wps:Execute service="WPS" version="1.0.0" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0/wpsExecute_request.xsd">
 	<ows:Identifier>buffer</ows:Identifier>
 	<wps:DataInputs>
 		<wps:Input>
@@ -30,7 +29,7 @@
 	</wps:DataInputs>
 	<wps:ResponseForm>
 		<wps:RawDataOutput>
-			<ows:Identifier>buffer</ows:Identifier>
+			<ows:Identifier>text</ows:Identifier>
 		</wps:RawDataOutput>
 	</wps:ResponseForm>
 </wps:Execute>

Modified: trunk/pywps/InAndOutputs.py
===================================================================
--- trunk/pywps/InAndOutputs.py	2008-04-17 13:05:01 UTC (rev 475)
+++ trunk/pywps/InAndOutputs.py	2008-04-23 14:03:56 UTC (rev 476)
@@ -111,7 +111,7 @@
 class ComplexInput(Input):
     def __init__(self,identifier,title,abstract=None,
                 metadata=[],minOccurs=1,maxOccurs=1,
-                maxmegabites=0.1,formats=[{"mimetype":"text/xml"}]):
+                maxmegabites=0.1,formats=[{"mimeType":"text/xml"}]):
         Input.__init__(self,identifier,title,abstract=None,
                 metadata=[],minOccurs=minOccurs,maxOccurs=maxOccurs,type="ComplexValue")
         
@@ -123,7 +123,7 @@
 
 
         if type(formats) == types.StringType:
-            formats = [{"mimetype":formats,"encoding":None,"schema":None}]
+            formats = [{"mimeType":formats,"encoding":None,"schema":None}]
         elif type(formats) == types.DictType:
             formats = [formats]
 
@@ -214,12 +214,14 @@
 
 class Output:
     def __init__(self,identifier,title,abstract=None,
-                metadata=[],type=None):
+                metadata=[],type=None, asReference=False):
         self.identifier = identifier
         self.title = title
         self.abstract = abstract
         self.metadata = metadata
         self.type = type
+        self.asReference = asReference
+        self.value = None
         return
 
     def setValue(self,value):
@@ -228,23 +230,28 @@
 class LiteralOutput(Output):
     def __init__(self,identifier,title,abstract=None,
                 metadata=[], uoms=(), dataType = types.StringType, 
-                default=None):
+                default=None, asReference=False):
         Output.__init__(self,identifier,title,abstract=None,
-                metadata=[],type="LiteralValue")
+                metadata=[],type="LiteralValue",asReference=asReference)
         
         self.uoms = uoms
+        if len(self.uoms) > 0:
+            self.uom = self.uoms[0]
+        else:
+            self.uom = None
         self.default = default
         self.dataType = dataType
         return
 
 class ComplexOutput(Output):
     def __init__(self,identifier,title,abstract=None,
-                metadata=[], formats=[{"mimetype":"text/xml"}]):
+                metadata=[], formats=[{"mimeType":"text/xml"}],
+                asReference=False):
         Output.__init__(self,identifier,title,abstract=None,
-                metadata=[],type="ComplexValue")
+                metadata=[],type="ComplexValue", asReference=asReference)
         
         if type(formats) == types.StringType:
-            formats = [{"mimetype":formats,"encoding":None,"schema":None}]
+            formats = [{"mimeType":formats,"encoding":None,"schema":None}]
         elif type(formats) == types.DictType:
             formats = [formats]
 
@@ -255,6 +262,7 @@
                 format["schema"] = None
 
         self.formats = formats
+        self.format = formats[0]
         return
 
     def setValue(self,value):
@@ -262,9 +270,9 @@
 
 class BoundingBoxOutput(Output):
     def __init__(self,identifier,title,abstract=None,
-                metadata=[], crss=[]):
+                metadata=[], crss=[], asReference=False):
         Output.__init__(self,identifier,title,abstract=None,
-                metadata=[],type="BoundingBoxValue")
+                metadata=[],type="BoundingBoxValue",asReference=asReference)
         
         self.crss = crss
         return

Modified: trunk/pywps/Process.py
===================================================================
--- trunk/pywps/Process.py	2008-04-17 13:05:01 UTC (rev 475)
+++ trunk/pywps/Process.py	2008-04-23 14:03:56 UTC (rev 476)
@@ -29,40 +29,49 @@
 class Status:
     def __init__(self):
         self.creationTime = time.time()
-        self.processAccepted = False
-        self.processStarted = False
-        self.processPaused = False
-        self.processSucceeded = False
-        self.processFailed = False
-
-        self.processCompleted = 0
+        self.code = None
+        self.percentCompleted = 0
         self.exceptionReport = None
+        self.code = None
+        self.value = None
 
-    def set(self, msg="",percentDone=0):
+    def set(self, msg="",percentDone=0, propagate=True):
+        """
+        propagate - call onStatusChanged method
+        """
+        self.code = "processstarted"
         if (type(percentDone) == types.StringType):
-            self.processCompleted += int(percentDone)
+            self.percentCompleted += int(percentDone)
         else:
-            self.processCompleted = percentDone
-        self.onStatusChanged()
+            self.percentCompleted = percentDone
 
+        if not msg:
+            msg = "True"
+
+        self.value = msg
+
+        if propagate:
+            self.onStatusChanged()
+
     def onStatusChanged(self):
         """
         To be redefined by other methods
         """
         pass
 
-    def setProcessStatus(self,name,value):
-        if name == "processAccepted":
-            self.processAccepted = value
-        elif name == "processStarted":
-            self.processStarted = value
-        elif name == "processPaused":
-            self.processPaused = value
-        elif name == "processSucceeded":
-            self.processSucceeded = value
-        elif name == "processFailed":
-            self.processFailed = value
+    def setProcessStatus(self,code,value):
+        """
+        Sets current status of the process. Calls onStatusChanged method
+        """
 
+        self.value = value
+        self.code = code.lower()
+
+        if self.code != "processfailed":
+            self.onStatusChanged()
+        return
+
+
 class WPSProcess:
     """
     """
@@ -77,6 +86,13 @@
         self.abstract = abstract
         self.wsdl  = None
         self.profile = profile
+        # "true" or "True" -> True
+        if type(storeSupported) == type(""):
+            if storeSupported.find("t") == 0 or\
+                storeSupported.find("T") == 0:
+                storeSupported = True
+            else:
+                storeSupported = False
         self.storeSupported = storeSupported
         self.statusSupported = statusSupported
         self.debug = False
@@ -111,7 +127,7 @@
 
     def addComplexInput(self,identifier,title,abstract=None,
                 metadata=[],minOccurs=1,maxOccurs=1,
-                formats=[{"mimetype":"text/xml"}],maxmegabites=0.1):
+                formats=[{"mimeType":"text/xml"}],maxmegabites=0.1):
 
         self.inputs[identifier] = InAndOutputs.ComplexInput(identifier=identifier,
                 title=title,abstract=abstract,
@@ -134,23 +150,25 @@
     # --------------------------------------------------------------------
 
     def addComplexOutput(self,identifier,title,abstract=None,
-            metadata=[],formats=[{"mimetype":"text/xml"}]):
+            metadata=[],formats=[{"mimeType":"text/xml"}],
+            asReference=False):
 
         self.outputs[identifier] = InAndOutputs.ComplexOutput(identifier=identifier,
                 title=title,abstract=abstract,
-                metadata=[], formats=formats)
+                metadata=[], formats=formats, asReference=asReference)
 
         return self.outputs[identifier]
 
     def addLiteralOutput(self, identifier, title, abstract=None,
-            uoms=(), type=types.IntType, default=None):
+            uoms=(), type=types.IntType, default=None,
+           asReference=False):
         """
         Add new output item of type LiteralValue to this process
         """
 
         self.outputs[identifier] = InAndOutputs.LiteralOutput(identifier=identifier,
                 title=title, abstract=abstract, dataType=type, uoms=uoms, 
-                default=None)
+                default=None, asReference=asReference)
 
         return self.outputs[identifier]
 

Modified: trunk/pywps/Templates/Execute.tmpl
===================================================================
--- trunk/pywps/Templates/Execute.tmpl	2008-04-17 13:05:01 UTC (rev 475)
+++ trunk/pywps/Templates/Execute.tmpl	2008-04-23 14:03:56 UTC (rev 476)
@@ -1,107 +1,110 @@
-<?xml version="1.0" encoding="<TMPL_VAR encoding>"?>
-<wps:ExecuteResponse xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 ..\wpsExecute_response.xsd" service="WPS" version="1.0.0" xml:lang="<TMPL_VAR lang>" serviceInstance="<TMPL_VAR serviceinstance>" statusLocation="<TMPL_VAR statuslocation>">
-    <wps:Process wps:processVersion="<TMPL_VAR version>">
-        <ows:Identifier><TMPL_VAR identifier></ows:Identifier>
-        <ows:Title><TMPL_VAR title></ows:Title>
-        <TMPL_IF abstract>
-        <ows:Abstract><TMPL_VAR abstract></ows:Abstract>
-        </TMPL_IF>
-        <TMPL_IF profile>
-        <wps:Profile><TMPL_VAR profile></wps:Profile>
-        </TMPL_IF>
-        <TMPL_IF wsdl>
-        <wps:WSDL xlink:href="<TMPL_VAR wsdl>"/>
-        </TMPL_IF>
-    </wps:Process>
-    <wps:Status creationTime="<TMPL_VAR statustime>">
-        <TMPL_IF processsucc>
-        <wps:ProcessSucceeded><TMPL_VAR processsucc></wps:ProcessSucceeded>
-        </TMPL_IF>
-        <TMPL_IF processaccepted>
-        <wps:ProcessAccepted><TMPL_VAR processaccepted></wps:ProcessAccepted>
-        </TMPL_IF>
-        <TMPL_IF processstarted>
-        <wps:ProcessStarted percentCompleted="<TMPL_VAR percentcompleted>"><TMPL_VAR processstarted></wps:ProcessStarted>
-        </TMPL_IF>
-        <TMPL_IF processpaused>
-        <wps:ProcessPaused percentCompleted="<TMPL_VAR percentcompleted>"><TMPL_VAR processpaused></wps:ProcessPaused>
-        </TMPL_IF>
-        <TMPL_IF processfailed>
-        <wps:ProcessFailed>
-            <wps:ExceptionReport>
-                <TMPL_IF exceptiontext>
-                <ows:Exception exceptionCode="<TMPL_VAR exceptioncode>" locator="<TMPL_VAR locator>">
-                    <ows:ExceptionText><TMPL_VAR exceptiontext></ows:ExceptionText>
-                <TMPL_ELSE>
-                <ows:Exception exceptionCode="<TMPL_VAR exceptioncode>" locator="<TMPL_VAR locator>" />
-                </TMPL_IF>
-            </wps.ExceptionReport>
-        </wps:ProcessFailed>
-        </TMPL_IF>
-    </wps:Status>
-    <TMPL_IF lineage>
-    <wps:DataInputs>
-        <TMPL_LOOP Inputs>
-        <wps:Input>
-            <ows:Identifier><TMPL_VAR identifier></ows:Identifier>
-            <ows:Title><TMPL_VAR title></ows:Title>
-            <TMPL_IF abstract>
-            <ows:Abstract>
-                <TMPL_VAR abstract>
-            </ows:Abstract>
-            </TMPL_IF>
-            <TMPL_IF reference>
-            <wps:Reference xlink:href="<TMPL_VAR reference>" method="<TMPL_VAR method>" mimeType="<TMPL_VAR mimetype>" encoding="<TMPL_VAR encoding>" schema="<TMPL_VAR schema>"/>
-                <TMPL_IF header>
-                <wps:Header key="<TMPL_VAR key>" value="<TMPL_VAR value>" />
-                </TMPL_IF>
-                <TMPL_IF body>
-                <wps:Body>
-                    <TMPL_VAR body>
-                </wps:Body>
-                </TMPL_IF>
-                <TMPL_IF bodyReference>
-                <wps:BodyReference xlink:href="<TMPL_VAR bodyreference>" />
-                </TMPL_IF>
-            <TMPL_ELSE>
-                <TMPL_INCLUDE NAME="Execute_Data.tmpl">
-            </TMPL_IF>
-        </wps:Input>
-        </TMPL_LOOP>
-    </wps:DataInputs>
-    <wps:OutputDefinitions mimeType="text/xml" encoding="UTF-8" schema="http://foo.bar/gml_polygon_schema.xsd" asReference="true">
-    <TMPL_LOOP outputDefinitions>
-        <wps:Output>
-            <ows:Identifier><TMPL_VAR identifier></ows:Identifier>
-            <ows:Title><TMPL_VAR title></ows:Title>
-            <TMPL_IF abstract>
-            <ows:Abstract><TMPL_VAR abstract></ows:Abstract>
-            </TMPL_IF>
-            <TMPL_IF reference>
-            <wps:Reference format="<TMPL_VAR format>" encoding="<TMPL_VAR encoding>" schema="<TMPL_VAR schema>" xlink:href="<TMPL_VAR reference>" />
-            <TMPL_ELSE>
-                <TMPL_INCLUDE NAME="Execute_Data.tmpl">
-            </TMPL_IF>
-        </wps:Output>
-    </TMPL_LOOP>
-    </wps:OutputDefinitions>
-    </TMPL_IF>
-    <TMPL_IF processsucceeded>
-    <wps:ProcessOutputs>
-        <TMPL_LOOP outputs>
-        <wps:Output>
-            <ows:Identifier><TMPL_VAR identifier></ows:Identifier>
-            <ows:Title><TMPL_VAR title></ows:Title>
-            <TMPL_IF abstract>
-            <ows:Abstract><TMPL_VAR abstract></ows:Abstract>
-            </TMPL_IF>
-            <TMPL_IF reference>
-            <wps:Reference xlink:href="<TMPL_VAR reference>" mimeType="<TMPL_VAR mimetype>" encoding="<TMPL_VAR encoding>" schema="TMPL_VAR schema>"/>
-            <TMPL_ELSE>
-                <TMPL_INCLUDE NAME="Execute_Data.tmpl">
-            </TMPL_IF>
-        </wps:Output>
-        </TMPL_LOOP>
-    </wps:ProcessOutputs>
-    </TMPL_IF>
-</wps:ExecuteResponse>
+<?xml version="1.0" encoding="<TMPL_VAR encoding>"?>
+<wps:ExecuteResponse xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 ..\wpsExecute_response.xsd" service="WPS" version="1.0.0" xml:lang="<TMPL_VAR lang>" serviceInstance="<TMPL_VAR serviceinstance>" statusLocation="<TMPL_VAR statuslocation>">
+    <wps:Process wps:processVersion="<TMPL_VAR version>">
+        <ows:Identifier><TMPL_VAR identifier></ows:Identifier>
+        <ows:Title><TMPL_VAR title></ows:Title>
+        <TMPL_IF abstract>
+        <ows:Abstract><TMPL_VAR abstract></ows:Abstract>
+        </TMPL_IF>
+        <TMPL_IF profile>
+        <wps:Profile><TMPL_VAR profile></wps:Profile>
+        </TMPL_IF>
+        <TMPL_IF wsdl>
+        <wps:WSDL xlink:href="<TMPL_VAR wsdl>"/>
+        </TMPL_IF>
+    </wps:Process>
+    <wps:Status creationTime="<TMPL_VAR statustime>">
+        <TMPL_IF processsucceeded>
+        <wps:ProcessSucceeded><TMPL_VAR processsucceeded></wps:ProcessSucceeded>
+        </TMPL_IF>
+        <TMPL_IF processaccepted>
+        <wps:ProcessAccepted><TMPL_VAR processaccepted></wps:ProcessAccepted>
+        </TMPL_IF>
+        <TMPL_IF processstarted>
+        <wps:ProcessStarted percentCompleted="<TMPL_VAR percentcompleted>"><TMPL_VAR processstarted></wps:ProcessStarted>
+        </TMPL_IF>
+        <TMPL_IF processpaused>
+        <wps:ProcessPaused percentCompleted="<TMPL_VAR percentcompleted>"><TMPL_VAR processpaused></wps:ProcessPaused>
+        </TMPL_IF>
+        <TMPL_IF processfailed>
+        <wps:ProcessFailed>
+            <wps:ExceptionReport>
+                <TMPL_IF exceptiontext>
+                <ows:Exception exceptionCode="<TMPL_VAR exceptioncode>" locator="<TMPL_VAR locator>">
+                    <ows:ExceptionText><TMPL_VAR exceptiontext></ows:ExceptionText>
+                <TMPL_ELSE>
+                <ows:Exception exceptionCode="<TMPL_VAR exceptioncode>" locator="<TMPL_VAR locator>" />
+                </TMPL_IF>
+            </wps.ExceptionReport>
+        </wps:ProcessFailed>
+        </TMPL_IF>
+    </wps:Status>
+    <TMPL_IF lineage>
+    <wps:DataInputs>
+        <TMPL_LOOP Inputs>
+        <wps:Input>
+            <ows:Identifier><TMPL_VAR identifier></ows:Identifier>
+            <ows:Title><TMPL_VAR title></ows:Title>
+            <TMPL_IF abstract>
+            <ows:Abstract>
+                <TMPL_VAR abstract>
+            </ows:Abstract>
+            </TMPL_IF>
+            <TMPL_IF reference>
+            <wps:Reference xlink:href="<TMPL_VAR reference>" method="<TMPL_VAR method>" mimeType="<TMPL_VAR mimetype>" encoding="<TMPL_VAR encoding>" schema="<TMPL_VAR schema>"/>
+                <TMPL_IF header>
+                <wps:Header key="<TMPL_VAR key>" value="<TMPL_VAR value>" />
+                </TMPL_IF>
+                <TMPL_IF body>
+                <wps:Body>
+                    <TMPL_VAR body>
+                </wps:Body>
+                </TMPL_IF>
+                <TMPL_IF bodyReference>
+                <wps:BodyReference xlink:href="<TMPL_VAR bodyreference>" />
+                </TMPL_IF>
+            <TMPL_ELSE>
+                <TMPL_INCLUDE NAME="Execute_Data_Inputs.tmpl">
+            </TMPL_IF>
+        </wps:Input>
+        </TMPL_LOOP>
+    </wps:DataInputs>
+    <wps:OutputDefinitions>
+    <TMPL_LOOP Outputdefinitions>
+        <TMPL_IF complexdata>
+        <wps:Output mimeType="<TMPL_VAR mimetype>" encoding="<TMPL_VAR encoding>" schema="<TMPL_VAR schema>" asReference="<TMPL_VAR asreference>">
+        </TMPL_IF>
+        <TMPL_IF literaldata>
+        <wps:Output <TMPL_VAR uom>>
+        </TMPL_IF>
+        <TMPL_IF bboxdata>
+        <wps:Output>
+        </TMPL_IF>
+            <ows:Identifier><TMPL_VAR identifier></ows:Identifier>
+            <ows:Title><TMPL_VAR title></ows:Title>
+            <TMPL_IF abstract>
+            <ows:Abstract><TMPL_VAR abstract></ows:Abstract>
+            </TMPL_IF>
+        </wps:Output>
+    </TMPL_LOOP>
+    </wps:OutputDefinitions>
+    </TMPL_IF>
+    <TMPL_IF processsucceeded>
+    <wps:ProcessOutputs>
+        <TMPL_LOOP Outputs>
+        <wps:Output>
+            <ows:Identifier><TMPL_VAR identifier></ows:Identifier>
+            <ows:Title><TMPL_VAR title></ows:Title>
+            <TMPL_IF abstract>
+            <ows:Abstract><TMPL_VAR abstract></ows:Abstract>
+            </TMPL_IF>
+            <TMPL_IF reference>
+            <wps:Reference xlink:href="<TMPL_VAR reference>" mimeType="<TMPL_VAR mimetype>" encoding="<TMPL_VAR encoding>" schema="TMPL_VAR schema>"/>
+            <TMPL_ELSE>
+                <TMPL_INCLUDE NAME="Execute_Data_Outputs.tmpl">
+            </TMPL_IF>
+        </wps:Output>
+        </TMPL_LOOP>
+    </wps:ProcessOutputs>
+    </TMPL_IF>
+</wps:ExecuteResponse>

Deleted: trunk/pywps/Templates/inc/Execute_Data.tmpl
===================================================================
--- trunk/pywps/Templates/inc/Execute_Data.tmpl	2008-04-17 13:05:01 UTC (rev 475)
+++ trunk/pywps/Templates/inc/Execute_Data.tmpl	2008-04-23 14:03:56 UTC (rev 476)
@@ -1,16 +0,0 @@
-            <wps:Data>
-                <TMPL_IF complexdata>
-                <wps:ComplexData mimeType="<TMPL_VAR mimetype>" schema="<TMPL_VAR schema>" encoding="<TMPL_VAR encoding>">
-                    <TMPL_VAR complexdata> 
-                </wps:ComplexData>
-                </TMPL_IF>
-                <TMPL_IF literaldata>
-                    <wps:LiteralData dataType="<TMPL_VAR type>" uom="<TMPL_VAR uom>"><TMPL_VAR literaldata></wps:LiteralData>
-                </TMPL_IF>
-                <TMPL_IF bboxdata>
-                    <wps:BoundingBoxData crs="<TMPL_VAR crs>" dimensions="<TMPL_VAR dimensions>">
-                        <ows:LowerCorner><TMPL_VAR minx> <TMPL_VAR miny></ows:LowerCorner>
-                        <ows:UpperCorner><TMPL_VAR maxx> <TMPL_VAR maxy></ows:LowerCorner>
-                    </wps:BoundingBoxData>
-                </TMPL_IF>
-            </wps:Data>

Copied: trunk/pywps/Templates/inc/Execute_Data_Inputs.tmpl (from rev 462, trunk/pywps/Templates/inc/Execute_Data.tmpl)

Modified: trunk/pywps/WPS/DescribeProcess.py
===================================================================
--- trunk/pywps/WPS/DescribeProcess.py	2008-04-17 13:05:01 UTC (rev 475)
+++ trunk/pywps/WPS/DescribeProcess.py	2008-04-23 14:03:56 UTC (rev 476)
@@ -25,7 +25,6 @@
 
 from Request import Request
 import os
-import types
 
 class DescribeProcess(Request):
     """
@@ -158,31 +157,15 @@
     def literalValue(self,inoutput,processInOutput):
 
         # data types
-        if inoutput.dataType == types.StringType:
-            processInOutput["dataTypeReference"] = \
-                                    "http://www.w3.org/TR/xmlschema-2/#string"
-            processInOutput["dataType"] = "string"
-        elif inoutput.dataType == types.FloatType:
-            processInOutput["dataTypeReference"] = \
-                                    "http://www.w3.org/TR/xmlschema-2/#float"
-            processInOutput["dataType"] = "float"
-        elif inoutput.dataType == types.IntType:
-            processInOutput["dataTypeReference"] =\
-                                    "http://www.w3.org/TR/xmlschema-2/#integer"
-            processInOutput["dataType"] = "integer"
-        elif inoutput.dataType == types.BooleanType:
-            processInOutput["dataTypeReference"] = \
-                                    "http://www.w3.org/TR/xmlschema-2/#boolean"
-            processInOutput["dataType"] = "boolean"
-        else:
-            # FIXME
-            pass
+        dataTypeReference = self.getDataTypeReference(input)
+        processInOutput["dataType"] = dataTypeReference["type"]
+        processInOutput["dataTypeReference"] = dataTypeReference["reference"]
         
         # UOMs
-        if len(inoutput.uoms) > 0:
+        if inoutput.uom:
             processInOutput["UOM"] = 1
-            processInOutput["defaultUOM"] = inoutput.uoms[0]
-        if len(inoutput.uoms) > 1:
+            processInOutput["defaultUOM"] = inoutput.uom
+        if len(inoutput.uoms) > 0:
             supportedUOMS = []
             for uom in inoutput.uoms:
                 supportedUOMS.append({"uom":uom})
@@ -216,14 +199,14 @@
 
     def complexValue(self,inoutput,processInOutput):
 
-        processInOutput["mimetype"] = inoutput.formats[0]["mimetype"]
+        processInOutput["mimetype"] = inoutput.formats[0]["mimeType"]
         processInOutput["encoding"] = inoutput.formats[0]["encoding"]
         processInOutput["schema"] = inoutput.formats[0]["schema"]
 
         processInOutput["Formats"] = []
         for format in inoutput.formats:
             processInOutput["Formats"].append({
-                                        "mimetype":format["mimetype"],
+                                        "mimetype":format["mimeType"],
                                         "encoding":format["encoding"],
                                         "schema":format["schema"]
                                             })

Modified: trunk/pywps/WPS/Execute.py
===================================================================
--- trunk/pywps/WPS/Execute.py	2008-04-17 13:05:01 UTC (rev 475)
+++ trunk/pywps/WPS/Execute.py	2008-04-23 14:03:56 UTC (rev 476)
@@ -24,64 +24,98 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
 from Request import Request
-import time,os,tempfile,re
-from pywps import Grass
+import time,os,sys,tempfile,re
+from shutil import copy as COPY
+from shutil import rmtree as RMTREE
 
 class Execute(Request):
     """
+    This class performes the Execute request of WPS specification
+
+    In the class, fork of the  processes has to be done, if the client
+    requested asynchronous request performance (status=true)
     """
+
+    statusPrinted = 0
+
+    # status variants
     accepted = "processaccepted"
     started = "processstarted"
-    succeeded = "processsucc"
+    succeeded = "processsucceeded"
     paused = "processpaused"
     failed = "processfailed"
 
+    # runnig process id
+    pid = None
+
+    # session ID
     id = ''
+
+    # status location and file
     statusLocation = ''
-    statusFile = None
+    statusFileName = None
+    statusFiles = [sys.stdout]
     
-    status = 0
-    processstatus = 0
+    # process status
+    statusRequired = False # should the request run assynchronously?
+    status = None
+    statusMessage = None
     percent = 0
-    exceptioncode = 0
+    exceptioncode = None
     locator = 0
     percent = 0
+    statusTime = None
 
-    dirsToBeRemoved = []     # directories, which should be removed
+    # directories, which should be removed
+    dirsToBeRemoved = []     
 
+    # working directory and grass
     workingDir = ""
     grass = None
 
+    parentProcess = False # Fork
+    printStatus = False
+
+    rawDataOutput = None
+
     def __init__(self,wps):
         """
-        Arguments:
-           self
-           wps   - parent WPS instance
+        wps   - parent WPS instance
         """
 
         Request.__init__(self,wps)
 
         self.wps = wps
         self.process = None
-
         self.template = self.templateManager.prepare(self.templateFile)
 
-        #
         # initialization
-        #
         self.statusTime = time.time()
+        self.pid = os.getpid()
         self.status = None
         self.id = self.makeSessionId()
-        self.statusLocation = os.path.join(self.wps.getConfigValue("server","outputPath"),self.id+".xml")
+        self.statusFileName = os.path.join(self.wps.getConfigValue("server","outputPath"),self.id+".xml")
+        self.statusLocation = self.wps.getConfigValue("server","outputUrl")+"/"+self.id+".xml"
 
-        #
+        # rawDataOutput
+        if self.wps.inputs["responseform"]["rawdataoutput"]:
+            self.rawDataOutput = self.wps.inputs["responseform"]["rawdataoutput"].keys()[0]
+
+        # is status required
+        self.statusRequired = False
+        if  self.wps.inputs["responseform"]["responsedocument"].has_key("status"):
+            if self.wps.inputs["responseform"]["responsedocument"]["status"]:
+                self.statusRequired = True
+                
+        # is store response required ?
+        if  self.wps.inputs["responseform"]["responsedocument"].has_key("storeexecuteresponse"):
+            if self.wps.inputs["responseform"]["responsedocument"]["storeexecuteresponse"]:
+                self.statusFiles.append(open(self.statusFileName,"w"))
+
         # setInput values
-        #
         self.initProcess()
 
-        #
         # HEAD
-        #
         self.templateProcessor.set("encoding",
                                     self.wps.getConfigValue("wps","encoding"))
         self.templateProcessor.set("lang",
@@ -92,47 +126,70 @@
                                     self.statusLocation)
         self.templateProcessor.set("serviceinstance",
                                     self.serviceInstanceUrl())
-        #
         # Description
-        #
         self.processDescription()
 
+        # Status == True ?
+        if self.statusRequired:
+            # Status
+            self.promoteStatus(self.accepted,"Process %s accepted" %\
+                    self.process.identifier)
+            
+            self.printStatus = True
 
-        #
-        # Status
-        #
-        self.setStatus(self.accepted,"Process %s accepted" %\
-                self.process.identifier)
+            # fork
+            self.splitThreads()
 
-        #
-        # lineage
-        #
-        if self.wps.inputs['responseform'].has_key("responsedocument"):
-            if self.wps.inputs['responseform']['responsedocument'].has_key('lineage') and \
-                self.wps.inputs['responseform']['responsedocument']['lineage'] == True:
-                self.lineageInputs()
+        if not self.parentProcess:
 
+            # init environment variable
+            self.initEnv()
 
-        # 
-        # Execute
-        #
-        if  self.wps.inputs["responseform"]["responsedocument"].has_key("status"):
-            if self.wps.inputs["responseform"]["responsedocument"]["status"]:
-                pass
-                #self.splitThreads()
-        self.executeProcess()
+            # donwload and consolidate data
+            self.consolidateInputs()
 
-        #
-        # Status
-        #
-        self.setStatus(self.succeeded, 
-                processstatus="PyWPS Process %s successfully calculated" %\
-                self.process.identifier)
+            self.promoteStatus(self.started,"Process %s started" %\
+                    self.process.identifier)
 
-        self.response = self.templateProcessor.process(self.template)
+            # Execute
+            self.executeProcess()
+
+            # Status
+            self.promoteStatus(self.succeeded, 
+                    statusMessage="PyWPS Process %s successfully calculated" %\
+                    self.process.identifier)
+
+            # lineage in and outputs
+            if self.wps.inputs['responseform'].has_key("responsedocument"):
+                if self.wps.inputs['responseform']['responsedocument'].has_key('lineage') and \
+                    self.wps.inputs['responseform']['responsedocument']['lineage'] == True:
+                    self.templateProcessor.set("lineage",1)
+                    self.lineageInputs()
+                    self.outputDefinitions()
+
+            # fill outputs
+            self.processOutputs()
+
+            # Response document
+            self.response = self.templateProcessor.process(self.template)
+
+            if self.rawDataOutput:
+                self.response = None
+                self.printRawData()
+
+            # everything worked, remove all temporary files
+            self.cleanEnv()
+
+            if (self.statusRequired):
+                self.printResponse(self.statusFiles)
         return
 
     def initProcess(self):
+        """
+        Setting and controling input values, set by the client. Also the
+        processes from PYWPS_PROCESS directory or default directory is
+        imported.
+        """
 
         # import the right package
         if self.wps.inputs["identifier"] in self.processes.__all__:
@@ -150,14 +207,27 @@
             raise self.wps.exceptions.InvalidParameterValue(
                     self.wps.inputs["identifier"])
 
-        # create temporary directory
-        self.initEnv()
 
+        # set propper method for status change
+        self.process.wps = self.wps
+        self.process.status.onStatusChanged = self.onStatusChanged
+        self.process.debug = self.wps.getConfigValue("server","debug")
+
+    def consolidateInputs(self):
+        """
+        Donwloads and controls input data, defined by the client
+        """
         # calculate maximum allowed input size
         maxFileSize = self.calculateMaxInputSize()
 
         # set input values
         for identifier in self.process.inputs:
+
+            # Status
+            self.promoteStatus(self.paused, 
+                    statusMessage="Getting input %s of process %s" %\
+                    (identifier, self.process.identifier))
+
             input = self.process.inputs[identifier]
 
             # exceptions handler
@@ -181,14 +251,16 @@
             if not input.value:
                 raise self.wps.exceptions.MissingParameterValue(identifier)
 
-        # set propper method for status change
-        self.process.wps = self.wps
-        self.process.status.onStatusChanged = self.onStatusChanged
-        self.process.debug = self.wps.getConfigValue("server","debug")
+    def onInputProblem(self,what,why):
+        """
+        This method is used for rewriting onProblem method of each input
 
-    def onInputProblem(self,what,why):
+        what - locator of the problem
+        why - possible reason of the problem
+        """
         
         exception = None
+
         if what == "FileSizeExceeded":
             exception = self.wps.exceptions.FileSizeExceeded
         elif what == "NoApplicableCode":
@@ -196,8 +268,11 @@
 
         raise exception(why)
 
-
     def executeProcess(self):
+        """
+        Calls 'execute' method of the process, catches possible exeptions
+        and raise error, if needed
+        """
         try:
             processError = self.process.execute()
             if processError:
@@ -212,6 +287,10 @@
                                 (self.process.identifier,e))
 
     def processDescription(self):
+        """
+        Fills Identifier, Title and Abstract, eventually WSDL and Profile
+        parts of the output XML document
+        """
 
         self.templateProcessor.set("title", self.process.title)
         self.templateProcessor.set("abstract", self.process.abstract)
@@ -220,52 +299,75 @@
         #self.templateProcessor.set("profile", self.process.profile)
         #self.templateProcessor.set("wsdl", self.process.wsdl)
 
-    def setStatus(self,status,
-                    processstatus=0, percent=0,
-                    exceptioncode=0, locator=0):
+    def promoteStatus(self,status,
+                    statusMessage=0, percent=0,
+                    exceptioncode=0, locator=0,
+                    output=None):
+        """
+        Sets status of currently performed Execute request
+
+        {String} status -  name of the status
+        {String} statusMessage - message, which should appear in output xml file
+        {Float} percent - percent done message
+        {String} exceptioncode - eventualy exception
+        {String} locator - where the problem occured
+        """
+
+        self.process.status.percentCompleted, self.process.status.value,\
+        self.printStatus
         
         self.statusTime = time.time()
         self.templateProcessor.set("statustime", time.ctime(self.statusTime))
         self.status = status
-        if processstatus != 0: self.processstatus = processstatus 
+        if statusMessage != 0: self.statusMessage = statusMessage 
         if percent != 0: self.percent = percent 
         if exceptioncode != 0: self.exceptioncode = exceptioncode 
         if locator != 0: self.locator = locator 
         
-
         # init value
         self.templateProcessor.set("processstarted",0)
-        self.templateProcessor.set("processsucc",0)
+        self.templateProcessor.set("processsucceeded",0)
         self.templateProcessor.set("processpaused",0)
         self.templateProcessor.set("processfailed",0)
         self.templateProcessor.set("processaccepted",0)
 
-
         if self.status == self.accepted:
             self.templateProcessor.set("processaccepted",
-                    self.processstatus)
+                    self.statusMessage)
 
         elif self.status == self.started:
-            self.templateProcessor.set("processstarted", "true")
-            self.templateProcessor.set("percentcompleted", self.percent*100)
+            self.templateProcessor.set("processstarted", self.statusMessage)
+            self.templateProcessor.set("percentcompleted", self.percent)
 
         elif self.status == self.succeeded:
-            self.process.status.set(percentDone=100)
+            self.process.status.set(msg=self.statusMessage, percentDone=100, propagate=False)
             self.templateProcessor.set("percentcompleted", self.percent)
-            self.templateProcessor.set("processsucc",
-                                                self.processstatus)
+            self.templateProcessor.set("processsucceeded",
+                                                self.statusMessage)
 
         elif self.status == self.paused:
-            self.templateProcessor.set("processpaused", self.processstatus)
+            self.templateProcessor.set("processpaused", self.statusMessage)
             self.templateProcessor.set("percentcompleted", self.percent)
 
         elif self.status == self.failed:
-            self.templateProcessor.set("exceptiontext", self.processstatus)
+            self.templateProcessor.set("exceptiontext", self.statusMessage)
             self.templateProcessor.set("exceptioncode", self.exceptioncode)
 
+        # update response
+        self.response = self.templateProcessor.process(self.template)
+
+        # printStatus
+        if self.printStatus and not self.rawDataOutput:
+            self.statusPrinted += 1
+            self.printResponse(self.statusFiles)
+
+
     def lineageInputs(self):
+        """
+        Called, if lineage request was set. Fills the <DataInputs> part of
+        output XML document.
+        """
         templateInputs = []
-        self.templateProcessor.set("lineage",1)
     
         for identifier in self.process.inputs.keys():
             templateInput = {}
@@ -278,27 +380,36 @@
             templateInputs.append(templateInput);
 
             if input.type == "LiteralValue":
-                templateInput = self.lineageLiteralInput(input,templateInput)
+                templateInput = self._lineageLiteralInput(input,templateInput)
             elif input.type == "ComplexValue":
-                templateInput = self.lineageComplexInput(input,templateInput)
+                templateInput = self._lineageComplexInput(input,templateInput)
             elif input.type == "BoundingBoxValue":
-                templateInput = self.lineageBboxInput(input,templateInput)
+                templateInput = self._lineageBBoxInput(input,templateInput)
 
         self.templateProcessor.set("Inputs",templateInputs)
 
-    def lineageLiteralInput(self, input, literalInput):
+    def _lineageLiteralInput(self, input, literalInput):
+        """
+        Fill input of literal data
+        """
         literalInput["literaldata"] = input.value
         literalInput["uom"] = str(input.uom)
         return literalInput
 
-    def lineageComplexInput(self, input, complexInput):
+    def _lineageComplexInput(self, input, complexInput):
+        """
+        Fill input of complex data
+        """
         complexInput["complexdata"] = input.value
         complexInput["encoding"] = input.format["encoding"]
-        complexInput["mimetype"] = input.format["mimetype"]
+        complexInput["mimetype"] = input.format["mimeType"]
         complexInput["schema"] = input.format["schema"]
         return complexInput
 
-    def lineageBboxInput(self,input,bboxInput):
+    def _lineageBBoxInput(self,input,bboxInput):
+        """
+        Fill input of bbox data
+        """
         bboxInput["bboxdata"] = 1
         bboxInput["crs"] = input.crs
         bboxInput["dimensions"] = input.dimensions
@@ -306,57 +417,196 @@
         bboxInput["miny"] = input.value[1]
         bboxInput["maxx"] = input.value[2]
         bboxInput["maxy"] = input.value[3]
-
         return bboxInput
 
+    def outputDefinitions(self):
+        """
+        Called, if lineage request was set. Fills the <OutputDefinitions> part of
+        output XML document.
+        """
+        templateOutputs = []
     
+        for identifier in self.process.outputs.keys():
+            templateOutput = {}
+            output = self.process.outputs[identifier]
+
+
+            templateOutput["identifier"] = output.identifier
+            templateOutput["title"] = output.title
+            templateOutput["abstract"] = output.abstract
+        
+            if self.process.storeSupported and output.asReference:
+                templateOutput["asreference"] = "true"
+            else:
+                templateOutput["asreference"] = "false"
+
+            templateOutputs.append(templateOutput);
+
+            if output.type == "LiteralValue":
+                templateOutput = self._lineageLiteralOutput(output,templateOutput)
+                templateOutput["literaldata"] = 1
+            elif output.type == "ComplexValue":
+                templateOutput = self._lineageComplexOutput(output,templateOutput)
+                templateOutput["complexdata"] = 1
+            else:
+                # FIXME TO BE FIXED
+                templateOutput["bboxdata"] = 1
+
+        self.templateProcessor.set("Outputdefinitions",templateOutputs)
+
+    def _lineageLiteralOutput(self, output, literalOutput):
+        if len(output.uoms):
+                literalOutput["uom"] = str(output.uoms[0])
+        return literalOutput
+
+    def _lineageComplexOutput(self, output, complexOutput):
+
+        complexOutput["mimetype"] = output.format["mimeType"]
+        complexOutput["encoding"] = output.format["encoding"]
+        complexOutput["shema"] = output.format["schema"]
+
+
+        return complexOutput
+
+    def processOutputs(self):
+        """
+        Fill <ProcessOutputs> part in the ouput XML document
+        This method is called if, self.status == ProcessSucceeded
+        """
+
+        templateOutputs = []
+    
+        for identifier in self.process.outputs.keys():
+            templateOutput = {}
+            output = self.process.outputs[identifier]
+
+            templateOutput["identifier"] = output.identifier
+            templateOutput["title"] = output.title
+            templateOutput["abstract"] = output.abstract
+
+            # Reference
+            if output.asReference:
+                self._asReferenceOutput(templateOutput, output)
+            # Data
+            else:
+                templateOutput["reference"] = 0
+                if output.type == "LiteralValue":
+                    templateOutput = self._literalOutput(output,templateOutput)
+                elif output.type == "ComplexValue":
+                    templateOutput = self._complexOutput(output,templateOutput)
+                elif output.type == "BoundingBoxValue":
+                    templateOutput = self._bboxOutput(output,templateOutput)
+
+                templateOutputs.append(templateOutput);
+        self.templateProcessor.set("Outputs",templateOutputs)
+
+    def _literalOutput(self, output, literalOutput):
+
+        literalOutput["uom"] = str(output.uom)
+        literalOutput["dataType"]= self.getDataTypeReference(output)["type"]
+        literalOutput["literaldata"] = output.value
+
+        return literalOutput
+
+    def _complexOutput(self, output, complexOutput):
+
+        complexOutput["mimeType"] = output.format["mimeType"]
+        complexOutput["encoding"] = output.format["encoding"]
+        complexOutput["schema"] = output.format["schema"]
+
+        # CDATA section in output
+        if output.format["mimeType"].find("text") < 0:
+            complexOutput["cdata"] = 1
+        # set output value
+        complexOutput["complexdata"] = open(output.value,"r").read()
+
+        # remove <?xml version= ... part from beginning of some xml
+        # documents
+        if output.format["mimeType"].find("xml") or\
+           output.format["mimeType"].find("gml") > -1:
+            beginXml = complexOutput["complexdata"].split("\n")[0]
+            if  beginXml.find("<?xml ") > -1:
+                complexOutput["complexdata"] = complexOutput["complexdata"].replace(beginXml+"\n","")
+
+        return complexOutput
+
+    def _bboxOutput(self, output, bboxOutput):
+        # FIXME TO BE FIXED
+        return bboxOutput
+
+    def _asReferenceOutput(self,templateOutput, output):
+
+        # copy the file to output directory
+        if output.type == "LiteralValue":
+            f = open(os.path.join(
+                        self.wps.getConfigValue("server","outputPath"),
+                                output.identifier+"-"+self.pid),"w")
+            f.write(output.value)
+            f.close()
+            templateOutput["href"] = self.wps.getConfigValue("server","outputUrl")+\
+                    "/"+output.identifier+"-"+self.pid
+        else:
+            COPY(output.value, self.wps.getConfigValue("server","outputPath"))
+            templateOutput["href"] = \
+                    self.wps.getConfigValue("server","outputUrl")+"/"+output.value
+        templateOutput["reference"] = 1
+        templateOutput["mimetype"] = output.format["mimeType"]
+        templateOutput["schema"] = output.format["encoding"]
+        templateOutput["encoding"] = output.format["schema"]
+
     def splitThreads(self):
+        """
+        Will 'try' to for currently running process. Parent process will
+        formulate resulting XML response with ProcessAccepted status, child
+        process will turn all sys.stdout and sys.stdin off, so the Web
+        Server can break the connection to the client.
+        """
         try:
-            self.statusLocation = self.settings.ServerSettings['outputUrl']+"/"+self.executeresponseXmlName
-            self.pid = os.fork() 
-            if self.pid:
-                self.make_response_xml()
-                file = open(
-                        os.path.join(self.settings.ServerSettings['outputPath'],self.executeresponseXmlName),"w")
-                file.write(self.document.toprettyxml())
-                file.close()
+            # this is the parent process
+            if os.fork():
+                self.parentProcess = True
                 return
+            # this is the child process
             else:
+                self.pid = os.getpid()
+
+                # should the status be printed on each change?
+                self.irintStatus = True
+
+                self.parentProcess = False
+                self.statusFiles.remove(sys.stdout)
+                if len(self.statusFiles) == 0:
+                    self.statusFiles = [open(self.statusFileName,"w")]
+
+                self.promoteStatus(self.started,"Process %s started" %\
+                    self.process.identifier)
+
+                return
+                # time.sleep(2)
                 # Reassign stdin, stdout, stderr for child
                 # so Apache will ignore it
-                # time.sleep(2)
-                self.status = "ProcessStarted"
-                si = open('/dev/null', 'r')
-                so = open('/dev/null', 'a+')
-                se = open('/dev/null', 'a+', 0)
+                si = open(os.devnull, 'r')
+                so = open(os.devnull, 'a+')
+                se = open(os.devnull, 'a+', 0)
                 os.dup2(si.fileno(), sys.stdin.fileno())
                 os.dup2(so.fileno(), sys.stdout.fileno())
                 os.dup2(se.fileno(), sys.stderr.fileno())
-
-                # make document
-                self.make_response_xml()
-
-                # begin checking
-                self.process.stopChecking = False
-
-                # define thread
-                status = Status(self,document=self.document, 
-                            filename=os.path.join(
-                                self.settings.ServerSettings['outputPath'],
-                                self.executeresponseXmlName),
-                            interval=1,
-                            process=self.process)
-                # take care on self.process.status
-                status.start()
-
         except OSError, e: 
-            sys.stderr.write( "fork #1 failed: %d (%s)\n" % (e.errno, e.strerror) )
-            sys.exit(1)
+            raise self.wps.exceptions.NoApplicableCode("Fork failed: %d (%s)\n" % (e.errno, e.strerror) )
+        return
 
     def makeSessionId(self):
+        """
+        Returns unique Execute session ID
+        """
         return "pywps-"+str(int(time.time()*100))
 
     def getSessionIdFromStatusLocation(self,statusLocation):
+        """
+        Parses the statusLocation, and gets the unique session ID from it
+
+        NOTE: Not in use, maybe should be removed.
+        """
         begin = statusLocation.find("/pywps-")
         end = statusLocation.find(".xml")
         if begin > -1 and end > -1:
@@ -365,6 +615,9 @@
             return None
 
     def serviceInstanceUrl(self):
+        """
+        Creates URL of GetCapabilities for this WPS
+        """
         serveraddress = self.wps.getConfigValue("wps","serveraddress")
 
         if not serveraddress.endswith("?") and \
@@ -380,8 +633,11 @@
         """
         This method is used for redefinition of self.process.status class
         """
-        self.percent = self.process.status.processCompleted
 
+        self.promoteStatus(self.process.status.code,statusMessage =
+                self.process.status.value,
+                percent=self.process.status.percentCompleted)
+
     def initEnv(self):
 
         self.workingDir = tempfile.mkdtemp(prefix="pywps",
@@ -394,6 +650,7 @@
         self.dirsToBeRemoved.append(self.workingDir)
 
         if self.process.grassLocation:
+            from pywps import Grass
             grass = Grass.Grass(self)
             if self.process.grassLocation == True:
                 grass.mkMapset()
@@ -403,13 +660,17 @@
                 raise self.wps.exceptions.NoApplicableCode("Location [%s] does not exist" % self.process.location)
         
     def cleanEnv(self):
-       
-        from shutil import rmtree
-        for dir in self.dirsToBeRemoved:
+        """
+        Removes temporary created files and dictionaries
+        """
+        for i in range(len(self.dirsToBeRemoved)):
+            dir = self.dirsToBeRemoved[0]
             if os.path.isdir(dir) and dir != "/":
-                #rmtree(dir)
+                RMTREE(dir)
                 pass
+            self.dirsToBeRemoved.remove(dir)
 
+
     def calculateMaxInputSize(self):
         maxSize = self.wps.getConfigValue("server","maxfilesize")
         maxSize = maxSize.lower()
@@ -427,3 +688,19 @@
             size *= 1
 
         return size
+    
+    def printRawData(self):
+        """
+        Prints raw data to sys.stdout with correct content-type, according
+        to mimeType attribute or output value
+        """
+
+        output = self.process.outputs[self.rawDataOutput]
+        if output.type == "LiteralValue":
+            print "Content-type: text/plain\n"
+            print output.value
+        elif output.type == "ComplexValue":
+            f = open(output.value,"r")
+            print "Content-type: %s\n" % output.format["mimeType"]
+            print f.read()
+            f.close()

Modified: trunk/pywps/WPS/Request.py
===================================================================
--- trunk/pywps/WPS/Request.py	2008-04-17 13:05:01 UTC (rev 475)
+++ trunk/pywps/WPS/Request.py	2008-04-23 14:03:56 UTC (rev 476)
@@ -27,16 +27,21 @@
 # make sure, that the package python-htmltmpl is installed on your system!
 from htmltmpl import TemplateManager, TemplateProcessor
 import os
+from sys import stdout as STDOUT
+import types
 from pywps import Templates
+import re
 
 class Request:
     response = None # Output document
     wps = None # Parent WPS object
     templateManager = None # HTML TemplateManager
-    templateProcessor = TemplateProcessor() # HTML TemplateProcessor
+    templateProcessor = TemplateProcessor(html_escape=0) # HTML TemplateProcessor
     template = None # HTML Template
     templateFile = None # File with template
     processDir = None # Directory with processes
+    statusFiles = STDOUT 
+    emptyParamRegex = re.compile('( \w+="")|( \w+="None")')
 
     def __init__(self,wps):
         self.wps = wps
@@ -69,6 +74,54 @@
             processes = __import__(os.path.split(self.processDir)[-1])
             self.processes = processes
         else:
-            import pywps
+            import pywps 
             from pywps import processes
             self.processes = pywps.processes
+
+    def getDataTypeReference(self,inoutput):
+        """
+        Returns data type reference according to W3C 
+        """
+        
+        dataType = {"type": None, "reference": None}
+        if inoutput.dataType == types.StringType:
+            processInOutput["dataTypeReference"] = \
+            dataType["type"] = "string"
+            dataType["reference"] = "http://www.w3.org/TR/xmlschema-2/#string"
+        elif inoutput.dataType == types.FloatType:
+            dataType["type"] = "float"
+            dataType["reference"] = "http://www.w3.org/TR/xmlschema-2/#float"
+        elif inoutput.dataType == types.IntType:
+            dataType["type"] = "integer"
+            dataType["reference"] = "http://www.w3.org/TR/xmlschema-2/#integer"
+        elif inoutput.dataType == types.BooleanType:
+            dataType["type"] = "boolean"
+            dataType["reference"] = "http://www.w3.org/TR/xmlschema-2/#boolean"
+        else:
+            # FIXME To be continued...
+            dataType["type"] = "string"
+            dataType["reference"] = "http://www.w3.org/TR/xmlschema-2/#string"
+            pass
+
+        return dataType
+
+    def printResponse(self,fileDes):
+        """
+        print response to file descriptor file descriptor
+        can be of type list or file
+        """
+
+        if type(fileDes) != type([]):
+            fileDes = [fileDes]
+
+        for f in fileDes:
+
+            # open file
+            if f != STDOUT and f.closed:
+                f = open(f.name,"w")
+
+            # '""' and '"None"'s will be removed
+            f.write(re.sub(self.emptyParamRegex,"",self.response))
+
+            if (f != STDOUT):
+                f.close()

Modified: trunk/pywps/etc/pywps.cfg
===================================================================
--- trunk/pywps/etc/pywps.cfg	2008-04-17 13:05:01 UTC (rev 475)
+++ trunk/pywps/etc/pywps.cfg	2008-04-23 14:03:56 UTC (rev 476)
@@ -29,7 +29,7 @@
 maxinputparamlength=1024
 maxfilesize=5mb
 tempPath=/tmp
-outputUrl=http//localhost/wps/wpsoutputs
+outputUrl=http://localhost/wps/wpsoutputs
 outputPath=/var/www/wps/wpsoutputs
 debug=true
 

Modified: trunk/pywps/processes3/buffer.py
===================================================================
--- trunk/pywps/processes3/buffer.py	2008-04-17 13:05:01 UTC (rev 475)
+++ trunk/pywps/processes3/buffer.py	2008-04-23 14:03:56 UTC (rev 476)
@@ -18,16 +18,16 @@
             grassLocation = True)
 
 
-        self.addComplexInput(identifier="data",
+        self.dataIn = self.addComplexInput(identifier="data",
                              title = "Input data")
 
-        self.addLiteralInput(identifier = "width",
+        self.widthIn = self.addLiteralInput(identifier = "width",
                              title = "Width")
 
-        self.addComplexOutput(identifier="buffer",
-                                title="Output buffer file")
+        self.bufferOut = self.addComplexOutput(identifier="buffer",
+                                title="Output buffer file",asReference=True)
 
-        self.addLiteralOutput(identifier="text",
+        self.textOut = self.addLiteralOutput(identifier="text",
                                 title="just some text")
         
     def execute(self):
@@ -41,13 +41,14 @@
         self.status.set("Buffering",50)
 	self.cmd("v.buffer input=data output=data_buff buffer=%s scale=1.0 tolerance=0.01" %\
                 (self.getInputValue('width')))
-            	
+
         self.status.set("Exporting data",90)
+
 	self.cmd("v.out.ogr type=area format=GML input=data_buff dsn=out.xml  olayer=path.xml")
-
         
         if "out.xml" in os.listdir(os.curdir):
-            self.setOutputValue('buffer', "out.xml")
+            self.bufferOut.setValue("out.xml")
+            self.textOut.setValue("ahoj, svete")
             return
         else:
             return "Output file not created"

Modified: trunk/wps3.py
===================================================================
--- trunk/wps3.py	2008-04-17 13:05:01 UTC (rev 475)
+++ trunk/wps3.py	2008-04-23 14:03:56 UTC (rev 476)
@@ -43,6 +43,11 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
+
+# TODO:
+# document evertyghin according to
+# http://www.python.org/doc/essays/styleguide.html
+
 import pywps
 from pywps import Parser 
 from pywps import Exceptions
@@ -110,8 +115,11 @@
             self.performRequest()
 
         if self.request.response:
-            print "Content-type: text/xml\n"
-            print self.request.response
+            # print only to standard out
+            if self.request.statusFiles == sys.stdout or\
+               sys.stdout in self.request.statusFiles:
+                print "Content-type: text/xml\n"
+                self.request.printResponse(self.request.statusFiles)
 
         return
     



More information about the Pywps-commits mailing list