ConfigTreeNode.py
branchpython3
changeset 3750 f62625418bff
parent 3674 d10a7907fb43
child 3752 9f6f46dbe3ae
equal deleted inserted replaced
3749:fda6c1a37662 3750:f62625418bff
    29 - Project tree organization match filesystem organization of project directory.
    29 - Project tree organization match filesystem organization of project directory.
    30 - Each node of the tree have its own xml configuration, whose grammar is defined for each node type, as XSD
    30 - Each node of the tree have its own xml configuration, whose grammar is defined for each node type, as XSD
    31 - ... TODO : document
    31 - ... TODO : document
    32 """
    32 """
    33 
    33 
    34 from __future__ import absolute_import
    34 
    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 operator import add
    39 from operator import add
   317             extra_files += _extra_files
   317             extra_files += _extra_files
   318 
   318 
   319         return LocationCFilesAndCFLAGS, LDFLAGS, extra_files
   319         return LocationCFilesAndCFLAGS, LDFLAGS, extra_files
   320 
   320 
   321     def IterChildren(self):
   321     def IterChildren(self):
   322         for _CTNType, Children in self.Children.items():
   322         for _CTNType, Children in list(self.Children.items()):
   323             for CTNInstance in Children:
   323             for CTNInstance in Children:
   324                 yield CTNInstance
   324                 yield CTNInstance
   325 
   325 
   326     def IECSortedChildren(self):
   326     def IECSortedChildren(self):
   327         # reorder children by IEC_channels
   327         # reorder children by IEC_channels
   328         ordered = [(chld.BaseParams.getIEC_Channel(), chld) for chld in self.IterChildren()]
   328         ordered = [(chld.BaseParams.getIEC_Channel(), chld) for chld in self.IterChildren()]
   329         if ordered:
   329         if ordered:
   330             ordered.sort()
   330             ordered.sort()
   331             return zip(*ordered)[1]
   331             return list(zip(*ordered))[1]
   332         else:
   332         else:
   333             return []
   333             return []
   334 
   334 
   335     def _GetChildBySomething(self, something, toks):
   335     def _GetChildBySomething(self, something, toks):
   336         for CTNInstance in self.IterChildren():
   336         for CTNInstance in self.IterChildren():
   541         @param CTNType: string desining the confnode class name (get name from CTNChildrenTypes)
   541         @param CTNType: string desining the confnode class name (get name from CTNChildrenTypes)
   542         @param CTNName: string for the name of the confnode instance
   542         @param CTNName: string for the name of the confnode instance
   543         """
   543         """
   544         # reorganize self.CTNChildrenTypes tuples from (name, CTNClass, Help)
   544         # reorganize self.CTNChildrenTypes tuples from (name, CTNClass, Help)
   545         # to ( name, (CTNClass, Help)), an make a dict
   545         # to ( name, (CTNClass, Help)), an make a dict
   546         transpose = zip(*self.CTNChildrenTypes)
   546         transpose = list(zip(*self.CTNChildrenTypes))
   547         CTNChildrenTypes = dict(zip(transpose[0], zip(transpose[1], transpose[2])))
   547         CTNChildrenTypes = dict(list(zip(transpose[0], list(zip(transpose[1], transpose[2])))))
   548         # Check that adding this confnode is allowed
   548         # Check that adding this confnode is allowed
   549         try:
   549         try:
   550             CTNClass, CTNHelp = CTNChildrenTypes[CTNType]
   550             CTNClass, CTNHelp = CTNChildrenTypes[CTNType]
   551         except KeyError:
   551         except KeyError:
   552             raise Exception(_("Cannot create child {a1} of type {a2} ").
   552             raise Exception(_("Cannot create child {a1} of type {a2} ").
   630         self.Children = {}
   630         self.Children = {}
   631 
   631 
   632     def LoadXMLParams(self, CTNName=None):
   632     def LoadXMLParams(self, CTNName=None):
   633         methode_name = os.path.join(self.CTNPath(CTNName), "methods.py")
   633         methode_name = os.path.join(self.CTNPath(CTNName), "methods.py")
   634         if os.path.isfile(methode_name):
   634         if os.path.isfile(methode_name):
   635             execfile(methode_name)
   635             exec(compile(open(methode_name, "rb").read(), methode_name, 'exec'))
   636 
   636 
   637         ConfNodeName = CTNName if CTNName is not None else self.CTNName()
   637         ConfNodeName = CTNName if CTNName is not None else self.CTNName()
   638 
   638 
   639         # Get the base xml tree
   639         # Get the base xml tree
   640         if self.MandatoryParams:
   640         if self.MandatoryParams: