示例#1
0
class Events(QWidget):
    def __init__(self, text=None, file_name=None):
        super().__init__()

        self.dead_code = None

        self.info_bar = QTextEdit()
        self.font = QFont("Iosevka", 11)
        self.label = QLabel("Events")
        self.info_bar.setFont(self.font)
        self.buttons_layout = QHBoxLayout()
        self.layout = QVBoxLayout(self)
        self.info_bar.setReadOnly(True)
        self.layout.addLayout(self.buttons_layout)
        self.buttons_layout.addWidget(self.label)
        self.layout.addWidget(self.info_bar)
        self.setStyleSheet(
            """
        
        background-color: transparent;
        
        """
        )

    def look_for_dead_code(self, text):
        self.vultureObject = Vulture()
        self.vultureObject.scan(text)

        with io.StringIO() as buf, redirect_stdout(buf):
            self.vultureObject.report()
            output = buf.getvalue()

        info = output.replace(":", "").split()
        formatted_info = []
        unformatted_info = []
        for word in info:
            try:
                integer = int(word)
                new_word = '<h5 style="color: #78ffd6; ">Line {} </h5>'.format(integer)
                formatted_info.append("\n")
                formatted_info.append(new_word)
                unformatted_info.append("\n")
                unformatted_info.append("Line {}".format(integer))
            except ValueError:
                formatted_info.append("<font color=#dd3e54>" + word + "</font>")
                unformatted_info.append(word)

        self.dead_code = " ".join(formatted_info)
        self.info_bar.setText(self.dead_code)
示例#2
0
class DeadCodeCheker(QThread):

    doneSignal = pyqtSignal(bool)
    infoSignal = pyqtSignal(str)

    def __init__(self):

        super(DeadCodeCheker, self).__init__()

        self.text = None
        self.events_class = None

    def add_args(self, text):
        self.text = text
        self.events_class = Events

    def run(self):

        self.vultureObject = Vulture()
        self.vultureObject.scan(self.text)

        with io.StringIO() as buf, redirect_stdout(buf):
            self.vultureObject.report()
            output = buf.getvalue()

        info = output.replace(":", "").split()
        formatted_info = []
        unformatted_info = []
        for word in info:
            try:
                integer = int(word)
                new_word = '<h5 style="color: #78ffd6; ">Line {} </h5>'.format(integer)
                formatted_info.append("\n")
                formatted_info.append(new_word)
                unformatted_info.append("\n")
                unformatted_info.append("Line {}".format(integer))
            except ValueError:
                formatted_info.append("<font color=#dd3e54>" + word + "</font>")
                unformatted_info.append(word)

        self.dead_code = " ".join(formatted_info)
        self.doneSignal.emit(True)
        self.infoSignal.emit(self.dead_code)
示例#3
0
class DeadCodeChecker():
    def __init__(self, text):
        self.vultureObject = Vulture()
        self.vultureObject.scan(text)

    def getString(self):

        with io.StringIO() as buf, redirect_stdout(buf):

            self.vultureObject.report()
            output = buf.getvalue()

        newOutput = output.replace(':', '')
        return newOutput

    def getList(self):
        with io.StringIO() as buf, redirect_stdout(buf):

            self.vultureObject.report()
            output = buf.getvalue()

        newOutput = output.replace(':', '').split('\n')
        return newOutput