From: Plamen Dimitrov Date: Tue, 26 Mar 2019 07:36:13 +0000 (+0800) Subject: Drop emulation of py3.5+ subprocess module for python 3.3 X-Git-Tag: v1.5~7^2~2 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=40d34f4e186721e38e3487fd231055ac50221a9f;p=pyi2ncommon Drop emulation of py3.5+ subprocess module for python 3.3 The Intra2net system now relies on python 3.7 ridding us of all this extra complexity. --- diff --git a/src/arnied_wrapper.py b/src/arnied_wrapper.py index c2ba2cc..52438bc 100644 --- a/src/arnied_wrapper.py +++ b/src/arnied_wrapper.py @@ -60,7 +60,6 @@ log = logging.getLogger('pyi2ncommon.arnied_wrapper') from .cnfline import build_cnfvar from . import cnfvar from . import sysmisc -from . import call_helpers @@ -100,10 +99,7 @@ def run_cmd(cmd="", ignore_errors=False, vm=None, timeout=60): raise subprocess.CalledProcessError(status, cmd, stderr=stderr) return subprocess.CompletedProcess(cmd, status, stdout=stdout, stderr=stderr) else: - if sys.version_info.major <= 3 and sys.version_info.minor < 5: - return call_helpers.subprocess_run(cmd, check=not ignore_errors, shell=True) - else: - return subprocess.run(cmd, check=not ignore_errors, shell=True, capture_output=True) + return subprocess.run(cmd, check=not ignore_errors, shell=True, capture_output=True) def verify_running(process='arnied', timeout=60, vm=None): diff --git a/src/call_helpers.py b/src/call_helpers.py index ca4e98f..4e945e1 100644 --- a/src/call_helpers.py +++ b/src/call_helpers.py @@ -81,60 +81,3 @@ def call_and_capture(command, stdin_data=None, split_lines=True, stderr_data.splitlines() else: return proc.returncode, stdout_data, stderr_data - - -# Backports of py3.5+ subprocess module - nothing better than to -# remove this and simply use 3.5+ python version on of course. - -class CompletedProcess(object): - """ - Backported minimal class from the py3.5+ subprocess module. - - All arguments are equivalent to the formal subprocess module. - """ - def __init__(self, args, returncode, stdout=None, stderr=None): - self.args = args - self.returncode = returncode - self.stdout = stdout - self.stderr = stderr - - def __repr__(self): - args = ['args={!r}'.format(self.args), - 'returncode={!r}'.format(self.returncode)] - if self.stdout is not None: - args.append('stdout={!r}'.format(self.stdout)) - if self.stderr is not None: - args.append('stderr={!r}'.format(self.stderr)) - return "{}({})".format(type(self).__name__, ', '.join(args)) - - -class CalledProcessError(Exception): - """ - Backported minimal class from the py3.5+ subprocess module. - - All arguments are equivalent to the formal subprocess module. - """ - def __init__(self, returncode, cmd, stderr=None): - self.returncode = returncode - self.cmd = cmd - self.stderr = stderr - - def __str__(self): - return "Command '%s' returned non-zero exit status %d." % ( - self.cmd, self.returncode) - - -def subprocess_run(args, check=True, shell=True, universal_newlines=False): - """ - Backported minimal function from the py3.5+ subprocess module. - - All arguments are equivalent to the formal subprocess module. - """ - command = args if isinstance(args, str) else " ".join(args) - status, stdout, stderr = \ - call_and_capture(command, shell=shell, split_lines=False, - universal_newlines=universal_newlines) - if check and status != 0: - raise CalledProcessError(status, args, stderr=stderr) - else: - return CompletedProcess(args, status, stdout=stdout, stderr=stderr)