Creating a new project from a preset the Wizard copy also the files contained into...
authorduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Fri, 23 Apr 2010 10:14:07 +0000 (10:14 +0000)
committerduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Fri, 23 Apr 2010 10:14:07 +0000 (10:14 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3503 38d2e660-2303-0410-9eaa-f027e97ec537

wizard/BProject.py

index 7d80236f82e54770a1e6742e96854e9bc59cf8b3..b5617ee2132c553c08121357b747f6d03369c969 100644 (file)
@@ -160,6 +160,8 @@ class BProject(object):
         self.setEnabledModules(project_data["ENABLED_MODULES"])
         self.infos["PROJECT_NAME"] = old_project_name
         self.infos["PROJECT_PATH"] = old_project_path        
+        self.infos["PRESET_NAME"] = project_data.get("PROJECT_NAME", os.path.basename(preset))
+        self.infos["PRESET_PATH"] = preset
 
     def loadProjectPresets(self):
         """
@@ -310,14 +312,10 @@ class BProject(object):
     def _newBertosProjectFromPreset(self):
         # Create/write/copy the common things
         self._newBertosProject()
-        
-        # Copy the sources files
-        # TODO: implement it!
-        
-        # Copy the user mk predefined file
-        # TODO: implement it!
-        
-        # Copy the main.c file (if the user doesn't check the empty main checkbox)
+
+        # Copy all the files and dirs except cfg/hw/*_wiz.mk
+        self._writeCustomSrcFiles()
+        # Override the main.c with the empty one if requested by the user
         # TODO: implement it!
         
         # Create project files for selected plugins
@@ -405,6 +403,19 @@ class BProject(object):
             f.write(string)
             f.close()
 
+    def _writeCustomSrcFiles(self):
+        preset = self.infos["PRESET_PATH"]
+        preset_name = self.infos["PRESET_NAME"]
+        origin = os.path.join(preset, preset_name)
+        project_related_stuff = ("cfg", "hw", self.infos["PROJECT_NAME"] + "_wiz.mk") + const.IGNORE_LIST
+        for element in os.listdir(origin):
+            if element not in project_related_stuff:
+                element = os.path.join(origin, element)
+                if os.path.isdir(element):
+                    copytree.copytree(element, self.prjdir, ignore_list=const.IGNORE_LIST)
+                else:
+                    shutil.copy(element, self.prjdir)        
+
     def _setupAutoenabledParameters(self):
         for module, information in self.infos["MODULES"].items():
             if "configuration" in information and information["configuration"] != "":