예제 #1
0
    def runModule(self, runScript, fileName, run_internal, run_with_args,
                  args):
        pythonPath = self.pythonPath()
        if pythonPath is None:
            return
        env = QtCore.QProcessEnvironment().systemEnvironment()
        self.runProcess.setProcessEnvironment(env)

        if run_internal:
            self.currentProcess = fileName
            if run_with_args:
                self.printout(
                    "\n*** Running: {0} <arguments={1}>\n".format(
                        self.currentProcess, args), 4)
                self.runProcess.start(pythonPath, [runScript, args],
                                      self.openMode)
            else:
                self.printout(
                    "\n*** Running: {0}\n".format(self.currentProcess), 4)
                self.runProcess.start(pythonPath, [runScript], self.openMode)
            self.runProcess.waitForStarted()
        else:
            if run_with_args:
                self.runProcess.startDetached(pythonPath,
                                              ["-i", runScript, args])
            else:
                self.runProcess.startDetached(pythonPath, ["-i", runScript])
예제 #2
0
    def runQProcess(self, context, callback):
        process = QtCore.QProcess(self)
        if context.workingDirectory is not None:
            process.setWorkingDirectory(context.workingDirectory)

        self.processTableModel.appendProcess(process,
                                             description=context.description())

        environment = QtCore.QProcessEnvironment()
        for key, value in context.environment.iteritems():
            environment.insert(key, value)

        process.setProcessEnvironment(environment)

        def onQProcessFinished(process, context, callback):
            def runCallback(exitCode):
                self.processTableModel.removeProcess(process)
                context.errorValue = str(
                    process.readAllStandardError()).decode("utf-8")
                context.outputValue = str(
                    process.readAllStandardOutput()).decode("utf-8")
                context.outputType = exitCode
                callback(context)

            return runCallback

        process.finished[int].connect(
            onQProcessFinished(process, context, callback))

        if context.inputType is not None:
            process.start(context.shellCommand, QtCore.QIODevice.ReadWrite)
            if not process.waitForStarted():
                raise Exception("No puedo correr")
            process.write(unicode(context.inputValue).encode("utf-8"))
            process.closeWriteChannel()
        else:
            process.start(context.shellCommand, QtCore.QIODevice.ReadOnly)
예제 #3
0
    def runProfiler(self, runScript, fileName, run_internal, run_with_args,
                    args):
        pythonPath = self.pythonPath()
        if pythonPath is None:
            return
        env = QtCore.QProcessEnvironment().systemEnvironment()
        self.runProcess.setProcessEnvironment(env)

        p_args = [
            '-m', 'cProfile', '-o',
            os.path.abspath(os.path.join("temp", "profile"))
        ]
        if os.name == 'nt':
            # On Windows, one has to replace backslashes by slashes to avoid
            # confusion with escape characters (otherwise, for example, '\t'
            # will be interpreted as a tabulation):
            p_args.append(os.path.normpath(runScript).replace(os.sep, '/'))
        else:
            p_args.append(runScript)

        self.profileMode = True
        if run_internal:
            self.currentProcess = fileName
            if run_with_args:
                self.printout(
                    ">>> Profiling: {0} <arguments={1}>\n".format(
                        self.currentProcess, args), 4)
            else:
                self.printout(
                    ">>> Profiling: {0} <arguments=None>\n".format(
                        self.currentProcess), 4)
            self.runProcess.start(pythonPath, p_args)
            self.runProcess.waitForStarted()
        else:
            p_args.insert(0, "-i")
            self.runProcess.startDetached(pythonPath, p_args)
예제 #4
0
    def runTrace(self, runScript, fileName, run_internal, run_with_args, args,
                 option):
        pythonPath = self.pythonPath()
        if pythonPath is None:
            return

        env = QtCore.QProcessEnvironment().systemEnvironment()
        self.runProcess.setProcessEnvironment(env)

        if run_internal:
            self.currentProcess = fileName
            if run_with_args:
                self.printout(
                    ">>> Trace Execution: {0} <arguments={1}>\n".format(
                        self.currentProcess, args), 4)
            else:
                self.printout(
                    ">>> Trace Execution: {0} <arguments=None>\n".format(
                        self.currentProcess), 4)
            if option == 0:
                # calling relationships
                if run_with_args:
                    self.runProcess.start(
                        pythonPath,
                        ['-m', "trace", '--trackcalls', runScript, args],
                        self.openMode)
                else:
                    self.runProcess.start(
                        pythonPath, ['-m', "trace", '--trackcalls', runScript],
                        self.openMode)
            elif option == 1:
                # functions called
                if run_with_args:
                    self.runProcess.start(
                        pythonPath,
                        ['-m', "trace", '--listfuncs', runScript, args],
                        self.openMode)
                else:
                    self.runProcess.start(
                        pythonPath, ['-m', "trace", '--listfuncs', runScript],
                        self.openMode)
            elif option == 2:
                # creates a file with same code but showing how many times
                # each line of code args
                countfile = os.path.abspath(os.path.join("temp", "count.txt"))
                file = open(countfile, 'w')
                file.close()
                if run_with_args:
                    self.runProcess.start(pythonPath, [
                        '-m', "trace", '--count',
                        '--file={0}'.format(countfile), runScript, args
                    ], self.openMode)
                else:
                    self.runProcess.start(pythonPath, [
                        '-m', "trace", '--count',
                        '--file={0}'.format(countfile), runScript
                    ], self.openMode)
            elif option == 3:
                # show in real time what lines of code are currently being
                # executed
                if run_with_args:
                    self.runProcess.start(pythonPath, [
                        '-m', "trace", '--timing', '--trace', runScript, args
                    ], self.openMode)
                else:
                    self.runProcess.start(
                        pythonPath,
                        ['-m', "trace", '--timing', '--trace', runScript],
                        self.openMode)
        else:
            if option == 0:
                # calling relationships
                if run_with_args:
                    self.runProcess.startDetached(
                        pythonPath,
                        ['-i', '-m', "trace", '--trackcalls', runScript, args],
                        self.openMode)
                else:
                    self.runProcess.startDetached(
                        pythonPath,
                        ['-i', '-m', "trace", '--trackcalls', runScript])
            elif option == 1:
                # functions called
                if run_with_args:
                    self.runProcess.startDetached(
                        pythonPath,
                        ['-i', '-m', "trace", '--listfuncs', runScript, args])
                else:
                    self.runProcess.startDetached(
                        pythonPath,
                        ['-i', '-m', "trace", '--listfuncs', runScript])
            elif option == 2:
                # creates a file with same code but showing how many times each
                # line of code runs
                if run_with_args:
                    self.runProcess.startDetached(
                        pythonPath,
                        ['-i', '-m', "trace", '--count', runScript, args])
                else:
                    self.runProcess.startDetached(
                        pythonPath,
                        ['-i', '-m', "trace", '--count', runScript])
            elif option == 3:
                # show in real time what lines of code are currently being
                # executed
                if run_with_args:
                    self.runProcess.startDetached(pythonPath, [
                        '-i', '-m', "trace", '--timing', '--trace', runScript,
                        args
                    ])
                else:
                    self.runProcess.startDetached(pythonPath, [
                        '-i', '-m', "trace", '--timing', '--trace', runScript
                    ])