From 969c37abd4d874e10e8ce0786ce5c97a0b816ec7 Mon Sep 17 00:00:00 2001 From: Stijn Seghers Date: Sun, 10 Apr 2016 16:20:04 +0200 Subject: [PATCH] Fix backports, fixes #91 --- battlebots/backports.py | 16 ++++++---------- battlebots/database/models.py | 6 +++--- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/battlebots/backports.py b/battlebots/backports.py index bd5adbf..525fa86 100644 --- a/battlebots/backports.py +++ b/battlebots/backports.py @@ -39,16 +39,18 @@ def sp_run(*popenargs, input=None, timeout=None, check=False, **kwargs): except sp.TimeoutExpired: process.kill() stdout, stderr = process.communicate() - raise sp.TimeoutExpired(process.args, timeout, output=stdout, - stderr=stderr) + err = sp.TimeoutExpired(process.args, timeout, output=stdout) + err.stderr = stderr + raise err except: process.kill() process.wait() raise retcode = process.poll() if check and retcode: - raise sp.CalledProcessError(retcode, process.args, output=stdout, - stderr=stderr) + err = sp.CalledProcessError(retcode, process.args, output=stdout) + err.stderr = stderr + raise err return CompletedProcess(process.args, retcode, stdout, stderr) @@ -77,9 +79,3 @@ def __repr__(self): if self.stderr is not None: args.append('stderr={!r}'.format(self.stderr)) return "{}({})".format(type(self).__name__, ', '.join(args)) - - def check_returncode(self): - """Raise CalledProcessError if the exit code is non-zero.""" - if self.returncode: - raise sp.CalledProcessError(self.returncode, self.args, - self.stdout, self.stderr) diff --git a/battlebots/database/models.py b/battlebots/database/models.py index de9f193..f64cd04 100644 --- a/battlebots/database/models.py +++ b/battlebots/database/models.py @@ -137,10 +137,10 @@ def compile(self, timeout=20): self.compiled = True return True except sp.SubprocessError as error: - error = '{error}\nStdout: {stdout}Stderr: {stderr}'.format( + error = '{error}\nStdout: {stdout}\nStderr: {stderr}'.format( error=error, - stdout=error.stdout.decode('utf8'), - stderr=error.stderr.decode('utf8')) + stdout=error.stdout.decode('utf8').rstrip(), + stderr=error.stderr.decode('utf8').rstrip()) logging.warning(error) self.compile_errors = error return False