Merging upstream version 0.15.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
470a4841cc
commit
3213982697
75 changed files with 1281 additions and 1555 deletions
20
qa/shell.py
20
qa/shell.py
|
@ -3,10 +3,11 @@
|
|||
# on gitlint internals for our integration testing framework.
|
||||
|
||||
import subprocess
|
||||
from qa.utils import ustr, USE_SH_LIB, IS_PY2
|
||||
from qa.utils import USE_SH_LIB, DEFAULT_ENCODING
|
||||
|
||||
if USE_SH_LIB:
|
||||
from sh import git, echo, gitlint # pylint: disable=unused-import,no-name-in-module,import-error
|
||||
gitlint = gitlint.bake(_unify_ttys=True, _tty_in=True) # pylint: disable=invalid-name
|
||||
|
||||
# import exceptions separately, this makes it a little easier to mock them out in the unit tests
|
||||
from sh import CommandNotFound, ErrorReturnCode, RunningCommand # pylint: disable=import-error
|
||||
|
@ -16,7 +17,7 @@ else:
|
|||
""" Exception indicating a command was not found during execution """
|
||||
pass
|
||||
|
||||
class RunningCommand(object):
|
||||
class RunningCommand:
|
||||
pass
|
||||
|
||||
class ShResult(RunningCommand):
|
||||
|
@ -27,7 +28,7 @@ else:
|
|||
self.full_cmd = full_cmd
|
||||
# TODO(jorisroovers): The 'sh' library by default will merge stdout and stderr. We mimic this behavior
|
||||
# for now until we fully remove the 'sh' library.
|
||||
self.stdout = stdout + ustr(stderr)
|
||||
self.stdout = stdout + stderr.decode(DEFAULT_ENCODING)
|
||||
self.stderr = stderr
|
||||
self.exit_code = exitcode
|
||||
|
||||
|
@ -55,14 +56,9 @@ else:
|
|||
# a non-zero exit code -> just return the entire result
|
||||
if hasattr(result, 'exit_code') and result.exit_code > 0:
|
||||
return result
|
||||
return ustr(result)
|
||||
return str(result)
|
||||
|
||||
def _exec(*args, **kwargs):
|
||||
if IS_PY2:
|
||||
no_command_error = OSError # noqa pylint: disable=undefined-variable,invalid-name
|
||||
else:
|
||||
no_command_error = FileNotFoundError # noqa pylint: disable=undefined-variable
|
||||
|
||||
pipe = subprocess.PIPE
|
||||
popen_kwargs = {'stdout': pipe, 'stderr': pipe, 'shell': kwargs.get('_tty_out', False)}
|
||||
if '_cwd' in kwargs:
|
||||
|
@ -73,11 +69,11 @@ else:
|
|||
try:
|
||||
p = subprocess.Popen(args, **popen_kwargs)
|
||||
result = p.communicate()
|
||||
except no_command_error:
|
||||
raise CommandNotFound
|
||||
except FileNotFoundError as exc:
|
||||
raise CommandNotFound from exc
|
||||
|
||||
exit_code = p.returncode
|
||||
stdout = ustr(result[0])
|
||||
stdout = result[0].decode(DEFAULT_ENCODING)
|
||||
stderr = result[1] # 'sh' does not decode the stderr bytes to unicode
|
||||
full_cmd = '' if args is None else ' '.join(args)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue