def get_process_environment(self): env = QtCore.QProcessEnvironment() # setup system environment variables except PATH for k, v in os.environ.items(): if k != 'PATH': env.insert(k, v) path = os.environ['PATH'] # Setup interpreter environment variables for k, v in self.config.environment_variables.items(): if not v: continue if k == 'PATH': # special case for PATH, best is to prepend to the existing system path path = v + os.pathsep + path env.insert(k, v) # Prepend interpreter path interpreter_path = self.get_full_path() if interpreter_path and os.path.exists( os.path.dirname(interpreter_path)): compiler_dir = os.path.dirname(interpreter_path) path = compiler_dir + os.pathsep + path env.insert('PATH', path) return env
def __init__(self, cmd, cb, env=None, cb_extra_args=None, cache=False): super(NonBlockingQtProcess, self).__init__() name = ".".join(cmd) self.name = name self.cmd = cmd self.cb_extra_args = cb_extra_args self.cache = cache self.output = "" if cache: if NonBlockingQtProcess.answer_if_in_cache(name, self, cb): return if not NonBlockingQtProcess.register_process(name, self, cb): # Output.debug("A process is already running. not running a new one.") return # A process is already running. cb will be called self.finished.connect(self._finished) self.readyReadStandardOutput.connect(self._readyReadStandardOutput) if env is not None: proc_env = QtCore.QProcessEnvironment() for k, v in env.items(): proc_env.insert(k, v) self.setProcessEnvironment(proc_env) self.setProcessChannelMode(QtCore.QProcess.MergedChannels) self.start(" ".join(self.cmd), QtCore.QIODevice.ReadOnly)
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( ">>> Running: {0} <arguments={1}>\n".format( self.currentProcess, args), 4) self.runProcess.start(pythonPath, [runScript, args], self.openMode) else: self.printout( ">>> Running: {0} <arguments=None>\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])
def get_process_environment(self): """ Returns the process environemnt that needs to be setup to run a compiler command or to run the compiled program. :rtype: QtCore.QProvessEnvironment """ env = QtCore.QProcessEnvironment() # setup system environemnts except PATH for k, v in os.environ.items(): if k != 'PATH': env.insert(k, v) PATH = os.environ['PATH'] # Retrieve msvc environment vars if needed if system.WINDOWS and self.config.vcvarsall: vc_vars = msvc.query_vcvarsall(self.config.vcvarsall, self.config.vcvarsall_arch) for k, v in vc_vars.items(): if k != 'path': env.insert(k, v) else: # we can safely replace original env by the one returned # by vcvarsall as it includes what is defined in our # process PATH = v # Setup compiler environement variables for k, v in self.config.environment_variables.items(): if not v: continue if k == 'PATH': # special case for PATH, best is to prepend to the existing system path PATH = v + os.pathsep + PATH env.insert(k, v) # Prepend compiler path compiler_path = self.get_full_compiler_path() if compiler_path and os.path.exists(os.path.dirname(compiler_path)): compiler_dir = os.path.dirname(compiler_path) PATH = compiler_dir + os.pathsep + PATH env.insert('PATH', PATH) return env
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)
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 ])