示例#1
0
 def run(self):
     if self.debug_process is not None:
         if self.askTerminateOrNot():
             self.terminate()
         else:
             return
     if not self.compile(no_debug=True):
         return
     self.updateWindowTitle(True)
     compiled_file = util.get_compiled_file(self.editor.lang, self.editor.fname)
     if not os.path.isfile(compiled_file):
         util.disp_error("Compiled file is not found.")
     try:
         output = subprocess.check_output(
             util.exec_command(self.editor.lang) + [compiled_file],
             stderr=subprocess.STDOUT,
         )
         self.console.writeLnSignal.emit(output)
     except subprocess.CalledProcessError as err:
         self.console.writeLnSignal.emit("[-] " + err.output.decode())
         self.console.writeLnSignal.emit("[-] Run process is terminated abnormally.")
         self.updateWindowTitle(False)
         return
     self.console.writeLnSignal.emit("[+] Run process is finished successfully!")
     self.updateWindowTitle(False)
示例#2
0
 def submit(self, *args):
     if not self.editor.fname:
         util.disp_error("Please save this file")
     submit.SubmitDialog(
         self,
         url=self.browser_widget.browser.url().toString(),
         lang=self.editor.lang,
     ).show()
示例#3
0
 def compile(self, no_debug: bool = False):
     self.console.clear()
     self.editor.reset_compile_info()
     if not self.editor.fname:
         util.disp_error("File is not opened.")
     command = util.compile_command(self.editor.lang, no_debug) + [self.editor.fname]
     try:
         out = subprocess.check_output(command, stderr=subprocess.STDOUT)
         self.console.writeLnSignal.emit("[+] Compile is finished successfully!")
         error_places, warning_places = self.parse_compile_error(out.decode())
         self.editor.highlight_compile_error(warning_places, is_warning=True)
     except subprocess.CalledProcessError as err:
         self.console.writeSignal.emit(WriteObj(err.output, mode="error"))
         error_places, warning_places = self.parse_compile_error(err.output.decode())
         self.editor.highlight_compile_error(error_places, is_warning=False)
         return False
     return True
示例#4
0
    def debug(self, *args, **kwargs):
        self.console.clear()
        if not self.compile():
            return
        if self.debug_process is not None:
            if self.askTerminateOrNot():
                self.terminate()
            else:
                return
        compiled_file = util.get_compiled_file(self.editor.lang, self.editor.fname)
        if not os.path.isfile(compiled_file):
            util.disp_error("Compiled file is not found.")
        try:
            assert self.debug_process is None
            self.debug_process = pexpect.spawn(
                util.debug_command(self.editor.lang) + " " + compiled_file
            )
            util.wait_input_ready(self.debug_process, self.editor.lang)
            self.console.writeSignal.emit(WriteObj(self.debug_process.before.decode()))

            for com in self.editor.generateBreak():
                self.debug_process.send(com)
                util.wait_input_ready(self.debug_process, self.editor.lang)
                self.console.writeSignal.emit(
                    WriteObj(self.debug_process.before.decode(), mode="gdb")
                )

            print("run " + compiled_file)
            self.debug_process.send(b"run\n")
            self.updateWindowTitle()
            if self.editor.lang == "python3":
                util.wait_input_ready(self.debug_process, self.editor.lang)
                self.debug_process.send(b"continue\n")
            self.post_process()

        except subprocess.CalledProcessError as err:
            self.console.writeSignal(WriteObj(err, mode="error"))
示例#5
0
    def debugWithTestData(self, use_lastcase=False):
        self.console.clear()
        if not self.compile():
            return
        if self.debug_process is not None:
            if self.askTerminateOrNot():
                self.terminate()
            else:
                return
        if (
            use_lastcase
            and self.last_used_testcase
            and os.path.isfile(self.last_used_testcase)
        ):
            fname = self.last_used_testcase
        else:
            fname = QtWidgets.QFileDialog.getOpenFileName(
                self, "Open", self.test_data_dir, "Test data (*.in)"
            )[0]
        if not fname:
            self.last_used_testcase = ""
            return
        self.last_used_testcase = fname

        with open(fname) as fr:
            inputs = [line for line in fr if line]

        compiled_file = util.get_compiled_file(self.editor.lang, self.editor.fname)
        if not os.path.isfile(compiled_file):
            util.disp_error("Compiled file is not found.")
        try:
            if self.debug_process is None:
                self.debug_process = pexpect.spawn(
                    util.debug_command(self.editor.lang) + " " + compiled_file
                )
                self.console.terminate_evcxr()
            else:
                self.continue_process()
                return
            util.wait_input_ready(self.debug_process, self.editor.lang)
            for com in self.editor.generateBreak():
                self.debug_process.send(com)
                util.wait_input_ready(self.debug_process, self.editor.lang)
                self.console.writeSignal.emit(
                    WriteObj(self.debug_process.before.decode(), mode="gdb")
                )

            print("run " + compiled_file)
            self.debug_process.send(b"run\n")
            self.updateWindowTitle()
            if self.editor.lang == "python3":
                util.wait_input_ready(self.debug_process, self.editor.lang)
                self.debug_process.send(b"continue\n")
            for i, debug_input in enumerate(inputs):
                msg = self.debug_process.before.decode()
                for line in msg.split("\r\n"):
                    self.console.writeSignal.emit(WriteObj(line, mode="gdb"))

                for line in reversed(msg.split("\r\n")):
                    if line.endswith("exited normally]"):
                        if i != len(inputs) - 1:
                            self.console.writeLnSignal.emit(
                                "[-] Partial input is rejected"
                            )
                        self.terminate()
                        return
                    if "exited with code" in line:
                        self.console.writeLnSignal.emit(
                            "[-] Process is finished with error"
                        )
                        self.terminate()
                        return

                self.debug_process.send(debug_input.encode())
            self.post_process()
            self.updateWindowTitle()
            self.console.run_evcxr()

        except subprocess.CalledProcessError as err:
            self.console.writeSignal.emit(WriteObj(err, mode="error"))
            self.console.run_evcxr()