From: duplo Date: Mon, 19 Apr 2010 15:03:44 +0000 (+0000) Subject: Add preset load functionality. X-Git-Tag: 2.5.0~446 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=1b91fae6ef2c8d756d1f3a1ab812ddb92e650c01;p=bertos.git Add preset load functionality. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3462 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/wizard/BBoardPage.py b/wizard/BBoardPage.py index 21363e7a..2bf90ff3 100644 --- a/wizard/BBoardPage.py +++ b/wizard/BBoardPage.py @@ -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) diff --git a/wizard/BProject.py b/wizard/BProject.py index 7cc1da49..81f2de6c 100644 --- a/wizard/BProject.py +++ b/wizard/BProject.py @@ -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 = {} diff --git a/wizard/const.py b/wizard/const.py index 3b6add0d..1bd69e8f 100644 --- a/wizard/const.py +++ b/wizard/const.py @@ -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': , +# 'description': , +# } CPU_DEF = { "CPU_NAME": "",