#!/usr/bin/python import cgitb; cgitb.enable() # For traceback information import os import cgi import tempfile import logging import datetime now = datetime.datetime.now() import simplejson from cclib.parser import ccopen fields = cgi.FieldStorage() log = open("log.txt", "a") log.write("%s\n" % now.strftime("%H:%M:%S %d-%B-%Y")) log.close() if fields.has_key("logfile"): handle, filename = tempfile.mkstemp() tmpfile = open(filename, "w") print >> tmpfile, fields.getfirst("logfile") tmpfile.close() failed = False try: a = ccopen(filename) a.logger.setLevel(logging.ERROR) data = a.parse() except: failed = True os.close(handle) os.remove(filename) if not failed: print "Content-Type: application/json; charset=utf-8" print "Status: 200 Ok" print print data.writejson() else: print "Content-Type: application/json; charset=utf-8" print "Status: 500 Internal Server Error" print print simplejson.dumps({'error': 'cclib was not able to parse this logfile without errors. Please send an email to cclib-users@lists.sf.net.'}) else: print "Content-Type: application/json; charset=utf-8" print "Status: 400 Bad Request" print print simplejson.dumps({'error': 'You need to set the value of the logfile parameter to the contents of a logfile'})