#!/usr/bin/python
import cgi, os, os.path, time, re, xml.sax.saxutils
lockFileName = "files/todolock"
fileName = "files/todos.xml"
while(os.path.exists(lockFileName)):
time.sleep(.25)
lockFileHandle = open(lockFileName, "w")
lockFileHandle.write("locked")
lockFileHandle.close()
form = cgi.FieldStorage()
#name = form['title'].value
#nextAction = form['nextAction'].value
name = form.getfirst("title")
nextAction = form.getfirst("nextAction")
category = form.getfirst("category")
oldFile = open(fileName, 'r')
oldFileLines = oldFile.readlines()
oldFile.close()
usedIDs = []
categoryStartre = re.compile(r'^' % category)
categoryEndre = re.compile(r'^')
todoIDre = re.compile(r'^\n' % category)
oldFileLines.insert(len(oldFileLines)-1, todoLineToInsert)
oldFileLines.insert(len(oldFileLines)-1, '\n')
newFile = open(fileName, 'w')
for line in oldFileLines:
newFile.write(line)
newFile.close()
os.remove(lockFileName)
print "Content-type: text/plain\n\n"
print "done."