ConfigTreeNode.py
changeset 1730 64d8f52bc8c8
parent 1722 89824afffef2
child 1732 94ffe74e6895
equal deleted inserted replaced
1726:d51af006fa6b 1730:64d8f52bc8c8
    65     CTNMaxCount = None
    65     CTNMaxCount = None
    66     ConfNodeMethods = []
    66     ConfNodeMethods = []
    67     LibraryControler = None
    67     LibraryControler = None
    68     EditorType = ConfTreeNodeEditor
    68     EditorType = ConfTreeNodeEditor
    69     IconPath = None
    69     IconPath = None
    70     
    70 
    71     def _AddParamsMembers(self):
    71     def _AddParamsMembers(self):
    72         self.CTNParams = None
    72         self.CTNParams = None
    73         if self.XSD:
    73         if self.XSD:
    74             self.Parser = GenerateParserFromXSDstring(self.XSD)
    74             self.Parser = GenerateParserFromXSDstring(self.XSD)
    75             obj = self.Parser.CreateRoot()
    75             obj = self.Parser.CreateRoot()
    76             name = obj.getLocalTag()
    76             name = obj.getLocalTag()
    77             self.CTNParams = (name, obj)
    77             self.CTNParams = (name, obj)
    78             setattr(self, name, obj)
    78             setattr(self, name, obj)
    79 
    79 
    80     def __init__(self):
    80     def __init__(self):
    81         # Create BaseParam 
    81         # Create BaseParam
    82         self.BaseParams = _BaseParamsParser.CreateRoot()
    82         self.BaseParams = _BaseParamsParser.CreateRoot()
    83         self.MandatoryParams = ("BaseParams", self.BaseParams)
    83         self.MandatoryParams = ("BaseParams", self.BaseParams)
    84         self._AddParamsMembers()
    84         self._AddParamsMembers()
    85         self.Children = {}
    85         self.Children = {}
    86         self._View = None
    86         self._View = None
    87         # copy ConfNodeMethods so that it can be later customized
    87         # copy ConfNodeMethods so that it can be later customized
    88         self.ConfNodeMethods = [dic.copy() for dic in self.ConfNodeMethods]
    88         self.ConfNodeMethods = [dic.copy() for dic in self.ConfNodeMethods]
    89         
    89 
    90     def ConfNodeBaseXmlFilePath(self, CTNName=None):
    90     def ConfNodeBaseXmlFilePath(self, CTNName=None):
    91         return os.path.join(self.CTNPath(CTNName), "baseconfnode.xml")
    91         return os.path.join(self.CTNPath(CTNName), "baseconfnode.xml")
    92     
    92 
    93     def ConfNodeXmlFilePath(self, CTNName=None):
    93     def ConfNodeXmlFilePath(self, CTNName=None):
    94         return os.path.join(self.CTNPath(CTNName), "confnode.xml")
    94         return os.path.join(self.CTNPath(CTNName), "confnode.xml")
    95 
    95 
    96     def ConfNodePath(self):
    96     def ConfNodePath(self):
    97         return os.path.join(self.CTNParent.ConfNodePath(), self.CTNType)
    97         return os.path.join(self.CTNParent.ConfNodePath(), self.CTNType)
   101             CTNName = self.CTNName()
   101             CTNName = self.CTNName()
   102         if not project_path:
   102         if not project_path:
   103             project_path = self.CTNParent.CTNPath()
   103             project_path = self.CTNParent.CTNPath()
   104         return os.path.join(project_path,
   104         return os.path.join(project_path,
   105                             CTNName + NameTypeSeparator + self.CTNType)
   105                             CTNName + NameTypeSeparator + self.CTNType)
   106     
   106 
   107     def CTNName(self):
   107     def CTNName(self):
   108         return self.BaseParams.getName()
   108         return self.BaseParams.getName()
   109     
   109 
   110     def CTNEnabled(self):
   110     def CTNEnabled(self):
   111         return self.BaseParams.getEnabled()
   111         return self.BaseParams.getEnabled()
   112     
   112 
   113     def CTNFullName(self):
   113     def CTNFullName(self):
   114         parent = self.CTNParent.CTNFullName()
   114         parent = self.CTNParent.CTNFullName()
   115         if parent != "":
   115         if parent != "":
   116             return parent + "." + self.CTNName()
   116             return parent + "." + self.CTNName()
   117         return self.BaseParams.getName()
   117         return self.BaseParams.getName()
   118     
   118 
   119     def GetIconName(self):
   119     def GetIconName(self):
   120         return None
   120         return None
   121     
   121 
   122     def CTNTestModified(self):
   122     def CTNTestModified(self):
   123         return self.ChangesToSave
   123         return self.ChangesToSave
   124 
   124 
   125     def ProjectTestModified(self):
   125     def ProjectTestModified(self):
   126         """
   126         """
   132         for CTNChild in self.IterChildren():
   132         for CTNChild in self.IterChildren():
   133             if CTNChild.ProjectTestModified():
   133             if CTNChild.ProjectTestModified():
   134                 return True
   134                 return True
   135 
   135 
   136         return False
   136         return False
   137     
   137 
   138     def RemoteExec(self, script, **kwargs):
   138     def RemoteExec(self, script, **kwargs):
   139         return self.CTNParent.RemoteExec(script, **kwargs)
   139         return self.CTNParent.RemoteExec(script, **kwargs)
   140     
   140 
   141     def OnCTNSave(self, from_project_path=None):
   141     def OnCTNSave(self, from_project_path=None):
   142         #Default, do nothing and return success
   142         #Default, do nothing and return success
   143         return True
   143         return True
   144 
   144 
   145     def GetParamsAttributes(self, path = None):
   145     def GetParamsAttributes(self, path = None):
   152         else:
   152         else:
   153             params = []
   153             params = []
   154             if self.CTNParams:
   154             if self.CTNParams:
   155                 params.append(self.CTNParams[1].getElementInfos(self.CTNParams[0]))
   155                 params.append(self.CTNParams[1].getElementInfos(self.CTNParams[0]))
   156             return params
   156             return params
   157         
   157 
   158     def SetParamsAttribute(self, path, value):
   158     def SetParamsAttribute(self, path, value):
   159         self.ChangesToSave = True
   159         self.ChangesToSave = True
   160         # Filter IEC_Channel and Name, that have specific behavior
   160         # Filter IEC_Channel and Name, that have specific behavior
   161         if path == "BaseParams.IEC_Channel":
   161         if path == "BaseParams.IEC_Channel":
   162             old_leading = ".".join(map(str, self.GetCurrentLocation()))
   162             old_leading = ".".join(map(str, self.GetCurrentLocation()))
   167             return new_value, True
   167             return new_value, True
   168         elif path == "BaseParams.Name":
   168         elif path == "BaseParams.Name":
   169             res = self.FindNewName(value)
   169             res = self.FindNewName(value)
   170             self.CTNRequestSave()
   170             self.CTNRequestSave()
   171             return res, True
   171             return res, True
   172         
   172 
   173         parts = path.split(".", 1)
   173         parts = path.split(".", 1)
   174         if self.MandatoryParams and parts[0] == self.MandatoryParams[0]:
   174         if self.MandatoryParams and parts[0] == self.MandatoryParams[0]:
   175             self.MandatoryParams[1].setElementValue(parts[1], value)
   175             self.MandatoryParams[1].setElementValue(parts[1], value)
   176             value = self.MandatoryParams[1].getElementInfos(parts[0], parts[1])["value"]
   176             value = self.MandatoryParams[1].getElementInfos(parts[0], parts[1])["value"]
   177         elif self.CTNParams and parts[0] == self.CTNParams[0]:
   177         elif self.CTNParams and parts[0] == self.CTNParams[0]:
   187             # If confnode do not have corresponding directory
   187             # If confnode do not have corresponding directory
   188             ctnpath = self.CTNPath()
   188             ctnpath = self.CTNPath()
   189             if not os.path.isdir(ctnpath):
   189             if not os.path.isdir(ctnpath):
   190                 # Create it
   190                 # Create it
   191                 os.mkdir(ctnpath)
   191                 os.mkdir(ctnpath)
   192     
   192 
   193             # generate XML for base XML parameters controller of the confnode
   193             # generate XML for base XML parameters controller of the confnode
   194             if self.MandatoryParams:
   194             if self.MandatoryParams:
   195                 BaseXMLFile = open(self.ConfNodeBaseXmlFilePath(),'w')
   195                 BaseXMLFile = open(self.ConfNodeBaseXmlFilePath(),'w')
   196                 BaseXMLFile.write(etree.tostring(
   196                 BaseXMLFile.write(etree.tostring(
   197                     self.MandatoryParams[1], 
   197                     self.MandatoryParams[1],
   198                     pretty_print=True, 
   198                     pretty_print=True,
   199                     xml_declaration=True, 
   199                     xml_declaration=True,
   200                     encoding='utf-8'))
   200                     encoding='utf-8'))
   201                 BaseXMLFile.close()
   201                 BaseXMLFile.close()
   202             
   202 
   203             # generate XML for XML parameters controller of the confnode
   203             # generate XML for XML parameters controller of the confnode
   204             if self.CTNParams:
   204             if self.CTNParams:
   205                 XMLFile = open(self.ConfNodeXmlFilePath(),'w')
   205                 XMLFile = open(self.ConfNodeXmlFilePath(),'w')
   206                 XMLFile.write(etree.tostring(
   206                 XMLFile.write(etree.tostring(
   207                     self.CTNParams[1], 
   207                     self.CTNParams[1],
   208                     pretty_print=True, 
   208                     pretty_print=True,
   209                     xml_declaration=True, 
   209                     xml_declaration=True,
   210                     encoding='utf-8'))
   210                     encoding='utf-8'))
   211                 XMLFile.close()
   211                 XMLFile.close()
   212             
   212 
   213             # Call the confnode specific OnCTNSave method
   213             # Call the confnode specific OnCTNSave method
   214             result = self.OnCTNSave(from_project_path)
   214             result = self.OnCTNSave(from_project_path)
   215             if not result:
   215             if not result:
   216                 return _("Error while saving \"%s\"\n")%self.CTNPath()
   216                 return _("Error while saving \"%s\"\n")%self.CTNPath()
   217     
   217 
   218             # mark confnode as saved
   218             # mark confnode as saved
   219             self.ChangesToSave = False
   219             self.ChangesToSave = False
   220             # go through all children and do the same
   220             # go through all children and do the same
   221             for CTNChild in self.IterChildren():
   221             for CTNChild in self.IterChildren():
   222                 CTNChildPath = None
   222                 CTNChildPath = None
   224                     CTNChildPath = CTNChild.CTNPath(project_path=from_project_path)
   224                     CTNChildPath = CTNChild.CTNPath(project_path=from_project_path)
   225                 result = CTNChild.CTNRequestSave(CTNChildPath)
   225                 result = CTNChild.CTNRequestSave(CTNChildPath)
   226                 if result:
   226                 if result:
   227                     return result
   227                     return result
   228         return None
   228         return None
   229     
   229 
   230     def CTNImport(self, src_CTNPath):
   230     def CTNImport(self, src_CTNPath):
   231         shutil.copytree(src_CTNPath, self.CTNPath)
   231         shutil.copytree(src_CTNPath, self.CTNPath)
   232         return True
   232         return True
   233 
   233 
   234     def CTNGlobalInstances(self):
   234     def CTNGlobalInstances(self):
   235         """
   235         """
   236         @return: [(instance_name, instance_type),...]
   236         @return: [(instance_name, instance_type),...]
   237         """
   237         """
   238         return []
   238         return []
   239     
   239 
   240     def _GlobalInstances(self):
   240     def _GlobalInstances(self):
   241         instances = self.CTNGlobalInstances()
   241         instances = self.CTNGlobalInstances()
   242         for CTNChild in self.IECSortedChildren():
   242         for CTNChild in self.IECSortedChildren():
   243             instances.extend(CTNChild._GlobalInstances())
   243             instances.extend(CTNChild._GlobalInstances())
   244         return instances
   244         return instances
   245     
   245 
   246     def CTNGenerate_C(self, buildpath, locations):
   246     def CTNGenerate_C(self, buildpath, locations):
   247         """
   247         """
   248         Generate C code
   248         Generate C code
   249         @param locations: List of complete variables locations \
   249         @param locations: List of complete variables locations \
   250             [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...)
   250             [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...)
   255             }, ...]
   255             }, ...]
   256         @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
   256         @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
   257         """
   257         """
   258         self.GetCTRoot().logger.write_warning(".".join(map(lambda x:str(x), self.GetCurrentLocation())) + " -> Nothing to do\n")
   258         self.GetCTRoot().logger.write_warning(".".join(map(lambda x:str(x), self.GetCurrentLocation())) + " -> Nothing to do\n")
   259         return [],"",False
   259         return [],"",False
   260     
   260 
   261     def _Generate_C(self, buildpath, locations):
   261     def _Generate_C(self, buildpath, locations):
   262         # Generate confnodes [(Cfiles, CFLAGS)], LDFLAGS, DoCalls, extra_files
   262         # Generate confnodes [(Cfiles, CFLAGS)], LDFLAGS, DoCalls, extra_files
   263         # extra_files = [(fname,fobject), ...]
   263         # extra_files = [(fname,fobject), ...]
   264         gen_result = self.CTNGenerate_C(buildpath, locations)
   264         gen_result = self.CTNGenerate_C(buildpath, locations)
   265         CTNCFilesAndCFLAGS, CTNLDFLAGS, DoCalls = gen_result[:3]
   265         CTNCFilesAndCFLAGS, CTNLDFLAGS, DoCalls = gen_result[:3]
   278             #or list of strings
   278             #or list of strings
   279             elif type(CTNLDFLAGS)==type(list()):
   279             elif type(CTNLDFLAGS)==type(list()):
   280                 LDFLAGS=CTNLDFLAGS[:]
   280                 LDFLAGS=CTNLDFLAGS[:]
   281         else:
   281         else:
   282             LDFLAGS=[]
   282             LDFLAGS=[]
   283         
   283 
   284         # recurse through all children, and stack their results
   284         # recurse through all children, and stack their results
   285         for CTNChild in self.IECSortedChildren():
   285         for CTNChild in self.IECSortedChildren():
   286             new_location = CTNChild.GetCurrentLocation()
   286             new_location = CTNChild.GetCurrentLocation()
   287             # How deep are we in the tree ?
   287             # How deep are we in the tree ?
   288             depth=len(new_location)
   288             depth=len(new_location)
   294                     [loc for loc in locations if loc["LOC"][0:depth] == new_location ])
   294                     [loc for loc in locations if loc["LOC"][0:depth] == new_location ])
   295             # stack the result
   295             # stack the result
   296             LocationCFilesAndCFLAGS += _LocationCFilesAndCFLAGS
   296             LocationCFilesAndCFLAGS += _LocationCFilesAndCFLAGS
   297             LDFLAGS += _LDFLAGS
   297             LDFLAGS += _LDFLAGS
   298             extra_files += _extra_files
   298             extra_files += _extra_files
   299         
   299 
   300         return LocationCFilesAndCFLAGS, LDFLAGS, extra_files
   300         return LocationCFilesAndCFLAGS, LDFLAGS, extra_files
   301 
   301 
   302     def IterChildren(self):
   302     def IterChildren(self):
   303         for CTNType, Children in self.Children.items():
   303         for CTNType, Children in self.Children.items():
   304             for CTNInstance in Children:
   304             for CTNInstance in Children:
   305                 yield CTNInstance
   305                 yield CTNInstance
   306     
   306 
   307     def IECSortedChildren(self):
   307     def IECSortedChildren(self):
   308         # reorder children by IEC_channels
   308         # reorder children by IEC_channels
   309         ordered = [(chld.BaseParams.getIEC_Channel(),chld) for chld in self.IterChildren()]
   309         ordered = [(chld.BaseParams.getIEC_Channel(),chld) for chld in self.IterChildren()]
   310         if ordered:
   310         if ordered:
   311             ordered.sort()
   311             ordered.sort()
   312             return zip(*ordered)[1]
   312             return zip(*ordered)[1]
   313         else:
   313         else:
   314             return []
   314             return []
   315     
   315 
   316     def _GetChildBySomething(self, something, toks):
   316     def _GetChildBySomething(self, something, toks):
   317         for CTNInstance in self.IterChildren():
   317         for CTNInstance in self.IterChildren():
   318             # if match component of the name
   318             # if match component of the name
   319             if getattr(CTNInstance.BaseParams, something) == toks[0]:
   319             if getattr(CTNInstance.BaseParams, something) == toks[0]:
   320                 # if Name have other components
   320                 # if Name have other components
   336     def GetChildByIECLocation(self, Location):
   336     def GetChildByIECLocation(self, Location):
   337         if Location:
   337         if Location:
   338             return self._GetChildBySomething("IEC_Channel", Location)
   338             return self._GetChildBySomething("IEC_Channel", Location)
   339         else:
   339         else:
   340             return self
   340             return self
   341     
   341 
   342     def GetCurrentLocation(self):
   342     def GetCurrentLocation(self):
   343         """
   343         """
   344         @return:  Tupple containing confnode IEC location of current confnode : %I0.0.4.5 => (0,0,4,5)
   344         @return:  Tupple containing confnode IEC location of current confnode : %I0.0.4.5 => (0,0,4,5)
   345         """
   345         """
   346         return self.CTNParent.GetCurrentLocation() + (self.BaseParams.getIEC_Channel(),)
   346         return self.CTNParent.GetCurrentLocation() + (self.BaseParams.getIEC_Channel(),)
   370     def GetVariableLocationTree(self):
   370     def GetVariableLocationTree(self):
   371         '''
   371         '''
   372         This function is meant to be overridden by confnodes.
   372         This function is meant to be overridden by confnodes.
   373 
   373 
   374         It should returns an list of dictionaries
   374         It should returns an list of dictionaries
   375         
   375 
   376         - IEC_type is an IEC type like BOOL/BYTE/SINT/...
   376         - IEC_type is an IEC type like BOOL/BYTE/SINT/...
   377         - location is a string of this variable's location, like "%IX0.0.0"
   377         - location is a string of this variable's location, like "%IX0.0.0"
   378         '''
   378         '''
   379         children = []
   379         children = []
   380         for child in self.IECSortedChildren():
   380         for child in self.IECSortedChildren():
   407             BaseDesiredName = DesiredName
   407             BaseDesiredName = DesiredName
   408         suffix = 1
   408         suffix = 1
   409         while res in AllNames:
   409         while res in AllNames:
   410             res = "%s_%d"%(BaseDesiredName, suffix)
   410             res = "%s_%d"%(BaseDesiredName, suffix)
   411             suffix += 1
   411             suffix += 1
   412         
   412 
   413         # Get old path
   413         # Get old path
   414         oldname = self.CTNPath()
   414         oldname = self.CTNPath()
   415         # Check previous confnode existance
   415         # Check previous confnode existance
   416         dontexist = self.BaseParams.getName() == "__unnamed__"
   416         dontexist = self.BaseParams.getName() == "__unnamed__"
   417         # Set the new name
   417         # Set the new name
   442         CurrentChannel = self.BaseParams.getIEC_Channel()
   442         CurrentChannel = self.BaseParams.getIEC_Channel()
   443         # Do nothing if no change
   443         # Do nothing if no change
   444         #if CurrentChannel == DesiredChannel: return CurrentChannel
   444         #if CurrentChannel == DesiredChannel: return CurrentChannel
   445         # Build a list of used Channels out of parent's Children
   445         # Build a list of used Channels out of parent's Children
   446         AllChannels = self.GetAllChannels()
   446         AllChannels = self.GetAllChannels()
   447         
   447 
   448         # Now, try to guess the nearest available channel
   448         # Now, try to guess the nearest available channel
   449         res = DesiredChannel
   449         res = DesiredChannel
   450         while res in AllChannels: # While channel not free
   450         while res in AllChannels: # While channel not free
   451             if res < CurrentChannel: # Want to go down ?
   451             if res < CurrentChannel: # Want to go down ?
   452                 res -=  1 # Test for n-1
   452                 res -=  1 # Test for n-1
   464 
   464 
   465     def _OpenView(self, name=None, onlyopened=False):
   465     def _OpenView(self, name=None, onlyopened=False):
   466         if self.EditorType is not None:
   466         if self.EditorType is not None:
   467             app_frame = self.GetCTRoot().AppFrame
   467             app_frame = self.GetCTRoot().AppFrame
   468             if self._View is None and not onlyopened:
   468             if self._View is None and not onlyopened:
   469                 
   469 
   470                 self._View = self.EditorType(app_frame.TabsOpened, self, app_frame)
   470                 self._View = self.EditorType(app_frame.TabsOpened, self, app_frame)
   471             
   471 
   472             if self._View is not None:
   472             if self._View is not None:
   473                 if name is None:
   473                 if name is None:
   474                     name = self.CTNFullName()
   474                     name = self.CTNFullName()
   475                 app_frame.EditProjectElement(self._View, name)
   475                 app_frame.EditProjectElement(self._View, name)
   476             
   476 
   477             return self._View
   477             return self._View
   478         return None
   478         return None
   479 
   479 
   480     def _CloseView(self, view):
   480     def _CloseView(self, view):
   481         app_frame = self.GetCTRoot().AppFrame
   481         app_frame = self.GetCTRoot().AppFrame
   525         # Check that adding this confnode is allowed
   525         # Check that adding this confnode is allowed
   526         try:
   526         try:
   527             CTNClass, CTNHelp = CTNChildrenTypes[CTNType]
   527             CTNClass, CTNHelp = CTNChildrenTypes[CTNType]
   528         except KeyError:
   528         except KeyError:
   529             raise Exception, _("Cannot create child {a1} of type {a2} ").format(a1 = CTNName, a2 = CTNType)
   529             raise Exception, _("Cannot create child {a1} of type {a2} ").format(a1 = CTNName, a2 = CTNType)
   530         
   530 
   531         # if CTNClass is a class factory, call it. (prevent unneeded imports)
   531         # if CTNClass is a class factory, call it. (prevent unneeded imports)
   532         if type(CTNClass) == types.FunctionType:
   532         if type(CTNClass) == types.FunctionType:
   533             CTNClass = CTNClass()
   533             CTNClass = CTNClass()
   534         
   534 
   535         # Eventualy Initialize child instance list for this class of confnode
   535         # Eventualy Initialize child instance list for this class of confnode
   536         ChildrenWithSameClass = self.Children.setdefault(CTNType, list())
   536         ChildrenWithSameClass = self.Children.setdefault(CTNType, list())
   537         # Check count
   537         # Check count
   538         if getattr(CTNClass, "CTNMaxCount", None) and len(ChildrenWithSameClass) >= CTNClass.CTNMaxCount:
   538         if getattr(CTNClass, "CTNMaxCount", None) and len(ChildrenWithSameClass) >= CTNClass.CTNMaxCount:
   539             msg = _("Max count ({a1}) reached for this confnode of type {a2} ").format(a1 = CTNClass.CTNMaxCount, a2 = CTNType)
   539             msg = _("Max count ({a1}) reached for this confnode of type {a2} ").format(a1 = CTNClass.CTNMaxCount, a2 = CTNType)
   540             raise Exception, msg
   540             raise Exception, msg
   541         
   541 
   542         # create the final class, derived of provided confnode and template
   542         # create the final class, derived of provided confnode and template
   543         class FinalCTNClass(CTNClass, ConfigTreeNode):
   543         class FinalCTNClass(CTNClass, ConfigTreeNode):
   544             """
   544             """
   545             ConfNode class is derivated into FinalCTNClass before being instanciated
   545             ConfNode class is derivated into FinalCTNClass before being instanciated
   546             This way __init__ is overloaded to ensure ConfigTreeNode.__init__ is called 
   546             This way __init__ is overloaded to ensure ConfigTreeNode.__init__ is called
   547             before CTNClass.__init__, and to do the file related stuff.
   547             before CTNClass.__init__, and to do the file related stuff.
   548             """
   548             """
   549             def __init__(_self):
   549             def __init__(_self):
   550                 # self is the parent
   550                 # self is the parent
   551                 _self.CTNParent = self
   551                 _self.CTNParent = self
   566                         msg = _("Project tree layout do not match confnode.xml {a1}!={a2} ").\
   566                         msg = _("Project tree layout do not match confnode.xml {a1}!={a2} ").\
   567                               format(a1 = NewCTNName, a2 = _self.BaseParams.getName())
   567                               format(a1 = NewCTNName, a2 = _self.BaseParams.getName())
   568                         raise Exception, msg
   568                         raise Exception, msg
   569 
   569 
   570                     # Now, self.CTNPath() should be OK
   570                     # Now, self.CTNPath() should be OK
   571                     
   571 
   572                     # Check that IEC_Channel is not already in use.
   572                     # Check that IEC_Channel is not already in use.
   573                     _self.FindNewIEC_Channel(_self.BaseParams.getIEC_Channel())
   573                     _self.FindNewIEC_Channel(_self.BaseParams.getIEC_Channel())
   574                     # Call the confnode real __init__
   574                     # Call the confnode real __init__
   575                     if getattr(CTNClass, "__init__", None):
   575                     if getattr(CTNClass, "__init__", None):
   576                         CTNClass.__init__(_self)
   576                         CTNClass.__init__(_self)
   587                     if getattr(CTNClass, "__init__", None):
   587                     if getattr(CTNClass, "__init__", None):
   588                         CTNClass.__init__(_self)
   588                         CTNClass.__init__(_self)
   589                     _self.CTNRequestSave()
   589                     _self.CTNRequestSave()
   590                     #just created, must be saved
   590                     #just created, must be saved
   591                     _self.ChangesToSave = True
   591                     _self.ChangesToSave = True
   592                 
   592 
   593             def _getBuildPath(_self):
   593             def _getBuildPath(_self):
   594                 return self._getBuildPath()
   594                 return self._getBuildPath()
   595             
   595 
   596         # Create the object out of the resulting class
   596         # Create the object out of the resulting class
   597         newConfNodeOpj = FinalCTNClass()
   597         newConfNodeOpj = FinalCTNClass()
   598         # Store it in CTNgedChils
   598         # Store it in CTNgedChils
   599         ChildrenWithSameClass.append(newConfNodeOpj)
   599         ChildrenWithSameClass.append(newConfNodeOpj)
   600         
   600 
   601         return newConfNodeOpj
   601         return newConfNodeOpj
   602     
   602 
   603     def ClearChildren(self):
   603     def ClearChildren(self):
   604         for child in self.IterChildren():
   604         for child in self.IterChildren():
   605             child.ClearChildren()
   605             child.ClearChildren()
   606         self.Children = {}
   606         self.Children = {}
   607     
   607 
   608     def LoadXMLParams(self, CTNName = None):
   608     def LoadXMLParams(self, CTNName = None):
   609         methode_name = os.path.join(self.CTNPath(CTNName), "methods.py")
   609         methode_name = os.path.join(self.CTNPath(CTNName), "methods.py")
   610         if os.path.isfile(methode_name):
   610         if os.path.isfile(methode_name):
   611             execfile(methode_name)
   611             execfile(methode_name)
   612         
   612 
   613         ConfNodeName = CTNName if CTNName is not None else self.CTNName()
   613         ConfNodeName = CTNName if CTNName is not None else self.CTNName()
   614         
   614 
   615         # Get the base xml tree
   615         # Get the base xml tree
   616         if self.MandatoryParams:
   616         if self.MandatoryParams:
   617             try:
   617             try:
   618                 basexmlfile = open(self.ConfNodeBaseXmlFilePath(CTNName), 'r')
   618                 basexmlfile = open(self.ConfNodeBaseXmlFilePath(CTNName), 'r')
   619                 self.BaseParams, error = _BaseParamsParser.LoadXMLString(basexmlfile.read())
   619                 self.BaseParams, error = _BaseParamsParser.LoadXMLString(basexmlfile.read())
   624                 basexmlfile.close()
   624                 basexmlfile.close()
   625             except Exception, exc:
   625             except Exception, exc:
   626                 msg = _("Couldn't load confnode base parameters {a1} :\n {a2}").format(a1 =  ConfNodeName, a2 = unicode(exc))
   626                 msg = _("Couldn't load confnode base parameters {a1} :\n {a2}").format(a1 =  ConfNodeName, a2 = unicode(exc))
   627                 self.GetCTRoot().logger.write_error(msg)
   627                 self.GetCTRoot().logger.write_error(msg)
   628                 self.GetCTRoot().logger.write_error(traceback.format_exc())
   628                 self.GetCTRoot().logger.write_error(traceback.format_exc())
   629         
   629 
   630         # Get the xml tree
   630         # Get the xml tree
   631         if self.CTNParams:
   631         if self.CTNParams:
   632             try:
   632             try:
   633                 xmlfile = open(self.ConfNodeXmlFilePath(CTNName), 'r')
   633                 xmlfile = open(self.ConfNodeXmlFilePath(CTNName), 'r')
   634                 obj, error = self.Parser.LoadXMLString(xmlfile.read())
   634                 obj, error = self.Parser.LoadXMLString(xmlfile.read())
   641                 xmlfile.close()
   641                 xmlfile.close()
   642             except Exception, exc:
   642             except Exception, exc:
   643                 msg = _("Couldn't load confnode parameters {a1} :\n {a2}").format(a1 = ConfNodeName, a2 = unicode(exc))
   643                 msg = _("Couldn't load confnode parameters {a1} :\n {a2}").format(a1 = ConfNodeName, a2 = unicode(exc))
   644                 self.GetCTRoot().logger.write_error(msg)
   644                 self.GetCTRoot().logger.write_error(msg)
   645                 self.GetCTRoot().logger.write_error(traceback.format_exc())
   645                 self.GetCTRoot().logger.write_error(traceback.format_exc())
   646         
   646 
   647     def LoadChildren(self):
   647     def LoadChildren(self):
   648         # Iterate over all CTNName@CTNType in confnode directory, and try to open them
   648         # Iterate over all CTNName@CTNType in confnode directory, and try to open them
   649         for CTNDir in os.listdir(self.CTNPath()):
   649         for CTNDir in os.listdir(self.CTNPath()):
   650             if os.path.isdir(os.path.join(self.CTNPath(), CTNDir)) and \
   650             if os.path.isdir(os.path.join(self.CTNPath(), CTNDir)) and \
   651                CTNDir.count(NameTypeSeparator) == 1:
   651                CTNDir.count(NameTypeSeparator) == 1:
   654                     self.CTNAddChild(pname, ptype)
   654                     self.CTNAddChild(pname, ptype)
   655                 except Exception, exc:
   655                 except Exception, exc:
   656                     msg = _("Could not add child \"{a1}\", type {a2} :\n{a3}\n").format(a1 = pname, a2 = ptype, a3 = unicode(exc))
   656                     msg = _("Could not add child \"{a1}\", type {a2} :\n{a3}\n").format(a1 = pname, a2 = ptype, a3 = unicode(exc))
   657                     self.GetCTRoot().logger.write_error(msg)
   657                     self.GetCTRoot().logger.write_error(msg)
   658                     self.GetCTRoot().logger.write_error(traceback.format_exc())
   658                     self.GetCTRoot().logger.write_error(traceback.format_exc())
   659