module installhelper.run_cmd
¶
Short summary¶
module pymyinstall.installhelper.run_cmd
Implements function run_cmd()
.
Classes¶
class |
truncated documentation |
---|---|
raised by function |
Functions¶
function |
truncated documentation |
---|---|
decode the output or the error after running a command line instructions |
|
return the interpreter path |
|
run a command line and wait for the result |
|
run a command line and wait for the result |
|
has the same signature as |
|
splits a command line |
Properties¶
property |
truncated documentation |
---|---|
|
A boolean value indicating whether this thread is a daemon thread. This must be set before start() is called, otherwise … |
|
Thread identifier of this thread or None if it has not been started. This is a nonzero integer. See the get_ident() … |
|
A string used for identification purposes only. It has no semantics. Multiple threads may be given the same name. … |
|
Native integral thread ID of this thread, or None if it has not been started. This is a non-negative integer. … |
Static Methods¶
staticmethod |
truncated documentation |
---|---|
|
Methods¶
method |
truncated documentation |
---|---|
|
|
Documentation¶
Implements function run_cmd
.
New in version 1.1.
- exception pymyinstall.installhelper.run_cmd.RunCmdException¶
Bases:
RuntimeError
raised by function
run_cmd
- class pymyinstall.installhelper.run_cmd._AsyncLineReader(fd, outputQueue, catch_exit)¶
Bases:
Thread
This constructor should always be called with keyword arguments. Arguments are:
group should be None; reserved for future extension when a ThreadGroup class is implemented.
target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.
name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.
args is the argument tuple for the target invocation. Defaults to ().
kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.
If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.
- __init__(fd, outputQueue, catch_exit)¶
This constructor should always be called with keyword arguments. Arguments are:
group should be None; reserved for future extension when a ThreadGroup class is implemented.
target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.
name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.
args is the argument tuple for the target invocation. Defaults to ().
kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.
If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.
- run()¶
Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
- pymyinstall.installhelper.run_cmd.decode_outerr(outerr, encoding, encerror, msg)¶
decode the output or the error after running a command line instructions
- Parameters:
outerr – output or error
encoding – encoding (if None, it is replaced by ascii)
encerror – how to handle errors
msg – to add to the exception message
- Returns:
converted string
Changed in version 1.4: If encoding is None, it is replaced by
'ascii'
.
- pymyinstall.installhelper.run_cmd.get_interpreter_path()¶
return the interpreter path
- pymyinstall.installhelper.run_cmd.run_cmd_old(cmd, sin='', shell=False, wait=False, log_error=True, secure=None, stop_waiting_if=None, do_not_log=False, encerror='ignore', encoding='utf8', cwd=None, fLOG=<built-in function print>)¶
run a command line and wait for the result
- Parameters:
cmd – command line
sin – sin, what must be written on the standard input
shell – if True, cmd is a shell command (and no command window is opened)
wait – call proc.wait
log_error – if log_error, call fLOG (error)
secure – if secure is a string (a valid filename), the function stores the output in a file and reads it continuously
stop_waiting_if – the function stops waiting if some condition is fulfilled. The function received the last line from the logs.
do_not_log – do not log the output
encerror – encoding errors (ignore by default) while converting the output into a string
encoding – encoding of the output
cwd – current folder
fLOG – logging function
- Returns:
content of stdout, stderr (only if wait is True)
Exception when installing a module
This error can occur when a module is installed on a virtual environment created before pip was updated on the main distribution. The solution consists in removing the virtual environment and create it again.
c:\Python34_x64vir\install\Scripts\python -u setup.py install running install running bdist_egg running egg_info Traceback (most recent call last): File "c:\Python34_x64vir\install\lib\site-packages\pkg_resources\__init__.py", line 2785, in _dep_map return self.__dep_map File "c:\Python34_x64vir\install\lib\site-packages\pkg_resources\__init__.py", line 2642, in __getattr__ raise AttributeError(attr) AttributeError: _DistInfoDistribution__dep_map During handling of the above exception, another exception occurred: Traceback (most recent call last): File "c:\Python34_x64vir\install\lib\site-packages\pkg_resources\__init__.py", line 2776, in _parsed_pkg_info return self._pkg_info File "c:\Python34_x64vir\install\lib\site-packages\pkg_resources\__init__.py", line 2642, in __getattr__ raise AttributeError(attr) AttributeError: _pkg_info During handling of the above exception, another exception occurred: Traceback (most recent call last): File "setup.py", line 169, in <module> package_data=package_data, File "C:\Python34_x64\Lib\distutils\core.py", line 148, in setup dist.run_commands() File "C:\Python34_x64\Lib\distutils\dist.py", line 955, in run_commands self.run_command(cmd) File "C:\Python34_x64\Lib\distutils\dist.py", line 974, in run_command cmd_obj.run() File "c:\Python34_x64vir\install\lib\site-packages\setuptools\command\install.py", line 67, in run self.do_egg_install() File "c:\Python34_x64vir\install\lib\site-packages\setuptools\command\install.py", line 109, in do_egg_install self.run_command('bdist_egg') File "C:\Python34_x64\Lib\distutils\cmd.py", line 313, in run_command self.distribution.run_command(command) File "C:\Python34_x64\Lib\distutils\dist.py", line 974, in run_command cmd_obj.run() File "c:\Python34_x64vir\install\lib\site-packages\setuptools\command\bdist_egg.py", line 151, in run self.run_command("egg_info") File "C:\Python34_x64\Lib\distutils\cmd.py", line 313, in run_command self.distribution.run_command(command) File "C:\Python34_x64\Lib\distutils\dist.py", line 974, in run_command cmd_obj.run() File "c:\Python34_x64vir\install\lib\site-packages\setuptools\command\egg_info.py", line 171, in run ep.require(installer=installer) File "c:\Python34_x64vir\install\lib\site-packages\pkg_resources\__init__.py", line 2355, in require items = working_set.resolve(reqs, env, installer) File "c:\Python34_x64vir\install\lib\site-packages\pkg_resources\__init__.py", line 835, in resolve new_requirements = dist.requires(req.extras)[::-1] File "c:\Python34_x64vir\install\lib\site-packages\pkg_resources\__init__.py", line 2586, in requires dm = self._dep_map File "c:\Python34_x64vir\install\lib\site-packages\pkg_resources\__init__.py", line 2787, in _dep_map self.__dep_map = self._compute_dependencies() File "c:\Python34_x64vir\install\lib\site-packages\pkg_resources\__init__.py", line 2809, in _compute_dependencies for req in self._parsed_pkg_info.get_all('Requires-Dist') or []: File "c:\Python34_x64vir\install\lib\site-packages\pkg_resources\__init__.py", line 2778, in _parsed_pkg_info metadata = self.get_metadata(self.PKG_INFO) File "c:\Python34_x64vir\install\lib\site-packages\pkg_resources\__init__.py", line 1993, in get_metadata raise KeyError("No metadata except PKG-INFO is available") KeyError: 'No metadata except PKG-INFO is available'
- pymyinstall.installhelper.run_cmd.run_cmd_private(cmd, sin='', shell=True, wait=False, log_error=True, stop_running_if=None, encerror='ignore', encoding='utf8', change_path=None, communicate=True, preprocess=True, timeout=None, catch_exit=False, fLOG=None, tell_if_no_output=None)¶
run a command line and wait for the result
- Parameters:
cmd – command line
sin – sin: what must be written on the standard input
shell – if True, cmd is a shell command (and no command window is opened)
wait – call
proc.wait
log_error – if log_error, call fLOG (error)
stop_running_if – the function stops waiting if some condition is fulfilled. The function received the last line from the logs. Signature:
stop_waiting_if(last_out, last_err) -> bool
. The function must return True to stop waiting. This function can also be used to intercept the standard output and the standard error while running.encerror – encoding errors (ignore by default) while converting the output into a string
encoding – encoding of the output
change_path – change the current path if not None (put it back after the execution)
communicate – use method communicate which is supposed to be safer, parameter
wait
must be Truepreprocess – preprocess the command line if necessary (not available on Windows) (False to disable that option)
timeout – when data is sent to stdin (
sin
), a timeout is needed to avoid waiting for ever (timeout is in seconds)catch_exit – catch SystemExit exception
fLOG – logging function (if not None, bypass others parameters)
tell_if_no_output – tells if there is no output every tell_if_no_output seconds
- Returns:
content of stdout, stdres (only if wait is True)
Run a program using the command line
from pyquickhelper.loghelper import run_cmd out,err = run_cmd( "python setup.py install", wait=True)
If you are using this function to run git function, parameter
shell
must be True.New in version 1.1.
- pymyinstall.installhelper.run_cmd.skip_run_cmd(cmd, sin='', shell=True, wait=False, log_error=True, stop_running_if=None, encerror='ignore', encoding='utf8', change_path=None, communicate=True, preprocess=True, timeout=None, catch_exit=False, fLOG=None, timeout_listen=None, tell_if_no_output=None)¶
has the same signature as
run_cmd
but does nothingNew in version 1.0.
- pymyinstall.installhelper.run_cmd.split_cmp_command(cmd, remove_quotes=True)¶
splits a command line
- Parameters:
cmd – command line
remove_quotes – True by default
- Returns:
list