ConfigTreeNode.py
changeset 2434 07f48018b6f5
parent 2418 5587c490a070
child 2443 75a274023970
equal deleted inserted replaced
2433:2e8bf28a8909 2434:07f48018b6f5
    34 from __future__ import absolute_import
    34 from __future__ import absolute_import
    35 import os
    35 import os
    36 import traceback
    36 import traceback
    37 import types
    37 import types
    38 import shutil
    38 import shutil
       
    39 from builtins import str as text
       
    40 
    39 from lxml import etree
    41 from lxml import etree
    40 
    42 
    41 from xmlclass import GenerateParserFromXSDstring
    43 from xmlclass import GenerateParserFromXSDstring
    42 
       
    43 from PLCControler import LOCATION_CONFNODE
    44 from PLCControler import LOCATION_CONFNODE
    44 from editors.ConfTreeNodeEditor import ConfTreeNodeEditor
    45 from editors.ConfTreeNodeEditor import ConfTreeNodeEditor
    45 
    46 
    46 _BaseParamsParser = GenerateParserFromXSDstring("""<?xml version="1.0" encoding="ISO-8859-1" ?>
    47 _BaseParamsParser = GenerateParserFromXSDstring("""<?xml version="1.0" encoding="ISO-8859-1" ?>
    47         <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    48         <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   275 
   276 
   276         # confnode asks for some LDFLAGS
   277         # confnode asks for some LDFLAGS
   277         LDFLAGS = []
   278         LDFLAGS = []
   278         if CTNLDFLAGS is not None:
   279         if CTNLDFLAGS is not None:
   279             # LDFLAGS can be either string
   280             # LDFLAGS can be either string
   280             if isinstance(CTNLDFLAGS, (str, unicode)):
   281             if isinstance(CTNLDFLAGS, (str, text)):
   281                 LDFLAGS += [CTNLDFLAGS]
   282                 LDFLAGS += [CTNLDFLAGS]
   282             # or list of strings
   283             # or list of strings
   283             elif isinstance(CTNLDFLAGS, list):
   284             elif isinstance(CTNLDFLAGS, list):
   284                 LDFLAGS += CTNLDFLAGS
   285                 LDFLAGS += CTNLDFLAGS
   285 
   286 
   625                     (fname, lnum, src) = ((ConfNodeName + " BaseParams",) + error)
   626                     (fname, lnum, src) = ((ConfNodeName + " BaseParams",) + error)
   626                     self.GetCTRoot().logger.write_warning(XSDSchemaErrorMessage.format(a1=fname, a2=lnum, a3=src))
   627                     self.GetCTRoot().logger.write_warning(XSDSchemaErrorMessage.format(a1=fname, a2=lnum, a3=src))
   627                 self.MandatoryParams = ("BaseParams", self.BaseParams)
   628                 self.MandatoryParams = ("BaseParams", self.BaseParams)
   628                 basexmlfile.close()
   629                 basexmlfile.close()
   629             except Exception as exc:
   630             except Exception as exc:
   630                 msg = _("Couldn't load confnode base parameters {a1} :\n {a2}").format(a1=ConfNodeName, a2=unicode(exc))
   631                 msg = _("Couldn't load confnode base parameters {a1} :\n {a2}").format(a1=ConfNodeName, a2=text(exc))
   631                 self.GetCTRoot().logger.write_error(msg)
   632                 self.GetCTRoot().logger.write_error(msg)
   632                 self.GetCTRoot().logger.write_error(traceback.format_exc())
   633                 self.GetCTRoot().logger.write_error(traceback.format_exc())
   633 
   634 
   634         # Get the xml tree
   635         # Get the xml tree
   635         if self.CTNParams:
   636         if self.CTNParams:
   642                 name = obj.getLocalTag()
   643                 name = obj.getLocalTag()
   643                 setattr(self, name, obj)
   644                 setattr(self, name, obj)
   644                 self.CTNParams = (name, obj)
   645                 self.CTNParams = (name, obj)
   645                 xmlfile.close()
   646                 xmlfile.close()
   646             except Exception as exc:
   647             except Exception as exc:
   647                 msg = _("Couldn't load confnode parameters {a1} :\n {a2}").format(a1=ConfNodeName, a2=unicode(exc))
   648                 msg = _("Couldn't load confnode parameters {a1} :\n {a2}").format(a1=ConfNodeName, a2=text(exc))
   648                 self.GetCTRoot().logger.write_error(msg)
   649                 self.GetCTRoot().logger.write_error(msg)
   649                 self.GetCTRoot().logger.write_error(traceback.format_exc())
   650                 self.GetCTRoot().logger.write_error(traceback.format_exc())
   650 
   651 
   651     def LoadChildren(self):
   652     def LoadChildren(self):
   652         # Iterate over all CTNName@CTNType in confnode directory, and try to open them
   653         # Iterate over all CTNName@CTNType in confnode directory, and try to open them
   655                CTNDir.count(NameTypeSeparator) == 1:
   656                CTNDir.count(NameTypeSeparator) == 1:
   656                 pname, ptype = CTNDir.split(NameTypeSeparator)
   657                 pname, ptype = CTNDir.split(NameTypeSeparator)
   657                 try:
   658                 try:
   658                     self.CTNAddChild(pname, ptype)
   659                     self.CTNAddChild(pname, ptype)
   659                 except Exception as exc:
   660                 except Exception as exc:
   660                     msg = _("Could not add child \"{a1}\", type {a2} :\n{a3}\n").format(a1=pname, a2=ptype, a3=unicode(exc))
   661                     msg = _("Could not add child \"{a1}\", type {a2} :\n{a3}\n").format(a1=pname, a2=ptype, a3=text(exc))
   661                     self.GetCTRoot().logger.write_error(msg)
   662                     self.GetCTRoot().logger.write_error(msg)
   662                     self.GetCTRoot().logger.write_error(traceback.format_exc())
   663                     self.GetCTRoot().logger.write_error(traceback.format_exc())