WebKit.cgi 2.2 KB

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