ConfigTreeNode.py
changeset 1868 616c3f4bcbcb
parent 1850 614396cbffbf
child 1881 091005ec69c4
equal deleted inserted replaced
1867:418777c1fbc7 1868:616c3f4bcbcb
   545             """
   545             """
   546             ConfNode class is derivated into FinalCTNClass before being instanciated
   546             ConfNode class is derivated into FinalCTNClass before being instanciated
   547             This way __init__ is overloaded to ensure ConfigTreeNode.__init__ is called
   547             This way __init__ is overloaded to ensure ConfigTreeNode.__init__ is called
   548             before CTNClass.__init__, and to do the file related stuff.
   548             before CTNClass.__init__, and to do the file related stuff.
   549             """
   549             """
   550             def __init__(_self):
   550             def __init__(self, parent):
   551                 # self is the parent
   551                 self.CTNParent = parent
   552                 _self.CTNParent = self
       
   553                 # Keep track of the confnode type name
   552                 # Keep track of the confnode type name
   554                 _self.CTNType = CTNType
   553                 self.CTNType = CTNType
   555                 # remind the help string, for more fancy display
   554                 # remind the help string, for more fancy display
   556                 _self.CTNHelp = CTNHelp
   555                 self.CTNHelp = CTNHelp
   557                 # Call the base confnode template init - change XSD into class members
   556                 # Call the base confnode template init - change XSD into class members
   558                 ConfigTreeNode.__init__(_self)
   557                 ConfigTreeNode.__init__(self)
   559                 # check name is unique
   558                 # check name is unique
   560                 NewCTNName = _self.FindNewName(CTNName)
   559                 NewCTNName = self.FindNewName(CTNName)
   561                 # If dir have already be made, and file exist
   560                 # If dir have already be made, and file exist
   562                 if os.path.isdir(_self.CTNPath(NewCTNName)):  # and os.path.isfile(_self.ConfNodeXmlFilePath(CTNName)):
   561                 if os.path.isdir(self.CTNPath(NewCTNName)):  # and os.path.isfile(self.ConfNodeXmlFilePath(CTNName)):
   563                     # Load the confnode.xml file into parameters members
   562                     # Load the confnode.xml file into parameters members
   564                     _self.LoadXMLParams(NewCTNName)
   563                     self.LoadXMLParams(NewCTNName)
   565                     # Basic check. Better to fail immediately.
   564                     # Basic check. Better to fail immediately.
   566                     if _self.BaseParams.getName() != NewCTNName:
   565                     if self.BaseParams.getName() != NewCTNName:
   567                         raise Exception(
   566                         raise Exception(
   568                             _("Project tree layout do not match confnode.xml {a1}!={a2} ").
   567                             _("Project tree layout do not match confnode.xml {a1}!={a2} ").
   569                             format(a1=NewCTNName, a2=_self.BaseParams.getName()))
   568                             format(a1=NewCTNName, a2=self.BaseParams.getName()))
   570 
   569 
   571                     # Now, self.CTNPath() should be OK
   570                     # Now, self.CTNPath() should be OK
   572 
   571 
   573                     # Check that IEC_Channel is not already in use.
   572                     # Check that IEC_Channel is not already in use.
   574                     _self.FindNewIEC_Channel(_self.BaseParams.getIEC_Channel())
   573                     self.FindNewIEC_Channel(self.BaseParams.getIEC_Channel())
   575                     # Call the confnode real __init__
   574                     # Call the confnode real __init__
   576                     if getattr(CTNClass, "__init__", None):
   575                     if getattr(CTNClass, "__init__", None):
   577                         CTNClass.__init__(_self)
   576                         CTNClass.__init__(self)
   578                     # Load and init all the children
   577                     # Load and init all the children
   579                     _self.LoadChildren()
   578                     self.LoadChildren()
   580                     # just loaded, nothing to saved
   579                     # just loaded, nothing to saved
   581                     _self.ChangesToSave = False
   580                     self.ChangesToSave = False
   582                 else:
   581                 else:
   583                     # If confnode do not have corresponding file/dirs - they will be created on Save
   582                     # If confnode do not have corresponding file/dirs - they will be created on Save
   584                     _self.CTNMakeDir()
   583                     self.CTNMakeDir()
   585                     # Find an IEC number
   584                     # Find an IEC number
   586                     _self.FindNewIEC_Channel(IEC_Channel)
   585                     self.FindNewIEC_Channel(IEC_Channel)
   587                     # Call the confnode real __init__
   586                     # Call the confnode real __init__
   588                     if getattr(CTNClass, "__init__", None):
   587                     if getattr(CTNClass, "__init__", None):
   589                         CTNClass.__init__(_self)
   588                         CTNClass.__init__(self)
   590                     _self.CTNRequestSave()
   589                     self.CTNRequestSave()
   591                     # just created, must be saved
   590                     # just created, must be saved
   592                     _self.ChangesToSave = True
   591                     self.ChangesToSave = True
   593 
   592 
   594             def _getBuildPath(_self):
   593             def _getBuildPath(self):
   595                 return self._getBuildPath()
   594                 return self.CTNParent._getBuildPath()
   596 
   595 
   597         # Create the object out of the resulting class
   596         # Create the object out of the resulting class
   598         newConfNodeOpj = FinalCTNClass()
   597         newConfNodeOpj = FinalCTNClass(self)
   599         # Store it in CTNgedChils
   598         # Store it in CTNgedChils
   600         ChildrenWithSameClass.append(newConfNodeOpj)
   599         ChildrenWithSameClass.append(newConfNodeOpj)
   601 
   600 
   602         return newConfNodeOpj
   601         return newConfNodeOpj
   603 
   602