import functions;

#Getting the HTML form input data.
form = cgi.FieldStorage()

numeroGeral = form["pid"].value

#Opening the xml file and locking it to prevent access from other processes.
xmlData = open(functions.PATIENTS_FILE_NAME, 'r+');
fcntl.flock(xmlData, fcntl.LOCK_EX);

#Parsing the XML file
xmlData.seek(0); #Going to the beginning of the file
dom = xml.dom.minidom.parse(xmlData);

#Retrieving the correct user.
result = functions.getPatientInfo(dom, numeroGeral);

#Closing the xml file
xmlData.close()

print "Content-Type: text/html\n\n"     # HTML is following

if result == None:
# Numero geral valido
    print '0'

else:
# Numero geral jah existente
    print '1'
Example #2
0
fcntl.flock(xmlData, fcntl.LOCK_EX);

#Opening the file used for backup and locking it.
bckData = open(functions.PATIENTS_FILE_NAME + '~', 'w');
fcntl.flock(bckData, fcntl.LOCK_EX);

#Generating the backup.
shutil.copyfileobj(xmlData, bckData);
bckData.close(); #Realeasing the backup file (unlock).

#Parsing the XML file
xmlData.seek(0); #Going to the beginning of the file
dom = xml.dom.minidom.parse(xmlData);

#Retrieving the correct user.
patient = functions.getPatientInfo(dom, form['pid'].value);

#Checking whether the form already exists. If so, we remove it first.
if len(patient.getElementsByTagName(form['form'].value)) != 0:
  patient.removeChild(patient.getElementsByTagName(form['form'].value)[0]);
patient.appendChild(data);

#Saving the new data to the XML file.
xmlData.seek(0); #Going to the beginning of the file.
xmlData.write(dom.toxml(encoding = xmlEncoding));
xmlData.truncate();
xmlData.close(); #Releasing the file (calls also unlock).

returnPage = "busca.cgi?uid=%s" % functions.fmt2GetMethod(os.environ["REMOTE_USER"]);
if functions.isMobile(os.environ): returnPage = "palm.psp";