#!/usr/bin/env python import cgi, posix, sys, os, traceback def gen_ilu_header(): sys.stdout.write("""
|
|
|
" #for key in os.environ.keys(): # print key, ":", cgi.escape(os.environ[key]) #print "" hexdigits = "ABCDEFabcdef0123456789" def validIOR(iorstring): if iorstring[0:4] == 'IOR:': digits = iorstring[4:] elif iorstring[0:5] == 'IOR2:': digits = iorstring[5:] else: return 0; if (len(digits)%2) != 0: return 0; for digit in digits: if (not digit in hexdigits): return 0; return 1 def figure_ior_contents(form): if not form.has_key("IOR"): sys.stdout.write("No IOR supplied. You must provide an IOR to parse.\n") elif not validIOR(form["IOR"].value): sys.stdout.write("""Your IOR is misformed. It must begin with either "IOR:" or "IOR2:", and then have an even number of hex digits.\n""") else: if form.has_key("verbose"): vflag = "-v" else: vflag = "" command = "./parseIOR " + vflag + " " + form["IOR"].value + " 2>&1" pipe = os.popen(command, 'r') lines = pipe.readlines() status = pipe.close() if vflag: lines = lines[10:] if status: sys.stdout.write("
\n")
else:
sys.stdout.write("Your IOR:
\n")
for line in lines:
sys.stdout.write(cgi.escape(line))
sys.stdout.write("")
def main():
form = cgi.FieldStorage()
sys.stdout.write("Content-Type: text/html\n\n")
gen_ilu_header()
figure_ior_contents(form)
gen_ilu_trailer()
try:
main()
except:
print "Content-Type: text/plain\n\n"
import StringIO
sio = StringIO.StringIO()
traceback.print_exc(None, sio)
tb = sio.getvalue()
print cgi.escape(tb), ""