Example #1
0
    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()
Example #2
0
    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()
Example #3
0
def doSVNCommit(plugin, client, path):
    """Performs SVN commit"""
    # The path could be a single file (buffer or project browser) or
    # a directory

    QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
    try:
        if path.endswith(os.path.sep):
            # This is a directory. Path lists should be built.
            statuses = plugin.getLocalStatus(path, pysvn.depth.infinity)
            if type(statuses) != list:
                logging.error("Error checking local SVN statuses for " + path)
                QApplication.restoreOverrideCursor()
                return

            pathsToCommit = []
            pathsToIgnore = []
            for item in statuses:
                if item[1] in COMMIT_ALLOW_STATUSES:
                    pathsToCommit.append(item)
                elif item[1] in IGNORE_STATUSES + [plugin.NOT_UNDER_VCS]:
                    pathsToIgnore.append(item)

            if not pathsToCommit:
                logging.info("No paths to commit for " + path)
                QApplication.restoreOverrideCursor()
                return
        else:
            # This is a single file
            status = plugin.getLocalStatus(path)
            if status not in COMMIT_ALLOW_STATUSES:
                logging.error("Cannot commit " + path +
                              " due to unexpected SVN status")
                QApplication.restoreOverrideCursor()
                return
            pathsToCommit = [
                (path, status),
            ]
            pathsToIgnore = []
    except Exception as exc:
        logging.error(str(exc))
        QApplication.restoreOverrideCursor()
        return
    QApplication.restoreOverrideCursor()

    dlg = SVNPluginCommitDialog(plugin, pathsToCommit, pathsToIgnore)
    res = dlg.exec_()

    if res == QDialog.Accepted:
        if len(dlg.commitPaths) == 0:
            return
        dlg.commitPaths.sort()

        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        try:

            def getLogMessage(msg=dlg.commitMessage):
                return True, msg

            def notifyCallback(event):
                if event['path']:
                    action = notifyActionToString(event['action'])
                    if action:
                        logging.info("Commit: " + action + " " + event['path'])
                        QApplication.processEvents()
                return

            client.callback_get_log_message = getLogMessage
            client.callback_notify = notifyCallback

            revision = client.checkin(dlg.commitPaths,
                                      log_message=dlg.commitMessage,
                                      recurse=False)
            logging.info("Committed revision " + str(revision.number))
            for path in dlg.commitPaths:
                plugin.notifyPathChanged(path)
        except pysvn.ClientError as exc:
            message = exc.args[0]
            logging.error(message)
        except Exception as exc:
            logging.error(str(exc))
        except:
            logging.error("Unknown error")
        QApplication.restoreOverrideCursor()
    def __process(self):
        """Search process"""
        self.__updateHistory()

        self.__inProgress = True
        numberOfMatches = 0
        self.searchResults = []
        self.searchRegexp = None

        # Form the regexp to search
        regexpText = self.findCombo.currentText()
        if not self.regexpCheckBox.isChecked():
            regexpText = re.escape(regexpText)
        if self.wordCheckBox.isChecked():
            regexpText = "\\b%s\\b" % regexpText
        flags = re.UNICODE
        if not self.caseCheckBox.isChecked():
            flags |= re.IGNORECASE

        try:
            self.searchRegexp = re.compile(regexpText, flags)
        except Exception as exc:
            logging.error("Invalid search expression: %s", str(exc))
            self.close()
            return

        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        self.fileLabel.setPath('Building list of files to search in...')
        QApplication.processEvents()
        try:
            files = self.__buildFilesList()
        except Exception as exc:
            QApplication.restoreOverrideCursor()
            if 'Cancel request' not in str(exc):
                logging.error(str(exc))
            self.close()
            return
        QApplication.restoreOverrideCursor()
        QApplication.processEvents()

        if not files:
            self.fileLabel.setPath('No files to search in')
            return

        self.progressBar.setRange(0, len(files))

        index = 1
        for item in files:

            if self.__cancelRequest:
                self.__inProgress = False
                self.close()
                return

            self.fileLabel.setPath('Matches: ' + str(numberOfMatches) +
                                   ' Processing: ' + item.fileName)

            item.search(self.searchRegexp)
            found = len(item.matches)
            if found > 0:
                numberOfMatches += found
                self.searchResults.append(item)

            self.progressBar.setValue(index)
            index += 1

            QApplication.processEvents()

        if numberOfMatches > 0 or self.__newSearch == False:
            # If it is redo then close the dialog anyway
            self.close()
        else:
            msg = 'No matches in ' + str(len(files)) + ' file'
            if len(files) > 1:
                msg += 's'
            self.fileLabel.setPath(msg)
            self.__inProgress = False