ConfigTreeNode.py
branchpython3
changeset 3752 9f6f46dbe3ae
parent 3750 f62625418bff
child 3755 ca814b175391
equal deleted inserted replaced
3751:a80a66ba52d6 3752:9f6f46dbe3ae
    36 import traceback
    36 import traceback
    37 import types
    37 import types
    38 import shutil
    38 import shutil
    39 from operator import add
    39 from operator import add
    40 from functools import reduce
    40 from functools import reduce
    41 from builtins import str as text
       
    42 from past.builtins import execfile
       
    43 
    41 
    44 from lxml import etree
    42 from lxml import etree
    45 
    43 
    46 from xmlclass import GenerateParserFromXSDstring
    44 from xmlclass import GenerateParserFromXSDstring
    47 from PLCControler import LOCATION_CONFNODE
    45 from PLCControler import LOCATION_CONFNODE
   292 
   290 
   293         # confnode asks for some LDFLAGS
   291         # confnode asks for some LDFLAGS
   294         LDFLAGS = []
   292         LDFLAGS = []
   295         if CTNLDFLAGS is not None:
   293         if CTNLDFLAGS is not None:
   296             # LDFLAGS can be either string
   294             # LDFLAGS can be either string
   297             if isinstance(CTNLDFLAGS, (str, text)):
   295             if isinstance(CTNLDFLAGS, str):
   298                 LDFLAGS += [CTNLDFLAGS]
   296                 LDFLAGS += [CTNLDFLAGS]
   299             # or list of strings
   297             # or list of strings
   300             elif isinstance(CTNLDFLAGS, list):
   298             elif isinstance(CTNLDFLAGS, list):
   301                 LDFLAGS += CTNLDFLAGS
   299                 LDFLAGS += CTNLDFLAGS
   302 
   300 
   645                     (fname, lnum, src) = ((ConfNodeName + " BaseParams",) + error)
   643                     (fname, lnum, src) = ((ConfNodeName + " BaseParams",) + error)
   646                     self.GetCTRoot().logger.write_warning(XSDSchemaErrorMessage.format(a1=fname, a2=lnum, a3=src))
   644                     self.GetCTRoot().logger.write_warning(XSDSchemaErrorMessage.format(a1=fname, a2=lnum, a3=src))
   647                 self.MandatoryParams = ("BaseParams", self.BaseParams)
   645                 self.MandatoryParams = ("BaseParams", self.BaseParams)
   648                 basexmlfile.close()
   646                 basexmlfile.close()
   649             except Exception as exc:
   647             except Exception as exc:
   650                 msg = _("Couldn't load confnode base parameters {a1} :\n {a2}").format(a1=ConfNodeName, a2=text(exc))
   648                 msg = _("Couldn't load confnode base parameters {a1} :\n {a2}").format(a1=ConfNodeName, a2=str(exc))
   651                 self.GetCTRoot().logger.write_error(msg)
   649                 self.GetCTRoot().logger.write_error(msg)
   652                 self.GetCTRoot().logger.write_error(traceback.format_exc())
   650                 self.GetCTRoot().logger.write_error(traceback.format_exc())
   653 
   651 
   654         # Get the xml tree
   652         # Get the xml tree
   655         if self.CTNParams:
   653         if self.CTNParams:
   662                 name = obj.getLocalTag()
   660                 name = obj.getLocalTag()
   663                 setattr(self, name, obj)
   661                 setattr(self, name, obj)
   664                 self.CTNParams = (name, obj)
   662                 self.CTNParams = (name, obj)
   665                 xmlfile.close()
   663                 xmlfile.close()
   666             except Exception as exc:
   664             except Exception as exc:
   667                 msg = _("Couldn't load confnode parameters {a1} :\n {a2}").format(a1=ConfNodeName, a2=text(exc))
   665                 msg = _("Couldn't load confnode parameters {a1} :\n {a2}").format(a1=ConfNodeName, a2=str(exc))
   668                 self.GetCTRoot().logger.write_error(msg)
   666                 self.GetCTRoot().logger.write_error(msg)
   669                 self.GetCTRoot().logger.write_error(traceback.format_exc())
   667                 self.GetCTRoot().logger.write_error(traceback.format_exc())
   670 
   668 
   671     def LoadChildren(self):
   669     def LoadChildren(self):
   672         # Iterate over all CTNName@CTNType in confnode directory, and try to open them
   670         # Iterate over all CTNName@CTNType in confnode directory, and try to open them
   675                CTNDir.count(NameTypeSeparator) == 1:
   673                CTNDir.count(NameTypeSeparator) == 1:
   676                 pname, ptype = CTNDir.split(NameTypeSeparator)
   674                 pname, ptype = CTNDir.split(NameTypeSeparator)
   677                 try:
   675                 try:
   678                     self.CTNAddChild(pname, ptype)
   676                     self.CTNAddChild(pname, ptype)
   679                 except Exception as exc:
   677                 except Exception as exc:
   680                     msg = _("Could not add child \"{a1}\", type {a2} :\n{a3}\n").format(a1=pname, a2=ptype, a3=text(exc))
   678                     msg = _("Could not add child \"{a1}\", type {a2} :\n{a3}\n").format(a1=pname, a2=ptype, a3=str(exc))
   681                     self.GetCTRoot().logger.write_error(msg)
   679                     self.GetCTRoot().logger.write_error(msg)
   682                     self.GetCTRoot().logger.write_error(traceback.format_exc())
   680                     self.GetCTRoot().logger.write_error(traceback.format_exc())
   683 
   681 
   684 
   682 
   685     def FatalError(self, message):
   683     def FatalError(self, message):