diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fca69c..5adc0a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## v0.2.2 + +- `exit_code` is now a property, `status_code` is still supported but will be deprecated +- `suppress_std_err` keyworded argument is added to prevent from always printing stderr + ## v0.2.1 - Custom enviroment variables can be passed to commands diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..417d6e1 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +upload: + twine check dist/* + twine upload dist/* + rm -rf dist/* diff --git a/docs/api_documentation.rst b/docs/api_documentation.rst index a30a783..b7f0c2d 100644 --- a/docs/api_documentation.rst +++ b/docs/api_documentation.rst @@ -1,7 +1,7 @@ API Documentation ================= -.. function:: soldier.run(command, background=False, std_id='', sudo=None, timeout=0, kill_on_timeout=False, shell=False) +.. function:: soldier.run(command, background=False, std_id='', sudo=None, timeout=0, kill_on_timeout=False, stream=False, suppress_std_err=False, shell=False) The main run command which executes the system process @@ -17,6 +17,8 @@ API Documentation :type env: dict(str, str) :param stream: When set to true, the output of your command will be streamed. (It does not work with piped commands) :type stream: bool + :param suppress_std_err: When set to true, the output from stderr would not be printed. + :type suppress_std_err: bool :param timeout: The timeout for the process in seconds :type timeout: int :param kill_on_timeout: If set to true, your process will killed when the time is up, and if it is False, it will throw a ``soldier.ProcessTimeoutError`` @@ -55,7 +57,8 @@ API Documentation **Properties** - pid - Returns the pid of the process - - status_code - Returns the status code of the process + - exit_code - Returns the exit code of the process + - status_code - Returns the exit code of the process (To be deprecated, prefer exit_code) - output - Returns the stdout (standard output) of the process - error - Returns the stderr (standard error) of the process - start_ts - Returns the start time (:class:`datetime.datetime` object) of the process diff --git a/docs/usage.rst b/docs/usage.rst index 314703a..432c719 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -14,7 +14,7 @@ After successfully installing soldier, you will now be able to communicate with >> print(current_path.output) /home/pythonista # Status Code - >> print(current_path.status_code) + >> print(current_path.exit_code) 0 **Run a process in background, and later terminate it** diff --git a/setup.py b/setup.py index 682002c..6a5b544 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name='soldier', - version='0.2.1', + version='0.2.2', author='Yash Mehrotra', author_email='yashmehrotra95@gmail.com', packages=['soldier'], diff --git a/soldier/soldier.py b/soldier/soldier.py index 59fd475..8f31eec 100644 --- a/soldier/soldier.py +++ b/soldier/soldier.py @@ -40,7 +40,7 @@ def __init__(self, command, **kwargs): """ self._command = command - self._status_code = None + self._exit_code = None self._background = kwargs.get('background', False) self._process = None self._pid = None @@ -60,6 +60,7 @@ def __init__(self, command, **kwargs): self._err = None self._timeout = kwargs.get('timeout', 0) self._kill_on_timeout = kwargs.get('kill_on_timeout', False) + self._suppress_std_err = kwargs.get('suppress_std_err', False) self._parse() self._validate() @@ -164,10 +165,10 @@ def _set_communication_params(self, wait=False): self._output, self._err = self._process.communicate(self._output) # This even comes as an output for stderr - if self._err: - warnings.warn(self._err, RuntimeWarning) + if self._err and not self._suppress_std_err: + print(self._err) - self._status_code = self._process.returncode + self._exit_code = self._process.returncode def _finish(self): """ @@ -208,7 +209,11 @@ def pid(self): @property def status_code(self): - return self._status_code + return self._exit_code + + @property + def exit_code(self): + return self._exit_code @property def output(self):