1#!/usr/bin/env python
2
3import sys, os, traceback, string
4import neo_cgi
5
6def log (s):
7  sys.stderr.write("CGI: %s\n" % s)
8
9def exceptionString():
10  import StringIO
11
12  ## get the traceback message
13  sfp = StringIO.StringIO()
14  traceback.print_exc(file=sfp)
15  exception = sfp.getvalue()
16  sfp.close()
17
18  return exception
19
20def main (argv, environ):
21  # log ("starting")
22  cgi = neo_cgi.CGI("")
23
24  try:
25    hdf_file = cgi.hdf.getValue("CGI.PathTranslated", "")
26    if hdf_file == "":
27      cgi.error ("No PATH_TRANSLATED var")
28      return
29
30    x = string.rfind (hdf_file, '/')
31    if x != -1:
32      cgi.hdf.setValue ("hdf.loadpaths.0", hdf_file[:x])
33
34    cgi.hdf.readFile(hdf_file)
35    content = cgi.hdf.getValue("Content", "")
36    if content == "":
37      cgi.error ("No Content var specified in HDF file %s" % hdf_file)
38      return
39
40    cgi.display(content)
41
42  except neo_cgi.CGIFinished:
43    return
44  except Exception, Reason:
45    log ("Python Exception: %s" % (str(repr(Reason))))
46    s = neo_cgi.text2html("Python Exception: %s" % exceptionString())
47    cgi.error (s)
48
49if __name__ == "__main__":
50  main (sys.argv, os.environ)
51