ConfigTreeNode.py
changeset 1765 ccf59c1f0b45
parent 1760 ed2e2afb9573
child 1767 c74815729afd
equal deleted inserted replaced
1764:d5df428640ff 1765:ccf59c1f0b45
   527         CTNChildrenTypes = dict(zip(transpose[0], zip(transpose[1], transpose[2])))
   527         CTNChildrenTypes = dict(zip(transpose[0], zip(transpose[1], transpose[2])))
   528         # Check that adding this confnode is allowed
   528         # Check that adding this confnode is allowed
   529         try:
   529         try:
   530             CTNClass, CTNHelp = CTNChildrenTypes[CTNType]
   530             CTNClass, CTNHelp = CTNChildrenTypes[CTNType]
   531         except KeyError:
   531         except KeyError:
   532             raise Exception, _("Cannot create child {a1} of type {a2} ").format(a1=CTNName, a2=CTNType)
   532             raise Exception(_("Cannot create child {a1} of type {a2} ").
       
   533                              format(a1=CTNName, a2=CTNType))
   533 
   534 
   534         # if CTNClass is a class factory, call it. (prevent unneeded imports)
   535         # if CTNClass is a class factory, call it. (prevent unneeded imports)
   535         if type(CTNClass) == types.FunctionType:
   536         if type(CTNClass) == types.FunctionType:
   536             CTNClass = CTNClass()
   537             CTNClass = CTNClass()
   537 
   538 
   538         # Eventualy Initialize child instance list for this class of confnode
   539         # Eventualy Initialize child instance list for this class of confnode
   539         ChildrenWithSameClass = self.Children.setdefault(CTNType, list())
   540         ChildrenWithSameClass = self.Children.setdefault(CTNType, list())
   540         # Check count
   541         # Check count
   541         if getattr(CTNClass, "CTNMaxCount", None) and len(ChildrenWithSameClass) >= CTNClass.CTNMaxCount:
   542         if getattr(CTNClass, "CTNMaxCount", None) and len(ChildrenWithSameClass) >= CTNClass.CTNMaxCount:
   542             msg = _("Max count ({a1}) reached for this confnode of type {a2} ").format(a1=CTNClass.CTNMaxCount, a2=CTNType)
   543             raise Exception(
   543             raise Exception, msg
   544                 _("Max count ({a1}) reached for this confnode of type {a2} ").
       
   545                 format(a1=CTNClass.CTNMaxCount, a2=CTNType))
   544 
   546 
   545         # create the final class, derived of provided confnode and template
   547         # create the final class, derived of provided confnode and template
   546         class FinalCTNClass(CTNClass, ConfigTreeNode):
   548         class FinalCTNClass(CTNClass, ConfigTreeNode):
   547             """
   549             """
   548             ConfNode class is derivated into FinalCTNClass before being instanciated
   550             ConfNode class is derivated into FinalCTNClass before being instanciated
   564                 if os.path.isdir(_self.CTNPath(NewCTNName)):  # and os.path.isfile(_self.ConfNodeXmlFilePath(CTNName)):
   566                 if os.path.isdir(_self.CTNPath(NewCTNName)):  # and os.path.isfile(_self.ConfNodeXmlFilePath(CTNName)):
   565                     # Load the confnode.xml file into parameters members
   567                     # Load the confnode.xml file into parameters members
   566                     _self.LoadXMLParams(NewCTNName)
   568                     _self.LoadXMLParams(NewCTNName)
   567                     # Basic check. Better to fail immediately.
   569                     # Basic check. Better to fail immediately.
   568                     if (_self.BaseParams.getName() != NewCTNName):
   570                     if (_self.BaseParams.getName() != NewCTNName):
   569                         msg = _("Project tree layout do not match confnode.xml {a1}!={a2} ").\
   571                         raise Exception(
   570                               format(a1=NewCTNName, a2=_self.BaseParams.getName())
   572                             _("Project tree layout do not match confnode.xml {a1}!={a2} ").
   571                         raise Exception, msg
   573                             format(a1=NewCTNName, a2=_self.BaseParams.getName()))
   572 
   574 
   573                     # Now, self.CTNPath() should be OK
   575                     # Now, self.CTNPath() should be OK
   574 
   576 
   575                     # Check that IEC_Channel is not already in use.
   577                     # Check that IEC_Channel is not already in use.
   576                     _self.FindNewIEC_Channel(_self.BaseParams.getIEC_Channel())
   578                     _self.FindNewIEC_Channel(_self.BaseParams.getIEC_Channel())