Пример #1
0
 def readXMLFile(self, xmlfile):
     # check, if the filename is valid
     if not FileHandling.filename_is_valid(xmlfile, "xml"):
         raise ValueError("file name not valid")
     
     try:
         xml = ElementTree.parse(xmlfile)
         self.root = xml.getroot()
     except ElementTree.ParseError:
         return False
         
     return True
Пример #2
0
    def writeXMLFile(self, project, items, xmlfile):
        # check, if the filename is valid
        if not FileHandling.filename_is_valid(xmlfile, "xml"):
            raise ValueError("file name not valid")
        newfile = xmlfile.strip()

        # temporarily add _tmp to the filename, if the file already exists
        exists = os.path.isfile(newfile)
        if exists:
            newfile = newfile.replace(".xml", "_tmp.xml", 1)

        # write all XML data to the file
        try:
            xml = self.createXMLData(project, items)
            xml.write(newfile, xml_declaration=True, encoding="utf-8")
            if exists:
                os.remove(xmlfile.strip())
                os.rename(newfile, xmlfile.strip())
        except OSError:
            return False
        
        return True