本文整理汇总了Python中qtpy.QtCore.QProcess类的典型用法代码示例。如果您正苦于以下问题:Python QProcess类的具体用法?Python QProcess怎么用?Python QProcess使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QProcess类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_environment
def update_environment(self, filename, name=None, prefix=None, emit=False):
"""
Set environment at 'prefix' or 'name' to match 'filename' spec as yaml.
"""
if name and prefix:
raise TypeError("Exactly one of 'name' or 'prefix' is required.")
if self._is_not_running:
if name:
temporal_envname = name
if prefix:
temporal_envname = 'tempenv' + int(random.random()*10000000)
envs_dir = self.info()['envs_dirs'][0]
os.symlink(prefix, os.sep.join([envs_dir, temporal_envname]))
cmd = self._abspath(True)
cmd.extend(['env', 'update', '--name', temporal_envname, '--file',
os.path.abspath(filename)])
qprocess = QProcess()
qprocess.start(cmd[0], cmd[1:])
qprocess.waitForFinished()
if prefix:
os.unlink(os.sep.join([envs_dir, 'tempenv']))
示例2: __init__
def __init__(self, cmd_list, environ=None):
"""
Process worker based on a QProcess for non blocking UI.
Parameters
----------
cmd_list : list of str
Command line arguments to execute.
environ : dict
Process environment,
"""
super(ProcessWorker, self).__init__()
self._result = None
self._cmd_list = cmd_list
self._fired = False
self._communicate_first = False
self._partial_stdout = None
self._started = False
self._timer = QTimer()
self._process = QProcess()
self._set_environment(environ)
self._timer.setInterval(150)
self._timer.timeout.connect(self._communicate)
self._process.readyReadStandardOutput.connect(self._partial)
示例3: start
def start(self):
filename = to_text_string(self.filecombo.currentText())
self.process = QProcess(self)
self.process.setProcessChannelMode(QProcess.SeparateChannels)
self.process.setWorkingDirectory(osp.dirname(filename))
self.process.readyReadStandardOutput.connect(self.read_output)
self.process.readyReadStandardError.connect(
lambda: self.read_output(error=True))
self.process.finished.connect(lambda ec, es=QProcess.ExitStatus:
self.finished(ec, es))
self.stop_button.clicked.connect(self.process.kill)
self.output = ''
self.error_output = ''
plver = PYLINT_VER
if plver is not None:
if plver.split('.')[0] == '0':
p_args = ['-i', 'yes']
else:
# Option '-i' (alias for '--include-ids') was removed in pylint
# 1.0
p_args = ["--msg-template='{msg_id}:{line:3d},"\
"{column}: {obj}: {msg}"]
p_args += [osp.basename(filename)]
else:
p_args = [osp.basename(filename)]
self.process.start(PYLINT_PATH, p_args)
running = self.process.waitForStarted()
self.set_running_state(running)
if not running:
QMessageBox.critical(self, _("Error"),
_("Process failed to start"))
示例4: start
def start(self, wdir=None, args=None, pythonpath=None):
filename = to_text_string(self.filecombo.currentText())
if wdir is None:
wdir = self._last_wdir
if wdir is None:
wdir = osp.basename(filename)
print(filename)
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):
filename = osp.normpath(filename).replace(os.sep, '/')
if args is None:
args = self._last_args
if args is None:
args = []
if pythonpath is None:
pythonpath = self._last_pythonpath
self._last_wdir = wdir
self._last_args = args
self._last_pythonpath = pythonpath
self.datelabel.setText(_('Running tests, please wait...'))
self.process = QProcess(self)
self.process.setProcessChannelMode(QProcess.SeparateChannels)
self.process.setWorkingDirectory(filename)
self.process.readyReadStandardOutput.connect(self.read_output)
self.process.readyReadStandardError.connect(
lambda: self.read_output(error=True))
self.process.finished.connect(self.finished)
self.stop_button.clicked.connect(self.process.kill)
if pythonpath is not None:
env = [to_text_string(_pth)
for _pth in self.process.systemEnvironment()]
baseshell.add_pathlist_to_PYTHONPATH(env, pythonpath)
self.process.setEnvironment(env)
self.output = ''
self.error_output = ''
executable = "py.test"
p_args = ['--junit-xml', self.DATAPATH]
# executable = "nosetests"
# p_args = ['--with-xunit', "--xunit-file=%s" % self.DATAPATH]
if args:
p_args.extend(programs.shell_split(args))
self.process.start(executable, p_args)
running = self.process.waitForStarted()
self.set_running_state(running)
if not running:
QMessageBox.critical(self, _("Error"),
_("Process failed to start"))
示例5: create_process
def create_process(self):
self.shell.clear()
self.process = QProcess(self)
self.process.setProcessChannelMode(QProcess.MergedChannels)
# PYTHONPATH (in case we use Python in this terminal, e.g. py2exe)
env = [to_text_string(_path)
for _path in self.process.systemEnvironment()]
processEnvironment = QProcessEnvironment()
for envItem in env:
envName, separator, envValue = envItem.partition('=')
processEnvironment.insert(envName, envValue)
add_pathlist_to_PYTHONPATH(env, self.path)
self.process.setProcessEnvironment(processEnvironment)
# Working directory
if self.wdir is not None:
self.process.setWorkingDirectory(self.wdir)
# Shell arguments
if os.name == 'nt':
p_args = ['/Q']
else:
p_args = ['-i']
if self.arguments:
p_args.extend( shell_split(self.arguments) )
self.process.readyReadStandardOutput.connect(self.write_output)
self.process.finished.connect(self.finished)
self.kill_button.clicked.connect(self.process.kill)
if os.name == 'nt':
self.process.start('cmd.exe', p_args)
else:
# Using bash:
self.process.start('bash', p_args)
self.send_to_process('PS1="\\[email protected]\\h:\\w> "\n')
running = self.process.waitForStarted()
self.set_running_state(running)
if not running:
QMessageBox.critical(self, _("Error"),
_("Process failed to start"))
else:
self.shell.setFocus()
self.started.emit()
return self.process
示例6: environment_exists
def environment_exists(self, name=None, prefix=None, abspath=True,
emit=False):
"""
Check if an environment exists by 'name' or by 'prefix'. If query is
by 'name' only the default conda environments directory is searched.
"""
if name and prefix:
raise TypeError("Exactly one of 'name' or 'prefix' is required.")
qprocess = QProcess()
cmd_list = self._abspath(abspath)
cmd_list.extend(['list', '--json'])
if name:
cmd_list.extend(['--name', name])
else:
cmd_list.extend(['--prefix', prefix])
qprocess.start(cmd_list[0], cmd_list[1:])
qprocess.waitForFinished()
output = qprocess.readAllStandardOutput()
output = handle_qbytearray(output, CondaProcess.ENCODING)
info = json.loads(output)
if emit:
self.sig_finished.emit("info", unicode(info), "")
return 'error' not in info
示例7: pip_list
def pip_list(self, name=None, prefix=None, abspath=True, emit=False):
"""
Get list of pip installed packages.
"""
if (name and prefix) or not (name or prefix):
raise TypeError("conda pip: exactly one of 'name' ""or 'prefix' "
"required.")
if self._is_not_running:
cmd_list = self._abspath(abspath)
if name:
cmd_list.extend(['list', '--name', name])
if prefix:
cmd_list.extend(['list', '--prefix', prefix])
qprocess = QProcess()
qprocess.start(cmd_list[0], cmd_list[1:])
qprocess.waitForFinished()
output = qprocess.readAllStandardOutput()
output = handle_qbytearray(output, CondaProcess.ENCODING)
result = []
lines = output.split('\n')
for line in lines:
if '<pip>' in line:
temp = line.split()[:-1] + ['pip']
result.append('-'.join(temp))
if emit:
self.sig_finished.emit("pip", str(result), "")
return result
示例8: __init__
def __init__(self, parent):
QObject.__init__(self, parent)
self._parent = parent
self._output = None
self._partial = None
self._stdout = None
self._error = None
self._parse = False
self._function_called = ""
self._name = None
self._process = QProcess()
self.set_root_prefix()
# Signals
self._process.finished.connect(self._call_conda_ready)
self._process.readyReadStandardOutput.connect(self._call_conda_partial)
示例9: run
def run(self):
"""Handle the connection with the server.
"""
# Set up the zmq port.
self.socket = self.context.socket(zmq.PAIR)
self.port = self.socket.bind_to_random_port('tcp://*')
# Set up the process.
self.process = QProcess(self)
if self.cwd:
self.process.setWorkingDirectory(self.cwd)
p_args = ['-u', self.target, str(self.port)]
if self.extra_args is not None:
p_args += self.extra_args
# Set up environment variables.
processEnvironment = QProcessEnvironment()
env = self.process.systemEnvironment()
if (self.env and 'PYTHONPATH' not in self.env) or DEV:
python_path = osp.dirname(get_module_path('spyderlib'))
# Add the libs to the python path.
for lib in self.libs:
try:
path = osp.dirname(imp.find_module(lib)[1])
python_path = osp.pathsep.join([python_path, path])
except ImportError:
pass
env.append("PYTHONPATH=%s" % python_path)
if self.env:
env.update(self.env)
for envItem in env:
envName, separator, envValue = envItem.partition('=')
processEnvironment.insert(envName, envValue)
self.process.setProcessEnvironment(processEnvironment)
# Start the process and wait for started.
self.process.start(self.executable, p_args)
self.process.finished.connect(self._on_finished)
running = self.process.waitForStarted()
if not running:
raise IOError('Could not start %s' % self)
# Set up the socket notifer.
fid = self.socket.getsockopt(zmq.FD)
self.notifier = QSocketNotifier(fid, QSocketNotifier.Read, self)
self.notifier.activated.connect(self._on_msg_received)
示例10: _prepare_process
def _prepare_process(self, config, pythonpath):
"""
Prepare and return process for running the unit test suite.
This sets the working directory and environment.
"""
process = QProcess(self)
process.setProcessChannelMode(QProcess.MergedChannels)
process.setWorkingDirectory(config.wdir)
process.finished.connect(self.finished)
if pythonpath is not None:
env = [
to_text_string(_pth)
for _pth in process.systemEnvironment()
]
add_pathlist_to_PYTHONPATH(env, pythonpath)
processEnvironment = QProcessEnvironment()
for envItem in env:
envName, separator, envValue = envItem.partition('=')
processEnvironment.insert(envName, envValue)
process.setProcessEnvironment(processEnvironment)
return process
示例11: __init__
def __init__(self, parent, on_finished=None, on_partial=None):
QObject.__init__(self, parent)
self._parent = parent
self.output = None
self.partial = None
self.stdout = None
self.error = None
self._parse = False
self._function_called = ''
self._name = None
self._process = QProcess()
self._on_finished = on_finished
self._process.finished.connect(self._call_conda_ready)
self._process.readyReadStandardOutput.connect(self._call_conda_partial)
if on_finished is not None:
self._process.finished.connect(on_finished)
if on_partial is not None:
self._process.readyReadStandardOutput.connect(on_partial)
self.set_root_prefix()
示例12: __init__
def __init__(self, cmd_list, parse=False, pip=False, callback=None,
extra_kwargs={}):
super(ProcessWorker, self).__init__()
self._result = None
self._cmd_list = cmd_list
self._parse = parse
self._pip = pip
self._conda = not pip
self._callback = callback
self._fired = False
self._communicate_first = False
self._partial_stdout = None
self._extra_kwargs = extra_kwargs
self._timer = QTimer()
self._process = QProcess()
self._timer.setInterval(50)
self._timer.timeout.connect(self._communicate)
self._process.finished.connect(self._communicate)
self._process.readyReadStandardOutput.connect(self._partial)
示例13: info
def info(self, abspath=True):
"""
Return a dictionary with configuration information.
No guarantee is made about which keys exist. Therefore this function
should only be used for testing and debugging.
"""
# return self._call_and_parse(['info', '--json'], abspath=abspath)
qprocess = QProcess()
cmd_list = self._abspath(abspath)
cmd_list.extend(['info', '--json'])
qprocess.start(cmd_list[0], cmd_list[1:])
qprocess.waitForFinished()
output = qprocess.readAllStandardOutput()
output = handle_qbytearray(output, CondaProcess.ENCODING)
info = json.loads(output)
return info
示例14: __init__
def __init__(self, cmd_list, parse=False, pip=False, callback=None,
extra_kwargs=None):
"""Conda worker based on a QProcess for non blocking UI.
Parameters
----------
cmd_list : list of str
Command line arguments to execute.
parse : bool (optional)
Parse json from output.
pip : bool (optional)
Define as a pip command.
callback : func (optional)
If the process has a callback to process output from comd_list.
extra_kwargs : dict
Arguments for the callback.
"""
super(ProcessWorker, self).__init__()
self._result = None
self._cmd_list = cmd_list
self._parse = parse
self._pip = pip
self._conda = not pip
self._callback = callback
self._fired = False
self._communicate_first = False
self._partial_stdout = None
self._extra_kwargs = extra_kwargs if extra_kwargs else {}
self._timer = QTimer()
self._process = QProcess()
self._timer.setInterval(150)
self._timer.timeout.connect(self._communicate)
# self._process.finished.connect(self._communicate)
self._process.readyReadStandardOutput.connect(self._partial)
示例15: info
def info(self, abspath=True):
"""
Return a dictionary with configuration information.
No guarantee is made about which keys exist. Therefore this function
should only be used for testing and debugging.
"""
if self._is_not_running():
qprocess = QProcess()
cmd_list = self._abspath(abspath)
cmd_list.extend(["info", "--json"])
qprocess.start(cmd_list[0], cmd_list[1:])
qprocess.waitForFinished()
output = qprocess.readAllStandardOutput()
output = handle_qbytearray(output, CondaProcess.ENCODING)
info = json.loads(output)
self.sig_finished.emit("info", str(info), "")
return info