Add preset load functionality.
authorduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 19 Apr 2010 15:03:44 +0000 (15:03 +0000)
committerduplo <duplo@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 19 Apr 2010 15:03:44 +0000 (15:03 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3462 38d2e660-2303-0410-9eaa-f027e97ec537

wizard/BBoardPage.py
wizard/BProject.py
wizard/const.py

index 21363e7a0b3738fabfa26410fe77ed05b9037cff..2bf90ff38843d975dc3263722b01a9387ba9dc52 100644 (file)
@@ -91,7 +91,7 @@ class BBoardPage(BWizardPage):
         """
         Overload of the BWizardPage reloadData method.
         """
-        self.project.loadProjectPresets()
+        self._fillPresetTree()
 
     ####
 
@@ -100,3 +100,15 @@ class BBoardPage(BWizardPage):
 
     ####
 
+    def _fillPresetTree(self):
+        self.project.loadProjectPresets()
+        preset_tree = self.project.info("PRESET_TREE")
+        for obj in preset_tree['children']:
+            self._createPresetNode(self.pageContent.boardTree, obj)
+
+    def _createPresetNode(self, parent, obj):
+        item_name = obj['info'].get('name', obj['info']['filename'])
+        item = QTreeWidgetItem(parent, [item_name]) 
+        children_dict = obj['children']
+        for child in children_dict:
+            self._createPresetNode(item, child)
index 7cc1da496432688f9cb5d44ac3c26cd039203667..81f2de6cd71fb60c5d93c0630ee6699d660c4ab7 100644 (file)
@@ -122,6 +122,29 @@ class BProject(object):
         """
         # NOTE: this method does nothing (for now).
         preset_path = os.path.join(self.infos["SOURCES_PATH"], const.PREDEFINED_BOARDS_DIR)
+        preset_tree = {}
+        if os.path.exists(preset_path):
+            preset_tree = self._loadProjectPresetTree(preset_path)
+        self.infos["PRESET_TREE"] = preset_tree
+
+    def _loadProjectPresetTree(self, path):
+        _tree = {}
+        _tree['info'] = self._loadPresetInfo(os.path.join(path, const.PREDEFINED_BOARD_SPEC_FILE))
+        _tree['info']['filename'] = os.path.basename(path)
+        _tree['children'] = []
+        entries = set(os.listdir(path))
+        for entry in entries:
+            _path = os.path.join(path, entry)
+            if os.path.isdir(_path):
+                sub_entries = set(os.listdir(_path))
+                if const.PREDEFINED_BOARD_SPEC_FILE in sub_entries:
+                    _tree['children'].append(self._loadProjectPresetTree(_path))
+        return _tree
+
+    def _loadPresetInfo(self, preset_spec_file):
+        D = {}
+        execfile(preset_spec_file, {}, D)
+        return D
 
     def loadModuleData(self, edit=False):
         module_info_dict = {}
index 3b6add0de74d5c77592669bc6e55c27a4d5911bf..1bd69e8fc242fd32876532da0cf89e98930dcd7e 100644 (file)
@@ -42,6 +42,11 @@ DATA_DIR = os.path.dirname(os.path.abspath(_tmp))
 del _tmp
 
 PREDEFINED_BOARDS_DIR = 'predefined_boards'
+PREDEFINED_BOARD_SPEC_FILE = '.spec'
+# PREDEFINED_BOARD_SPEC_INFO = {
+#    'name': <name of the board/directory>,
+#    'description': <description of the board/directory>,
+# }
 
 CPU_DEF = {
     "CPU_NAME": "",