- QApplication.instance().setOverrideCursor(Qt.WaitCursor)
- for i in range(self.pageContent.toolchainList.count()):
- self.validateToolchain(i)
- QApplication.instance().restoreOverrideCursor()
-
- def validateToolchain(self, i):
- filename = qvariant_converter.getStringDict(self.pageContent.toolchainList.item(i).data(Qt.UserRole))["path"]
- valid = False
- info = {}
- ## Check for the other tools of the toolchain
- for tool in TOOLCHAIN_ITEMS:
- if os.path.exists(filename.replace("gcc", tool)):
- valid = True
- else:
- valid = False
- break
- ## Try to retrieve the informations about the toolchain only for the valid toolchains
- if valid:
- self._validation_process = QProcess()
- self._validation_process.start(filename, ["-v"])
- self._validation_process.waitForStarted(1000)
- if self._validation_process.waitForFinished(200):
- description = str(self._validation_process.readAllStandardError())
- info = bertos_utils.getToolchainInfo(description)
- if len(info.keys()) >= 4:
- valid = True
+ """
+ Slot called when the user clicks on the validate button. It starts the
+ toolchain validation procedure for all the toolchains.
+ """
+ try:
+ QApplication.instance().setOverrideCursor(Qt.WaitCursor)
+ for i in range(self.pageContent.toolchainList.count()):
+ data = qvariant_converter.getStringDict(self.pageContent.toolchainList.item(i).data(Qt.UserRole))
+ self.validateToolchain(data["path"])
+ self._populateToolchainList()
+ finally:
+ QApplication.instance().restoreOverrideCursor()
+
+ ####
+
+ def _populateToolchainList(self):
+ """
+ Fills the toolchain list with the toolchains stored in the QSettings.
+ """
+ self.pageContent.toolchainList.clear()
+ self._valid_items = []
+ toolchains = self._toolchain_manager.predefined_toolchains + self._toolchain_manager.toolchains
+ toolchain_dict = {
+ 'valid': [],
+ 'non-valid': [],
+ 'unknown': [],
+ 'unverified': [],
+ }
+ for key, value in toolchains:
+ if os.path.exists(key):
+ item_data = {"path":key}
+ if value:
+ item_data.update(value)
+ if value is not None:
+ k, data = self.validateToolchain(key)
+ item_data.update(data)
+ toolchain_dict[k].append(item_data)
+ else:
+ toolchain_dict["unverified"].append(item_data)
+ self._processItems(toolchain_dict["valid"], self._validItem)
+ self._processItems(toolchain_dict["non-valid"], self._invalidItem)
+ self._processItems(toolchain_dict["unknown"], self._unknownItem)
+ self._processItems(toolchain_dict["unverified"])
+
+ def _processItems(self, item_list, procedure=lambda x: None):
+ sel_toolchain = self.projectInfo("TOOLCHAIN")
+ for item_data in item_list:
+ item = QListWidgetItem(item_data["path"])
+ item.setData(Qt.UserRole, qvariant_converter.convertStringDict(item_data))
+ self.pageContent.toolchainList.addItem(item)
+ procedure(item)
+ if sel_toolchain and sel_toolchain["path"] == item_data["path"]:
+ self.pageContent.toolchainList.setCurrentItem(item)
+
+ def currentToolchain(self):
+ selected_toolchain = qvariant_converter.getStringDict(self.pageContent.toolchainList.currentItem().data(Qt.UserRole))
+ return selected_toolchain
+
+ def _clearList(self):
+ """
+ Removes all the toolchain from the list.
+ """
+ self.pageContent.toolchainList.clear()
+
+ def _search(self):
+ """
+ Searches for toolchains in the stored directories, and stores them in the
+ QSettings.
+ """
+ dir_list = self.searchDirList()
+ if self.pathSearch():
+ dir_list += [element for element in bertos_utils.getSystemPath()]
+ _toolchain_dict = self._toolchain_manager.storedToolchainDict()
+ toolchain_list = bertos_utils.findToolchains(dir_list)
+ for toolchain in toolchain_list:
+ self._toolchain_manager.addToolchain(toolchain, _toolchain_dict.get(toolchain, False))
+ self._populateToolchainList()
+ self.showMessage(self.tr("Toolchain search result."), self.tr("%1 toolchains found").arg(len(toolchain_list)))
+
+ def _validItem(self, item):
+ """
+ Sets the item at index as a valid item and associates the given info to it.
+ """
+ data = qvariant_converter.getStringDict(item.data(Qt.UserRole))
+ item.setIcon(QIcon(":/images/ok.png"))
+ self._valid_items.append(item)
+ if "version" in data and "target" in data:
+ item.setText("GCC " + data["version"] + " - " + data["target"].strip())
+
+ def _invalidItem(self, item):
+ data = qvariant_converter.getStringDict(item.data(Qt.UserRole))
+ item.setIcon(QIcon(":/images/warning.png"))
+ if "version" in data and "target" in data:
+ item.setText("GCC " + data["version"] + " - " + data["target"].strip())
+
+ def _unknownItem(self, item):
+ """
+ Sets the item at index as an invalid item.
+ """
+ item.setIcon(QIcon(":/images/error.png"))
+
+ def validateToolchain(self, filename):
+ """
+ Toolchain validation procedure.
+ """
+ info = self._toolchain_manager.validateToolchain(filename)
+ if info:
+ needed = self.projectInfo("CPU_INFOS")
+ if "target" in info and info["target"].find(needed["TOOLCHAIN"]) != -1:
+ return 'valid', info