def onOccurences(self): """The user requested a list of occurences""" if not self.isPythonBuffer(): return if self._parent.getType() == MainWindowTabWidgetBase.VCSAnnotateViewer: return if not os.path.isabs(self._parent.getFileName()): GlobalData().mainWindow.showStatusBarMessage( "Please save the buffer and try again") return fileName = self._parent.getFileName() QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) definitions = getOccurrences(self, fileName) QApplication.restoreOverrideCursor() if len(definitions) == 0: GlobalData().mainWindow.showStatusBarMessage('No occurences found') return # There are found items GlobalData().mainWindow.showStatusBarMessage('') result = [] for definition in definitions: fName = definition.module_path if not fName: fName = fileName lineno = definition.line index = getSearchItemIndex(result, fName) if index < 0: widget = GlobalData().mainWindow.getWidgetForFileName(fName) if widget is None: uuid = "" else: uuid = widget.getUUID() newItem = ItemToSearchIn(fName, uuid) result.append(newItem) index = len(result) - 1 result[index].addMatch(definition.name, lineno) GlobalData().mainWindow.displayFindInFiles('', result)
def __process(self): " Analysis process " self.__inProgress = True mainWindow = GlobalData().mainWindow editorsManager = mainWindow.editorsManagerWidget.editorsManager modified = editorsManager.getModifiedList( True) # True - only project files if modified: modNames = [modItem[0] for modItem in modified] label = "File" if len(modified) >= 2: label += "s" label += ": " logging.warning( "The analisys is performed for the content of saved files. " \ "The unsaved modifications will not be taken into account. " \ + label + ", ".join( modNames ) ) self.__updateFoundLabel() self.__progressBar.setRange(0, len(self.__srcModel.rootItem.childItems)) QApplication.processEvents() QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) count = 0 candidates = [] for treeItem in self.__srcModel.rootItem.childItems: if self.__cancelRequest: break name = str(treeItem.data(0)).split('(')[0] path = os.path.realpath(treeItem.getPath()) lineNumber = int(treeItem.data(2)) absPosition = treeItem.sourceObj.absPosition count += 1 self.__progressBar.setValue(count) self.__infoLabel.setText(self.__formInfoLabel(name)) QApplication.processEvents() # Analyze the name found = False try: # True is for throwing exceptions locations = getOccurrences(path, absPosition, True) if len( locations ) == 1 and \ locations[ 0 ][ 1 ] == lineNumber: found = True index = getSearchItemIndex(candidates, path) if index < 0: widget = mainWindow.getWidgetForFileName(path) if widget is None: uuid = "" else: uuid = widget.getUUID() newItem = ItemToSearchIn(path, uuid) candidates.append(newItem) index = len(candidates) - 1 candidates[index].addMatch(name, lineNumber) except Exception, exc: # There is nothing interesting with exceptions here. # It seems to me that rope throws them in case if the same item # is declared multiple times in a file. I also suspect that # exceptions may come up in case of syntactic errors. # So I just suppress them. pass #logging.warning( "Error detected while analysing " + \ # self.__whatAsString() + " '" + name + \ # "'. Message: " + str( exc ) ) if found: self.__found += 1 self.__updateFoundLabel() QApplication.processEvents()
def __process(self): """Analysis process""" self.__inProgress = True mainWindow = GlobalData().mainWindow QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) # return code gives really nothing. So the error in running the utility # is detected by the stderr content. # Also, there could be a mix of messages for a project. Some files # could have syntax errors - there will be messages on stderr. The # other files are fine so there will be messages on stdout stdout, stderr = self.__run() candidates = [] for line in stdout.splitlines(): line = line.strip() if line: # Line is like file.py:2: unused variable 'a' (60% confidence) try: startIndex = line.find(':') if startIndex < 0: continue endIndex = line.find(':', startIndex + 1) if endIndex < 0: continue fileName = line[:startIndex] startIndex = line.find(':') if startIndex < 0: continue endIndex = line.find(':', startIndex + 1) if endIndex < 0: continue fileName = os.path.abspath(line[:startIndex]) lineno = int(line[startIndex + 1:endIndex]) message = line[endIndex + 1:].strip() except: continue index = getSearchItemIndex(candidates, fileName) if index < 0: widget = mainWindow.getWidgetForFileName(fileName) if widget is None: uuid = '' else: uuid = widget.getUUID() newItem = ItemToSearchIn(fileName, uuid) candidates.append(newItem) index = len(candidates) - 1 candidates[index].addMatch('', lineno, message) self.__found += 1 self.__updateFoundLabel() QApplication.processEvents() if self.__found == 0: if stderr: logging.error('Error running vulture for ' + self.__path + ':\n' + stderr) else: logging.info('No unused candidates found') else: mainWindow.displayFindInFiles('', candidates) QApplication.restoreOverrideCursor() self.__infoLabel.setText('Done') self.__inProgress = False self.accept()
def __process(self): """Analysis process""" self.__inProgress = True mainWindow = GlobalData().mainWindow editorsManager = mainWindow.editorsManagerWidget.editorsManager # True - only project files modified = editorsManager.getModifiedList(True) if modified: modNames = [modItem[0] for modItem in modified] label = "File" if len(modified) >= 2: label += "s" label += ": " logging.warning("The analisys is performed for the content " "of saved files. The unsaved modifications will " "not be taken into account. " + label + ", ".join(modNames)) self.__updateFoundLabel() self.__progressBar.setRange(0, len(self.__srcModel.rootItem.childItems)) QApplication.processEvents() QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) count = 0 candidates = [] for treeItem in self.__srcModel.rootItem.childItems: if self.__cancelRequest: break name = str(treeItem.data(0)).split('(')[0] path = os.path.realpath(treeItem.getPath()) lineNumber = int(treeItem.data(2)) pos = treeItem.sourceObj.pos count += 1 self.__progressBar.setValue(count) self.__infoLabel.setText(self.__formInfoLabel(name)) QApplication.processEvents() # Analyze the name found = False definitions = getOccurrences(None, path, lineNumber, pos) if len(definitions) == 1: found = True index = getSearchItemIndex(candidates, path) if index < 0: widget = mainWindow.getWidgetForFileName(path) if widget is None: uuid = "" else: uuid = widget.getUUID() newItem = ItemToSearchIn(path, uuid) candidates.append(newItem) index = len(candidates) - 1 candidates[index].addMatch(name, lineNumber) if found: self.__found += 1 self.__updateFoundLabel() QApplication.processEvents() if self.__found == 0: # The analysis could be interrupted if not self.__cancelRequest: logging.info("No unused candidates found") else: mainWindow.displayFindInFiles("", candidates) QApplication.restoreOverrideCursor() self.__infoLabel.setText('Done') self.__inProgress = False self.accept()