ConfigTreeNode.py
branch1.1 Korean release
changeset 1280 72a826dfcfbb
parent 1179 3e7bd88fcff7
child 1315 ff14a66bbd12
equal deleted inserted replaced
977:c8e008b8cefe 1280:72a826dfcfbb
    71         return os.path.join(self.CTNPath(CTNName), "confnode.xml")
    71         return os.path.join(self.CTNPath(CTNName), "confnode.xml")
    72 
    72 
    73     def ConfNodePath(self):
    73     def ConfNodePath(self):
    74         return os.path.join(self.CTNParent.ConfNodePath(), self.CTNType)
    74         return os.path.join(self.CTNParent.ConfNodePath(), self.CTNType)
    75 
    75 
    76     def CTNPath(self,CTNName=None):
    76     def CTNPath(self,CTNName=None,project_path=None):
    77         if not CTNName:
    77         if not CTNName:
    78             CTNName = self.CTNName()
    78             CTNName = self.CTNName()
    79         return os.path.join(self.CTNParent.CTNPath(),
    79         if not project_path:
       
    80             project_path = self.CTNParent.CTNPath()
       
    81         return os.path.join(project_path,
    80                             CTNName + NameTypeSeparator + self.CTNType)
    82                             CTNName + NameTypeSeparator + self.CTNType)
    81     
    83     
    82     def CTNName(self):
    84     def CTNName(self):
    83         return self.BaseParams.getName()
    85         return self.BaseParams.getName()
    84     
    86     
   111         return False
   113         return False
   112     
   114     
   113     def RemoteExec(self, script, **kwargs):
   115     def RemoteExec(self, script, **kwargs):
   114         return self.CTNParent.RemoteExec(script, **kwargs)
   116         return self.CTNParent.RemoteExec(script, **kwargs)
   115     
   117     
   116     def OnCTNSave(self):
   118     def OnCTNSave(self, from_project_path=None):
   117         #Default, do nothing and return success
   119         #Default, do nothing and return success
   118         return True
   120         return True
   119 
   121 
   120     def GetParamsAttributes(self, path = None):
   122     def GetParamsAttributes(self, path = None):
   121         if path:
   123         if path:
   146             return res, True
   148             return res, True
   147         
   149         
   148         parts = path.split(".", 1)
   150         parts = path.split(".", 1)
   149         if self.MandatoryParams and parts[0] == self.MandatoryParams[0]:
   151         if self.MandatoryParams and parts[0] == self.MandatoryParams[0]:
   150             self.MandatoryParams[1].setElementValue(parts[1], value)
   152             self.MandatoryParams[1].setElementValue(parts[1], value)
       
   153             value = self.MandatoryParams[1].getElementInfos(parts[0], parts[1])["value"]
   151         elif self.CTNParams and parts[0] == self.CTNParams[0]:
   154         elif self.CTNParams and parts[0] == self.CTNParams[0]:
   152             self.CTNParams[1].setElementValue(parts[1], value)
   155             self.CTNParams[1].setElementValue(parts[1], value)
       
   156             value = self.CTNParams[1].getElementInfos(parts[0], parts[1])["value"]
   153         return value, False
   157         return value, False
   154 
   158 
   155     def CTNMakeDir(self):
   159     def CTNMakeDir(self):
   156         os.mkdir(self.CTNPath())
   160         os.mkdir(self.CTNPath())
   157 
   161 
   158     def CTNRequestSave(self):
   162     def CTNRequestSave(self, from_project_path=None):
   159         if self.GetCTRoot().CheckProjectPathPerm(False):
   163         if self.GetCTRoot().CheckProjectPathPerm(False):
   160             # If confnode do not have corresponding directory
   164             # If confnode do not have corresponding directory
   161             ctnpath = self.CTNPath()
   165             ctnpath = self.CTNPath()
   162             if not os.path.isdir(ctnpath):
   166             if not os.path.isdir(ctnpath):
   163                 # Create it
   167                 # Create it
   176                 XMLFile.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
   180                 XMLFile.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
   177                 XMLFile.write(self.CTNParams[1].generateXMLText(self.CTNParams[0], 0).encode("utf-8"))
   181                 XMLFile.write(self.CTNParams[1].generateXMLText(self.CTNParams[0], 0).encode("utf-8"))
   178                 XMLFile.close()
   182                 XMLFile.close()
   179             
   183             
   180             # Call the confnode specific OnCTNSave method
   184             # Call the confnode specific OnCTNSave method
   181             result = self.OnCTNSave()
   185             result = self.OnCTNSave(from_project_path)
   182             if not result:
   186             if not result:
   183                 return _("Error while saving \"%s\"\n")%self.CTNPath()
   187                 return _("Error while saving \"%s\"\n")%self.CTNPath()
   184     
   188     
   185             # mark confnode as saved
   189             # mark confnode as saved
   186             self.ChangesToSave = False
   190             self.ChangesToSave = False
   187             # go through all children and do the same
   191             # go through all children and do the same
   188             for CTNChild in self.IterChildren():
   192             for CTNChild in self.IterChildren():
   189                 result = CTNChild.CTNRequestSave()
   193                 CTNChildPath = None
       
   194                 if from_project_path is not None:
       
   195                     CTNChildPath = CTNChild.CTNPath(project_path=from_project_path)
       
   196                 result = CTNChild.CTNRequestSave(CTNChildPath)
   190                 if result:
   197                 if result:
   191                     return result
   198                     return result
   192         return None
   199         return None
   193     
   200     
   194     def CTNImport(self, src_CTNPath):
   201     def CTNImport(self, src_CTNPath):
   463         CTNInstance.OnCTNClose()
   470         CTNInstance.OnCTNClose()
   464         # Delete confnode dir
   471         # Delete confnode dir
   465         shutil.rmtree(CTNInstance.CTNPath())
   472         shutil.rmtree(CTNInstance.CTNPath())
   466         # Remove child of Children
   473         # Remove child of Children
   467         self.Children[CTNInstance.CTNType].remove(CTNInstance)
   474         self.Children[CTNInstance.CTNType].remove(CTNInstance)
       
   475         if len(self.Children[CTNInstance.CTNType]) == 0:
       
   476             self.Children.pop(CTNInstance.CTNType)
   468         # Forget it... (View have to refresh)
   477         # Forget it... (View have to refresh)
   469 
   478 
   470     def CTNRemove(self):
   479     def CTNRemove(self):
   471         # Fetch the confnode
   480         # Fetch the confnode
   472         #CTNInstance = self.GetChildByName(CTNName)
   481         #CTNInstance = self.GetChildByName(CTNName)