[Pywps-commits] r748 - in trunk: doc/examples doc/examples/clients doc/examples/processes pywps/Process pywps/Wps
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Feb 2 10:19:20 CET 2009
Author: jachym
Date: 2009-02-02 10:19:20 +0100 (Mon, 02 Feb 2009)
New Revision: 748
Added:
trunk/doc/examples/clients/
trunk/doc/examples/clients/ultimatequestion-ajax.html
Modified:
trunk/doc/examples/processes/ultimatequestionprocess.py
trunk/pywps/Process/Process.py
trunk/pywps/Wps/Execute.py
Log:
added new example of the ajax client
Added: trunk/doc/examples/clients/ultimatequestion-ajax.html
===================================================================
--- trunk/doc/examples/clients/ultimatequestion-ajax.html 2009-01-29 17:17:39 UTC (rev 747)
+++ trunk/doc/examples/clients/ultimatequestion-ajax.html 2009-02-02 09:19:20 UTC (rev 748)
@@ -0,0 +1,140 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us" >
+ <head>
+ <title>Ultimate question</title>
+<script type="text/javascript" language="javascript">
+
+ var url = window.location.protocol+"//"+window.location.host+'/cgi-bin/wps-trunk?service=wps&version=1.0.0&request=describeprocess&identifier=ultimatequestionprocess';
+
+ function startRequest() {
+ makeRequest(url);
+ url = window.location.protocol+"//"+window.location.host+'/cgi-bin/wps-trunk?service=wps&version=1.0.0&request=execute&identifier=ultimatequestionprocess&status=true&storeexecuteresponse=true';
+ };
+
+ function makeRequest(url) {
+ document.getElementById("request").innerHTML = new Date().getTime().toLocaleString();
+
+ var httpRequest;
+
+ if (window.XMLHttpRequest) { // Mozilla, Safari, ...
+ httpRequest = new XMLHttpRequest();
+ if (httpRequest.overrideMimeType) {
+ httpRequest.overrideMimeType('text/xml');
+ // See note below about this line
+ }
+ }
+ else if (window.ActiveXObject) { // IE
+ try {
+ httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
+ }
+ catch (e) {
+ try {
+ httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
+ }
+ catch (e) {}
+ }
+ }
+
+ if (!httpRequest) {
+ alert('Giving up :( Cannot create an XMLHTTP instance');
+ return false;
+ }
+ httpRequest.onreadystatechange = function() { displayStatus(httpRequest); };
+ httpRequest.open('GET', url, true);
+ httpRequest.send('');
+
+ }
+
+ function displayStatus(httpRequest) {
+
+ if (httpRequest.readyState == 4) {
+ if (httpRequest.status == 200) {
+ var resp = httpRequest.responseXML;
+
+ var statusText = null;
+ var statusValue = null;
+ var percentDone = null;
+ var title = resp.getElementsByTagName("ows:Title")[0].firstChild.nodeValue;
+ var abstract = resp.getElementsByTagName("ows:Abstract")[0].firstChild.nodeValue;
+ var stat = resp.getElementsByTagName("wps:Status")[0];
+
+ var answerTitle = null;
+ var answer= null;
+
+ if (stat) {
+ var answer = null;
+ var url = null;
+
+ var accepted = stat.getElementsByTagName("wps:ProcessAccepted")[0];
+ if (accepted) {
+ statusValue = accepted.firstChild.nodeValue;
+ statusText = "ProcessAccepted";
+ percentDone = 0;
+ }
+
+ var started = stat.getElementsByTagName("wps:ProcessStarted")[0];
+ if (started) {
+ statusValue = started.firstChild.nodeValue;
+ statusText = "ProcessStarted";
+ percentDone = started.getAttribute("percentCompleted");
+ }
+
+ var succeeded = stat.getElementsByTagName("wps:ProcessSucceeded")[0];
+ if (succeeded) {
+ statusValue = succeeded.firstChild.nodeValue;
+ statusText = "ProcessStarted";
+ percentDone = 100;
+ answer = resp.getElementsByTagName("wps:LiteralData")[0].firstChild.nodeValue;
+ answerTitle = resp.getElementsByTagName("wps:Output")[0].getElementsByTagName("ows:Title")[0].firstChild.nodeValue;
+ }
+ url = resp.firstChild.getAttribute("statusLocation");
+ if (accepted || started) {
+ window.setTimeout("makeRequest('"+url+"')",2000);
+ }
+ }
+
+ document.getElementById("title").innerHTML = title;
+ document.getElementById("abstract").innerHTML = abstract;
+ document.getElementById("statusValue").innerHTML = statusValue;
+ document.getElementById("statusText").innerHTML = statusText;
+ document.getElementById("percentDone").innerHTML = percentDone;
+ document.getElementById("answerTitle").innerHTML = answerTitle;
+ document.getElementById("answerValue").innerHTML = answer;
+ document.getElementById("response").innerHTML = new Date().getTime().toLocaleString();
+
+ } else {
+ alert('There was a problem with the request.');
+ }
+ }
+
+ }
+</script>
+</head>
+<body onload="startRequest()">
+ <h1 id="title"></h1>
+ <div id="abstract">
+ </div>
+ <dl>
+ <dt>Status:</dt>
+ <dd id="statusText"></dd>
+
+ <dt>Value:</dt>
+ <dd id="statusValue"></dd>
+
+ <dt>Percent done:</dt>
+ <dd id="percentDone"></dd>
+
+ <dt>Answer Title:</dt>
+ <dd id="answerTitle"></dd>
+
+ <dt>Answer Value:</dt>
+ <dd id="answerValue"></dd>
+
+ <dt>Last request:</dt>
+ <dd id="request"></dd>
+
+ <dt>Last response:</dt>
+ <dd id="response"></dd>
+ </dl>
+ <input type="button" onclick="startRequest()" value="Start calculation" />
+</body>
Modified: trunk/doc/examples/processes/ultimatequestionprocess.py
===================================================================
--- trunk/doc/examples/processes/ultimatequestionprocess.py 2009-01-29 17:17:39 UTC (rev 747)
+++ trunk/doc/examples/processes/ultimatequestionprocess.py 2009-02-02 09:19:20 UTC (rev 748)
@@ -34,7 +34,7 @@
self.status.set("Preparing....", 0)
for i in xrange(1, 11):
time.sleep(10)
- self.status.set("Thinking.....", float(i*20))
+ self.status.set("Thinking.....", float(i*10))
#The final answer
self.Answer.setValue("42")
Modified: trunk/pywps/Process/Process.py
===================================================================
--- trunk/pywps/Process/Process.py 2009-01-29 17:17:39 UTC (rev 747)
+++ trunk/pywps/Process/Process.py 2009-02-02 09:19:20 UTC (rev 748)
@@ -106,10 +106,12 @@
lang = None
grassLocation = None
grassMapset = None
+ logFile = None
def __init__(self, identifier, title = None, abstract=None,
metadata=[],profile=[], version=None,
- statusSupported=True, storeSupported=False, grassLocation=None):
+ statusSupported=True, storeSupported=False, grassLocation=None,
+ logFile = sys.stderr):
"""Process initialization. All parameters can be set lately
Mandatory parameters:
@@ -428,8 +430,14 @@
if (type(cmd) == types.StringType):
cmd = cmd.strip().split()
- self.message("PyWPS Cmd: %s\n" % (cmd.__str__()))
+ idx = stdin.find("\n")
+ if 0 < idx <= 60:
+ stdinOut = stdin[:idx]
+ else:
+ stdinOut = stdin[:60]
+ self.message("PyWPS Cmd: %s %s\n" % (cmd.__str__(),stdinOut))
+
try:
subprocessstdin = None
if stdin:
@@ -468,8 +476,8 @@
printed. nothing happen otherwise.
"""
- if self.debug or force:
- sys.stderr.write(msg)
+ if self.debug or force and self.logFile:
+ self.logFile.write(msg)
return
def getInput(self,identifier):
Modified: trunk/pywps/Wps/Execute.py
===================================================================
--- trunk/pywps/Wps/Execute.py 2009-01-29 17:17:39 UTC (rev 747)
+++ trunk/pywps/Wps/Execute.py 2009-02-02 09:19:20 UTC (rev 748)
@@ -25,7 +25,7 @@
from Response import Response
from htmltmpl import TemplateError
-import time,os,sys,tempfile,re,types
+import time,os,sys,tempfile,re,types, ConfigParser
from shutil import copyfile as COPY
from shutil import rmtree as RMTREE
@@ -72,6 +72,7 @@
grass = None
rawDataOutput = None
+ logFile = None
def __init__(self,wps):
@@ -90,6 +91,7 @@
raise self.wps.exceptions.InvalidParameterValue("version")
# initialization
+ self.logFile = sys.stderr
self.statusTime = time.time()
self.pid = os.getpid()
self.status = None
@@ -203,12 +205,22 @@
# redirect stdout, so that apache sends back the response immediately
si = open('/dev/null', 'r')
so = open('/dev/null', 'a+')
- #se = open('/dev/null', 'a+', 0)
os.dup2(si.fileno(), sys.stdin.fileno())
os.dup2(so.fileno(), sys.stdout.fileno())
- #os.dup2(se.fileno(), sys.stderr.fileno())
+ # logfile
+ try:
+ self.logFile = self.wps.getConfigValue("server","logFile")
+ se = open(self.logFile, 'a+', 0)
+ os.dup2(se.fileno(), sys.stderr.fileno())
+ except ConfigParser.NoOptionError,e:
+ pass
+ except IOError,e:
+ raise self.wps.exceptions.NoApplicableCode("Logfile IOError: %s" % e.__str__())
+ except Exception, e:
+ raise self.wps.exceptions.NoApplicableCode("Logfile error: %s" % e.__str__())
+
# attempt to execute
try:
@@ -319,6 +331,7 @@
self.process.wps = self.wps
self.process.status.onStatusChanged = self.onStatusChanged
self.process.debug = self.wps.getConfigValue("server","debug")
+ self.process.logFile = self.logFile
def consolidateInputs(self):
""" Donwload and control input data, defined by the client """
@@ -531,6 +544,11 @@
#self.status == self.succeeded or
self.status == self.failed):
self.printResponse(self.statusFiles)
+
+ if self.status == self.started:
+ print >>sys.stderr, "PyWPS Status [%s][%.1f]: %s" % (self.status,float(self.percent),self.statusMessage)
+ else:
+ print >>sys.stderr, "PyWPS Status [%s]: %s" % (self.status,self.statusMessage)
def lineageInputs(self):
More information about the Pywps-commits
mailing list