def xmlSetup(self, logType, logList):
from xml.etree.ElementTree import Element, SubElement, ElementTree<EOL>from datetime import datetime<EOL>curr_time = datetime.now()<EOL>if logType == "<STR_LIT>":<EOL><INDENT>log_entry = Element('<STR_LIT>')<EOL>title     = SubElement(log_entry, '<STR_LIT:title>')<EOL>program   = SubElement(log_entry, '<STR_LIT>')<EOL>timestamp = SubElement(log_entry, '<STR_LIT>')<EOL>priority  = SubElement(log_entry, '<STR_LIT>')<EOL>os_user   = SubElement(log_entry, '<STR_LIT>')<EOL>hostname  = SubElement(log_entry, '<STR_LIT>')<EOL>text      = SubElement(log_entry, '<STR_LIT:text>')<EOL>log_user  = SubElement(log_entry, '<STR_LIT>')<EOL>logbook = []<EOL>for i in range(len(logList)):<EOL><INDENT>logbook.append(SubElement(log_entry, '<STR_LIT>'))<EOL>logbook[i].text = logList[i].lower()<EOL><DEDENT>log_entry.attrib['<STR_LIT:type>'] = "<STR_LIT>"<EOL>program.text = "<STR_LIT>"<EOL>priority.text = "<STR_LIT>"<EOL>os_user.text = "<STR_LIT>"<EOL>hostname.text = "<STR_LIT>"<EOL>text.attrib['<STR_LIT:type>'] = "<STR_LIT>"<EOL>if not self.imagePixmap.isNull():<EOL><INDENT>attachment = SubElement(log_entry, '<STR_LIT>')<EOL>attachment.attrib['<STR_LIT:name>'] = "<STR_LIT>"<EOL>attachment.attrib['<STR_LIT:type>'] = "<STR_LIT>" + self.imageType<EOL>attachment.text = curr_time.strftime("<STR_LIT>") + str(curr_time.microsecond) + "<STR_LIT:.>" + self.imageType<EOL><DEDENT>timestamp.text = curr_time.strftime("<STR_LIT>")<EOL>fileName = "<STR_LIT>" + curr_time.strftime("<STR_LIT>") + str(curr_time.microsecond) + "<STR_LIT>"<EOL><DEDENT>else:  <EOL><INDENT>timeString = curr_time.strftime("<STR_LIT>")<EOL>log_entry = Element(None)<EOL>severity  = SubElement(log_entry, '<STR_LIT>')<EOL>location  = SubElement(log_entry, '<STR_LIT:location>')<EOL>keywords  = SubElement(log_entry, '<STR_LIT>')<EOL>time      = SubElement(log_entry, '<STR_LIT:time>')<EOL>isodate   = SubElement(log_entry, '<STR_LIT>')<EOL>log_user  = SubElement(log_entry, '<STR_LIT>')<EOL>category  = SubElement(log_entry, '<STR_LIT>')<EOL>title     = SubElement(log_entry, '<STR_LIT:title>')<EOL>metainfo  = SubElement(log_entry, '<STR_LIT>')<EOL>if not self.imagePixmap.isNull():<EOL><INDENT>imageFile = SubElement(log_entry, '<STR_LIT>')<EOL>imageFile.text = timeString + "<STR_LIT>" + self.imageType<EOL>thumbnail = SubElement(log_entry, '<STR_LIT:file>')<EOL>thumbnail.text = timeString + "<STR_LIT>"<EOL><DEDENT>text      = SubElement(log_entry, '<STR_LIT:text>')  <EOL>log_entry.attrib['<STR_LIT:type>'] = "<STR_LIT>"<EOL>category.text = "<STR_LIT>"<EOL>location.text = "<STR_LIT>"<EOL>severity.text = "<STR_LIT>"<EOL>keywords.text = "<STR_LIT:none>"<EOL>time.text = curr_time.strftime("<STR_LIT>")<EOL>isodate.text = curr_time.strftime("<STR_LIT>")<EOL>metainfo.text = timeString + "<STR_LIT>"<EOL>fileName = "<STR_LIT>" + metainfo.text<EOL><DEDENT>log_user.text = str(self.logui.userName.text())<EOL>title.text = str(self.logui.titleEntry.text())<EOL>if title.text == "<STR_LIT>":<EOL><INDENT>QMessageBox().warning(self, "<STR_LIT>", "<STR_LIT>")<EOL>return None<EOL><DEDENT>text.text = str(self.logui.textEntry.toPlainText())<EOL>if text.text == "<STR_LIT>":<EOL><INDENT>text.text = "<STR_LIT:U+0020>"<EOL><DEDENT>xmlFile = open(fileName, "<STR_LIT:w>")<EOL>if logType == "<STR_LIT>":<EOL><INDENT>ElementTree(log_entry).write(xmlFile)<EOL><DEDENT>else:<EOL><INDENT>xmlString = self.prettify(log_entry)<EOL>xmlFile.write(xmlString)<EOL><DEDENT>xmlFile.write("<STR_LIT:\n>")  <EOL>xmlFile.close()<EOL>return fileName.rstrip("<STR_LIT>")<EOL>
Create xml file with fields from logbook form.