4 # This file is part of BeRTOS.
6 # Bertos is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 # As a special exception, you may use this file as part of a free software
21 # library without restriction. Specifically, if other files instantiate
22 # templates or use macros or inline functions from this file, or you compile
23 # this file and link it with other files to produce an executable, this
24 # file does not by itself cause the resulting executable to be covered by
25 # the GNU General Public License. This exception does not however
26 # invalidate any other reasons why the executable file might be covered by
27 # the GNU General Public License.
29 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
32 # Author: Lorenzo Berni <duplo@develer.com>
37 from PyQt4.QtCore import *
38 from PyQt4.QtGui import *
40 import qvariant_converter
41 from toolchain_validation import validateToolchain
44 class ToolchainManager(object):
46 self._app_settings = QApplication.instance().settings
48 def validateToolchain(self, toolchain):
49 toolchains = self.storedToolchainDict()
50 if toolchain in toolchains:
51 toolchains[toolchain] = True
52 self.setStoredToolchainDict(toolchains)
53 return self._validateToolchain(toolchain)
54 elif toolchain in self._predefined_toolchain_set:
55 return self._validateToolchain(toolchain)
59 def _validateToolchain(self, toolchain):
61 Returns information about the toolchain located in path
62 "toolchain". If the toolchain is not recognized, or it doesn't
63 exists anymore a empty dict is returned.
65 Example of toolchain information dict:
74 return validateToolchain(toolchain)
76 def addToolchain(self, toolchain, validated=False):
77 if toolchain not in self.predefined_toolchains:
78 toolchains = self.storedToolchainDict()
79 toolchains[toolchain] = validated
80 self.setStoredToolchainDict(toolchains)
82 def removeToolchain(self, toolchain):
83 toolchains = self.storedToolchainDict()
84 if toolchain in toolchains:
85 del toolchains[toolchain]
86 self.setStoredToolchainDict(toolchains)
88 def storedToolchainDict(self):
89 toolchains = self._app_settings.value("toolchains", QVariant())
90 toolchains = qvariant_converter.getBoolDict(toolchains)
93 def setStoredToolchainDict(self, toolchain_dict):
94 toolchains = qvariant_converter.convertBoolDict(toolchain_dict)
95 self._app_settings.setValue("toolchains", toolchains)
100 toolchain_dict = self.storedToolchainDict()
101 for toolchain, validated in toolchain_dict.items():
103 information = self._validateToolchain(toolchain)
106 toolchains.append((toolchain, information))
110 def predefined_toolchains(self):
112 stored_toolchains = self._predefined_toolchain_set
113 for toolchain in stored_toolchains:
114 toolchains.append((toolchain, self._validateToolchain(toolchain)))
118 def _predefined_toolchain_set(self):
119 stored_toolchains = set()
121 import winreg_importer
122 stored_toolchains |= set(winreg_importer.getBertosToolchains())
123 return stored_toolchains
125 def suitableToolchains(self, target):
126 toolchains = self.toolchains
127 suitable_toolchains = []
128 for name, info in toolchains:
129 t = info.get("target", None)
130 if t and t.find(target) != -1:
131 suitable_toolchains.append(name)
132 return suitable_toolchains