LPCBeremiz.py
changeset 478 029688dad14d
parent 472 80eb3bde98e3
child 487 1df4a28d3586
equal deleted inserted replaced
477:f66a092b6e74 478:029688dad14d
   352             elif os.path.isfile(srcpath):
   352             elif os.path.isfile(srcpath):
   353                 shutil.copy2(srcpath, dstpath)
   353                 shutil.copy2(srcpath, dstpath)
   354 
   354 
   355 class LPCPluginsRoot(PluginsRoot):
   355 class LPCPluginsRoot(PluginsRoot):
   356 
   356 
   357     PlugChildsTypes = [("LPCBus", LPCBus, "LPC bus")]
       
   358 
       
   359     PluginMethods = [
   357     PluginMethods = [
   360         {"bitmap" : opjimg("Build"),
   358         {"bitmap" : opjimg("Build"),
   361          "name" : _("Build"),
   359          "name" : _("Build"),
   362          "tooltip" : _("Build project into build folder"),
   360          "tooltip" : _("Build project into build folder"),
   363          "method" : "_build"},
   361          "method" : "_build"},
   364         {"bitmap" : opjimg("Clean"),
       
   365          "name" : _("Clean"),
       
   366          "enabled" : False,
       
   367          "tooltip" : _("Clean project build folder"),
       
   368          "method" : "_Clean"},
       
   369     ]
   362     ]
       
   363 
       
   364     def __init__(self, frame, logger):
       
   365         PluginsRoot.__init__(self, frame, logger)
       
   366         self.PlugChildsTypes += [("LPCBus", LPCBus, "LPC bus")]
   370 
   367 
   371     def GetProjectName(self):
   368     def GetProjectName(self):
   372         return self.Project.getname()
   369         return self.Project.getname()
   373 
   370 
   374     def GetDefaultTarget(self):
   371     def GetDefaultTarget(self):
   375         target = self.Classes["BeremizRoot_TargetType"]()
   372         target = self.Classes["BeremizRoot_TargetType"]()
   376         target_value = self.Classes["TargetType_Makefile"]()
   373         target_value = self.Classes["TargetType_LPC"]()
   377         target_value.setBuildPath(self.BuildPath)
   374         target_value.setBuildPath(self.BuildPath)
   378         target.setcontent({"name": "Makefile", "value": target_value})
   375         target.setcontent({"name": "Makefile", "value": target_value})
   379         return target
   376         return target
   380      
   377      
   381     def SetProjectName(self, name):
   378     def SetProjectName(self, name):
   394         self.Project.removeVariableByFilter(leading)
   391         self.Project.removeVariableByFilter(leading)
   395         self.BufferProject()
   392         self.BufferProject()
   396 
   393 
   397     def LoadProject(self, ProjectPath, BuildPath=None):
   394     def LoadProject(self, ProjectPath, BuildPath=None):
   398         """
   395         """
   399         Load a project XML file
   396         Load a project contained in a folder
   400         @param ProjectPath: path of the project xml file
   397         @param ProjectPath: path of the project folder
   401         """
   398         """
       
   399         if os.path.basename(ProjectPath) == "":
       
   400             ProjectPath = os.path.dirname(ProjectPath)
       
   401         # Verify that project contains a PLCOpen program
       
   402         plc_file = os.path.join(ProjectPath, "plc.xml")
       
   403         if not os.path.isfile(plc_file):
       
   404             return _("Chosen folder doesn't contain a program. It's not a valid project!")
   402         # Load PLCOpen file
   405         # Load PLCOpen file
   403         result = self.OpenXMLFile(ProjectPath)
   406         result = self.OpenXMLFile(plc_file)
   404         if result:
   407         if result:
   405             return result
   408             return result
   406         # Change XSD into class members
   409         # Change XSD into class members
   407         self._AddParamsMembers()
   410         self._AddParamsMembers()
   408         self.PluggedChilds = {}
   411         self.PluggedChilds = {}
   409         # Keep track of the root plugin (i.e. project path)
   412         # Keep track of the root plugin (i.e. project path)
   410         self.ProjectPath = ProjectPath
   413         self.ProjectPath = ProjectPath
   411 
   414         self.BuildPath = self._getBuildPath()
   412         self.BuildPath = tempfile.mkdtemp()
       
   413         if BuildPath is not None:
   415         if BuildPath is not None:
   414             mycopytree(BuildPath, self.BuildPath)
   416             mycopytree(BuildPath, self.BuildPath)
   415         
   417         
       
   418         # If dir have already be made, and file exist
       
   419         if os.path.isdir(self.PlugPath()) and os.path.isfile(self.PluginXmlFilePath()):
       
   420             #Load the plugin.xml file into parameters members
       
   421             result = self.LoadXMLParams()
       
   422             if result:
       
   423                 return result
       
   424             #Load and init all the childs
       
   425             self.LoadChilds()
   416         self.RefreshPluginsBlockLists()
   426         self.RefreshPluginsBlockLists()
   417         
   427 
   418         if os.path.exists(self._getBuildPath()):
   428         return None
   419             self.EnableMethod("_Clean", True)
       
   420         
   429         
   421     def SaveProject(self):
   430     def SaveProject(self):
   422         self.SaveXMLFile(self.ProjectPath)
   431         self.SaveXMLFile(self.ProjectPath)
   423 
   432 
   424 #-------------------------------------------------------------------------------
   433 #-------------------------------------------------------------------------------
   724         RefreshTimer = None
   733         RefreshTimer = None
   725         
   734         
   726         def __init__(self, projectOpen, buildpath):
   735         def __init__(self, projectOpen, buildpath):
   727             cmd.Cmd.__init__(self)
   736             cmd.Cmd.__init__(self)
   728             self.PluginRoot = LPCPluginsRoot(None, self.Log)
   737             self.PluginRoot = LPCPluginsRoot(None, self.Log)
   729             if projectOpen is not None and os.path.isfile(projectOpen):
   738             if projectOpen is not None and os.path.isdir(projectOpen):
   730                 result = self.PluginRoot.LoadProject(projectOpen, buildpath)
   739                 result = self.PluginRoot.LoadProject(projectOpen, buildpath)
   731                 if result:
   740                 if result:
   732                     print "Error: Invalid project directory", result
   741                     print "Error: Invalid project directory", result
   733             else:
   742             else:
   734                 print "Error: No such file or directory"
   743                 print "Error: No such file or directory"