CodeFileTreeNode.py
changeset 1330 96b242e4c59d
parent 1315 ff14a66bbd12
child 1332 ac7d39f4e376
equal deleted inserted replaced
1328:a2f2981df9b0 1330:96b242e4c59d
     1 import os, re
     1 import os, re, traceback
     2 
     2 
     3 from copy import deepcopy
     3 from copy import deepcopy
     4 from lxml import etree
     4 from lxml import etree
     5 from xmlclass import GenerateParserFromXSDstring
     5 from xmlclass import GenerateParserFromXSDstring
     6 
     6 
     7 from PLCControler import UndoBuffer
     7 from PLCControler import UndoBuffer
       
     8 from ConfigTreeNode import XSDSchemaErrorMessage
     8 
     9 
     9 CODEFILE_XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
    10 CODEFILE_XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
    10 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    11 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    11             xmlns:xhtml="http://www.w3.org/1999/xhtml">
    12             xmlns:xhtml="http://www.w3.org/1999/xhtml">
    12   <xsd:element name="%(codefile_name)s">
    13   <xsd:element name="%(codefile_name)s">
    82                 '<%s xmlns:xhtml="http://www.w3.org/1999/xhtml">' % self.CODEFILE_NAME)
    83                 '<%s xmlns:xhtml="http://www.w3.org/1999/xhtml">' % self.CODEFILE_NAME)
    83             for cre, repl in [
    84             for cre, repl in [
    84                 (re.compile("(?<!<xhtml:p>)(?:<!\[CDATA\[)"), "<xhtml:p><![CDATA["),
    85                 (re.compile("(?<!<xhtml:p>)(?:<!\[CDATA\[)"), "<xhtml:p><![CDATA["),
    85                 (re.compile("(?:]]>)(?!</xhtml:p>)"), "]]></xhtml:p>")]:
    86                 (re.compile("(?:]]>)(?!</xhtml:p>)"), "]]></xhtml:p>")]:
    86                 codefile_xml = cre.sub(repl, codefile_xml)
    87                 codefile_xml = cre.sub(repl, codefile_xml)
    87             self.CodeFile = etree.fromstring(codefile_xml, self.CodeFileParser)    
    88             
    88             self.CreateCodeFileBuffer(True)
    89             try:
    89         
    90                 self.CodeFile, error = self.CodeFileParser.LoadXMLString(codefile_xml)
       
    91                 if error is not None:
       
    92                     self.GetCTRoot().logger.write_warning(
       
    93                         XMLSyntaxErrorMessage % ((self.CODEFILE_NAME,) + error))
       
    94                 self.CreateCodeFileBuffer(True)
       
    95             except Exception, exc:
       
    96                 self.GetCTRoot().logger.write_error(_("Couldn't load confnode parameters %s :\n %s") % (CTNName, unicode(exc)))
       
    97                 self.GetCTRoot().logger.write_error(traceback.format_exc())
    90         else:
    98         else:
    91             self.CodeFile = self.CodeFileParser.CreateRoot()
    99             self.CodeFile = self.CodeFileParser.CreateRoot()
    92             self.CreateCodeFileBuffer(False)
   100             self.CreateCodeFileBuffer(False)
    93             self.OnCTNSave()
   101             self.OnCTNSave()
    94 
   102