22 import Preferences |
22 import Preferences |
23 import UI.PixmapCache |
23 import UI.PixmapCache |
24 |
24 |
25 from eric5config import getConfig |
25 from eric5config import getConfig |
26 |
26 |
|
27 |
27 class TabnannyDialog(QDialog, Ui_TabnannyDialog): |
28 class TabnannyDialog(QDialog, Ui_TabnannyDialog): |
28 """ |
29 """ |
29 Class implementing a dialog to show the results of the tabnanny check run. |
30 Class implementing a dialog to show the results of the tabnanny check run. |
30 """ |
31 """ |
31 def __init__(self, parent = None): |
32 def __init__(self, parent=None): |
32 """ |
33 """ |
33 Constructor |
34 Constructor |
34 |
35 |
35 @param parent The parent widget (QWidget). |
36 @param parent The parent widget (QWidget). |
36 """ |
37 """ |
53 |
54 |
54 def __resort(self): |
55 def __resort(self): |
55 """ |
56 """ |
56 Private method to resort the tree. |
57 Private method to resort the tree. |
57 """ |
58 """ |
58 self.resultList.sortItems(self.resultList.sortColumn(), |
59 self.resultList.sortItems(self.resultList.sortColumn(), |
59 self.resultList.header().sortIndicatorOrder()) |
60 self.resultList.header().sortIndicatorOrder()) |
60 |
61 |
61 def __createResultItem(self, file, line, sourcecode): |
62 def __createResultItem(self, file, line, sourcecode): |
62 """ |
63 """ |
63 Private method to create an entry in the result list. |
64 Private method to create an entry in the result list. |
85 |
86 |
86 self.filterFrame.setVisible(True) |
87 self.filterFrame.setVisible(True) |
87 |
88 |
88 self.__data = self.__project.getData("CHECKERSPARMS", "Tabnanny") |
89 self.__data = self.__project.getData("CHECKERSPARMS", "Tabnanny") |
89 if self.__data is None or "ExcludeFiles" not in self.__data: |
90 if self.__data is None or "ExcludeFiles" not in self.__data: |
90 self.__data = {"ExcludeFiles" : ""} |
91 self.__data = {"ExcludeFiles": ""} |
91 self.excludeFilesEdit.setText(self.__data["ExcludeFiles"]) |
92 self.excludeFilesEdit.setText(self.__data["ExcludeFiles"]) |
92 |
93 |
93 def start(self, fn): |
94 def start(self, fn): |
94 """ |
95 """ |
95 Public slot to start the tabnanny check. |
96 Public slot to start the tabnanny check. |
139 source = Utilities.readEncodedFile(file)[0] |
140 source = Utilities.readEncodedFile(file)[0] |
140 # convert eols |
141 # convert eols |
141 source = Utilities.convertLineEnds(source, "\n") |
142 source = Utilities.convertLineEnds(source, "\n") |
142 except (UnicodeError, IOError) as msg: |
143 except (UnicodeError, IOError) as msg: |
143 self.noResults = False |
144 self.noResults = False |
144 self.__createResultItem(file, "1", |
145 self.__createResultItem(file, "1", |
145 "Error: {0}".format(str(msg)).rstrip()[1:-1]) |
146 "Error: {0}".format(str(msg)).rstrip()[1:-1]) |
146 progress += 1 |
147 progress += 1 |
147 continue |
148 continue |
148 |
149 |
149 flags = Utilities.extractFlags(source) |
150 flags = Utilities.extractFlags(source) |
150 ext = os.path.splitext(file)[1] |
151 ext = os.path.splitext(file)[1] |
151 if ("FileType" in flags and |
152 if ("FileType" in flags and |
152 flags["FileType"] in ["Python", "Python2"]) or \ |
153 flags["FileType"] in ["Python", "Python2"]) or \ |
153 file in py2files or \ |
154 file in py2files or \ |
154 (ext in [".py", ".pyw"] and \ |
155 (ext in [".py", ".pyw"] and \ |
155 Preferences.getProject("DeterminePyFromProject") and \ |
156 Preferences.getProject("DeterminePyFromProject") and \ |
156 self.__project.isOpen() and \ |
157 self.__project.isOpen() and \ |
208 filterString = self.excludeFilesEdit.text() |
209 filterString = self.excludeFilesEdit.text() |
209 if "ExcludeFiles" not in self.__data or \ |
210 if "ExcludeFiles" not in self.__data or \ |
210 filterString != self.__data["ExcludeFiles"]: |
211 filterString != self.__data["ExcludeFiles"]: |
211 self.__data["ExcludeFiles"] = filterString |
212 self.__data["ExcludeFiles"] = filterString |
212 self.__project.setData("CHECKERSPARMS", "Tabnanny", self.__data) |
213 self.__project.setData("CHECKERSPARMS", "Tabnanny", self.__data) |
213 filterList = [f.strip() for f in filterString.split(",") |
214 filterList = [f.strip() for f in filterString.split(",") |
214 if f.strip()] |
215 if f.strip()] |
215 if filterList: |
216 if filterList: |
216 for filter in filterList: |
217 for filter in filterList: |
217 fileList = \ |
218 fileList = \ |
218 [f for f in fileList if not fnmatch.fnmatch(f, filter)] |
219 [f for f in fileList if not fnmatch.fnmatch(f, filter)] |
222 self.cancelled = False |
223 self.cancelled = False |
223 self.start(fileList) |
224 self.start(fileList) |
224 |
225 |
225 def on_resultList_itemActivated(self, itm, col): |
226 def on_resultList_itemActivated(self, itm, col): |
226 """ |
227 """ |
227 Private slot to handle the activation of an item. |
228 Private slot to handle the activation of an item. |
228 |
229 |
229 @param itm reference to the activated item (QTreeWidgetItem) |
230 @param itm reference to the activated item (QTreeWidgetItem) |
230 @param col column the item was activated in (integer) |
231 @param col column the item was activated in (integer) |
231 """ |
232 """ |
232 if self.noResults: |
233 if self.noResults: |
251 (boolean, string, string, string). The values are only |
252 (boolean, string, string, string). The values are only |
252 valid, if the status is True. |
253 valid, if the status is True. |
253 """ |
254 """ |
254 interpreter = Preferences.getDebugger("PythonInterpreter") |
255 interpreter = Preferences.getDebugger("PythonInterpreter") |
255 if interpreter == "" or not Utilities.isExecutable(interpreter): |
256 if interpreter == "" or not Utilities.isExecutable(interpreter): |
256 return (True, filename, "1", |
257 return (True, filename, "1", |
257 self.trUtf8("Python2 interpreter not configured.")) |
258 self.trUtf8("Python2 interpreter not configured.")) |
258 |
259 |
259 checker = os.path.join(getConfig('ericDir'), |
260 checker = os.path.join(getConfig('ericDir'), |
260 "UtilitiesPython2", "TabnannyChecker.py") |
261 "UtilitiesPython2", "TabnannyChecker.py") |
261 |
262 |
262 proc = QProcess() |
263 proc = QProcess() |
263 proc.setProcessChannelMode(QProcess.MergedChannels) |
264 proc.setProcessChannelMode(QProcess.MergedChannels) |
264 proc.start(interpreter, [checker, filename]) |
265 proc.start(interpreter, [checker, filename]) |
265 finished = proc.waitForFinished(15000) |
266 finished = proc.waitForFinished(15000) |
266 if finished: |
267 if finished: |
267 output = \ |
268 output = \ |
268 str(proc.readAllStandardOutput(), |
269 str(proc.readAllStandardOutput(), |
269 Preferences.getSystem("IOEncoding"), |
270 Preferences.getSystem("IOEncoding"), |
270 'replace').splitlines() |
271 'replace').splitlines() |
271 |
272 |
272 nok = output[0] == "ERROR" |
273 nok = output[0] == "ERROR" |
273 if nok: |
274 if nok: |
274 fn = output[1] |
275 fn = output[1] |
276 error = output[3] |
277 error = output[3] |
277 return (True, fn, line, error) |
278 return (True, fn, line, error) |
278 else: |
279 else: |
279 return (False, None, None, None) |
280 return (False, None, None, None) |
280 |
281 |
281 return (True, filename, "1", |
282 return (True, filename, "1", |
282 self.trUtf8("Python2 interpreter did not finish within 15s.")) |
283 self.trUtf8("Python2 interpreter did not finish within 15s.")) |