Modify the timout of the validation process and the result rapresentation
[bertos.git] / wizard / BToolchainPage.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
5 # All rights reserved.
6 #
7 # $Id:$
8 #
9 # Author: Lorenzo Berni <duplo@develer.com>
10 #
11
12 import os
13
14 from BWizardPage import *
15 import BToolchainSearch
16 import bertos_utils
17
18 class BToolchainPage(BWizardPage):
19     
20     def __init__(self):
21         BWizardPage.__init__(self, "toolchain_select.ui")
22         self.setTitle(self.tr("Select toolchain"))
23         self._validationProcess = None
24         self._populateToolchainList()
25         self._connectSignals()
26     
27     def _updateUi(self):
28         if self.pageContent.customDirBox.isChecked():
29             self._enableCustomDir()
30         else:
31             self._disableCustomDir()
32         if self.pageContent.pathBox.isChecked() or (self.pageContent.customDirBox.isChecked() and self.pageContent.customDirList.count() != 0):
33             self.pageContent.doSearchButton.setEnabled(True)
34         else:
35             self.pageContent.doSearchButton.setEnabled(False)
36     
37     def _populateToolchainList(self):
38         toolchains = self._settingsRetrieve("toolchains").toList()
39         for element in toolchains:
40             item = QListWidgetItem(element.toString())
41             item.setData(Qt.UserRole, element)
42             self.pageContent.toolchainList.addItem(item)
43             
44     def _clearList(self):
45         self.pageContent.toolchainList.clear()
46     
47     def _selectionChanged(self):
48         self.emit(SIGNAL("completeChanged()"))
49     
50     def _search(self):
51         dirList = [unicode(element.toString()) for element in self._settingsRetrieve("search_dir_list").toList()]
52         if(self._settingsRetrieve("path_search").toBool()):
53             dirList += [element for element in bertos_utils.getSystemPath()]
54         toolchainList = bertos_utils.findToolchains(dirList)
55         storedToolchainList = self._settingsRetrieve("toolchains").toList()
56         storedToolchainList = set([unicode(toolchain.toString()) for toolchain in storedToolchainList])
57         toolchainList =set(toolchainList) - set(storedToolchainList)
58         for element in toolchainList:
59             item = QListWidgetItem(element)
60             item.setData(Qt.UserRole, QVariant(element))
61             self.pageContent.toolchainList.addItem(item)
62         self._settingsStore("toolchains", list(toolchainList.union(storedToolchainList)))
63         
64     def _connectSignals(self):
65         self.connect(self.pageContent.toolchainList, SIGNAL("itemSelectionChanged()"), self._selectionChanged)
66         self.connect(self.pageContent.addButton, SIGNAL("clicked()"), self.addToolchain)
67         self.connect(self.pageContent.removeButton, SIGNAL("clicked()"), self.removeToolchain)
68         self.connect(self.pageContent.searchButton, SIGNAL("clicked()"), self.searchToolchain)
69         self.connect(self.pageContent.checkButton, SIGNAL("clicked()"), self.validateToolchains)
70     
71     def _validItem(self, index, infos):
72         item = self.pageContent.toolchainList.item(index)
73         needed = self._projectInfoRetrieve("CPU_INFOS")
74         if infos["target"].find(unicode(needed[QString("TOOLCHAIN")].toString())) != -1:
75             item.setIcon(QIcon(":/images/ok.png"))
76         else:
77             item.setIcon(QIcon(":/images/warning.png"))
78         item.setText(infos["version"] + " " + infos["target"])
79     
80     def _invalidItem(self, index):
81         item = self.pageContent.toolchainList.item(index)
82         item.setIcon(QIcon(":/images/error.png"))
83     
84     def addToolchain(self):
85         sel_toolchain = QFileDialog.getOpenFileName(self, self.tr("Choose the toolchain"), "")
86         if not sel_toolchain.isEmpty():
87             item = QListWidgetItem(sel_toolchain)
88             item.setData(Qt.UserRole, QVariant(sel_toolchain))
89             self.pageContent.toolchainList.addItem(item)
90             toolchains = self._settingsRetrieve("toolchains").toList()
91             toolchains = set([toolchain.toString() for toolchain in toolchains] + [sel_toolchain])
92             self._settingsStore("toolchains", list(toolchains))
93     
94     def removeToolchain(self):
95         if self.pageContent.toolchainList.currentRow() != -1:
96             item = self.pageContent.toolchainList.takeItem(self.pageContent.toolchainList.currentRow())
97             item = item.data(Qt.UserRole).toString()
98             toolchains = self._settingsRetrieve("toolchains").toList()
99             toolchains = [unicode(toolchain.toString()) for toolchain in toolchains]
100             toolchains.remove(unicode(item))
101             self._settingsStore("toolchains", toolchains)
102     
103     def searchToolchain(self):
104         search = BToolchainSearch.BToolchainSearch()
105         self.connect(search, SIGNAL("accepted()"), self._search)
106         search.exec_()
107     
108     def validateToolchains(self):
109         for i in range(self.pageContent.toolchainList.count()):
110             filename = unicode(self.pageContent.toolchainList.item(i).data(Qt.UserRole).toString())
111             self._validationProcess = QProcess()
112             self._validationProcess.start(filename, ["-v"])
113             self._validationProcess.waitForStarted(1000)
114             if self._validationProcess.waitForFinished(200):
115                 description = str(self._validationProcess.readAllStandardError())
116                 infos = bertos_utils.getToolchainInfo(description)
117                 if len(infos.keys()) == 4:
118                     self._validItem(i, infos)
119                 else:
120                     self._invalidItem(i)
121             else:
122                 self._validationProcess.kill()
123                 self._invalidItem(i)
124     
125     def isComplete(self):
126         if self.pageContent.toolchainList.currentRow() != -1:
127             self._projectInfoStore("TOOLCHAIN", self.pageContent.toolchainList.item(self.pageContent.toolchainList.currentRow()).data(Qt.UserRole).toString())
128             return True
129         else:
130             return False