From b6fdd7329a97c1e7abff7e34e2bac569e1de2137 Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Aug 31 2016 07:15:40 +0000 Subject: Output both stdout and stderr when not in tty Output both stdout and stderr so that all of them can be redirected to other destination. Signed-off-by: Chenxiong Qi --- diff --git a/setup.cfg b/setup.cfg index fd43831..a3f598c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,3 +1,6 @@ +[flake8] +max-line-length = 100 + [nosetests] verbosity = 2 detailed-errors = 1 diff --git a/src/pyrpkg/__init__.py b/src/pyrpkg/__init__.py index f881e11..98433f6 100644 --- a/src/pyrpkg/__init__.py +++ b/src/pyrpkg/__init__.py @@ -937,11 +937,10 @@ class Commands(object): subprocess.check_call(command, env=environ, shell=shell, stdout=sys.stdout, stderr=sys.stderr, cwd=cwd) - except (subprocess.CalledProcessError, - OSError) as e: + except (subprocess.CalledProcessError, OSError) as e: raise rpkgError(e) except KeyboardInterrupt: - raise rpkgError() + raise rpkgError('Command is terminated by user.') else: # Ok, we're not on a live tty, so pipe and log. if pipe: @@ -964,17 +963,15 @@ class Commands(object): cwd=cwd) output, error = proc.communicate() else: - proc = subprocess.Popen(command, env=environ, shell=shell, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, cwd=cwd) - output, error = proc.communicate() - except OSError as e: + proc = subprocess.Popen(command, env=environ, shell=shell, cwd=cwd) + proc.wait() + except KeyboardInterrupt: + raise rpkgError('Command is terminated by user.') + except Exception as e: raise rpkgError(e) - self.log.info(output) - if proc.returncode: - raise rpkgError('Command %s returned code %s with error: %s' - % (' '.join(cmd), proc.returncode, error)) - return + + if proc.returncode != 0: + raise rpkgError('Command %s returned code %s' % (' '.join(cmd), proc.returncode)) def _verify_file(self, file, hash, hashtype): warn_deprecated(self.__class__.__name__, '_verify_file',