1#!/usr/bin/env python2 2 3# If the Webware installation is located somewhere else, 4# then set the webwareDir variable to point to it here: 5webwareDir = None 6 7# If you used the MakeAppWorkDir.py script to make a separate 8# application working directory, specify it here: 9workDir = None 10 11try: 12 import os, sys 13 if not webwareDir: 14 webwareDir = os.path.dirname(os.path.dirname(os.getcwd())) 15 sys.path.insert(1, webwareDir) 16 webKitDir = os.path.join(webwareDir, 'WebKit') 17 if workDir is None: 18 workDir = webKitDir 19 else: 20 sys.path.insert(1, workDir) 21 try: 22 import WebKit.Adapters.CGIAdapter 23 except ImportError: 24 if os.path.exists(webwareDir) and os.path.exists(webKitDir): 25 cgiAdapter = os.path.join(webKitDir, 'Adapters', 'CGIAdapter.py') 26 if os.path.exists(cgiAdapter): 27 raise 28 msg = "CGIAdapter module at <code>%s</code> cannot be loaded" % cgiAdapter 29 else: 30 msg = "Webware installation not found at <code>%s</code>" % webwareDir 31 sys.stdout.write('''Content-Type: text/html\n 32<html><head><title>WebKit CGI Error</title><body> 33<h3>WebKit CGI Error</h3> 34<p>%s.</p> 35<p>You may need to edit the WebKit.cgi script so that <code>webwareDir</code> 36points to the actual Webware installation directory.</p> 37<p>You may also need to modify permissions of the Webware installation 38with <code>chmod</code> so that the CGIAdapter module can be imported.</p> 39</body></html>\n''' % msg) 40 else: 41 WebKit.Adapters.CGIAdapter.main(workDir) 42except: 43 import sys, traceback 44 from time import asctime, localtime, time 45 sys.stderr.write('[%s] [error] WebKit: Error in adapter\n' % asctime(localtime(time()))) 46 sys.stderr.write('Error while executing script\n') 47 traceback.print_exc(file=sys.stderr) 48 output = ''.join(traceback.format_exception(*sys.exc_info())) 49 output = output.replace('&', '&').replace( 50 '<', '<').replace('>', '>').replace('"', '"') 51 sys.stdout.write('''Content-Type: text/html\n 52<html><head><title>WebKit CGI Error</title><body> 53<h3>WebKit CGI Error</h3> 54<pre>%s</pre> 55</body></html>\n''' % output) 56