#!/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() idToUpdate = int(form.getfirst("todoID")) note = form.getfirst("note") if (note == None): note = '' #idToUpdate = 2 #note = '' oldFile = open(fileName, 'r') oldFileLines = oldFile.readlines() oldFile.close() usedIDs = [] lineIndex = 0 todoIDre = re.compile(r'^)$', line, re.IGNORECASE) if (noNoteMatch): oldFileLines[lineIndex] = '%s note=%s%s\n' % (noNoteMatch.group(1), xml.sax.saxutils.quoteattr(note), noNoteMatch.group(2)) break lineIndex = lineIndex + 1 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."