diff options
author | anatoly techtonik <techtonik@gmail.com> | 2012-12-12 15:02:28 (GMT) |
---|---|---|
committer | anatoly techtonik <techtonik@gmail.com> | 2012-12-12 15:02:28 (GMT) |
commit | 2e3fb8d5b786eec70b69ae2a058581d6fa892bf9 (patch) | |
tree | f73340d6d42635cd7d632826a204df1e2f70da01 /QMTest | |
parent | 58b9a8a944854346f09f0502147429303211f8dc (diff) | |
download | SCons-2e3fb8d5b786eec70b69ae2a058581d6fa892bf9.zip SCons-2e3fb8d5b786eec70b69ae2a058581d6fa892bf9.tar.gz SCons-2e3fb8d5b786eec70b69ae2a058581d6fa892bf9.tar.bz2 |
Remove subprocess compatibility code used for Python < 2.4
Diffstat (limited to 'QMTest')
-rw-r--r-- | QMTest/TestCmd.py | 70 | ||||
-rw-r--r-- | QMTest/TestCmdTests.py | 70 |
2 files changed, 22 insertions, 118 deletions
diff --git a/QMTest/TestCmd.py b/QMTest/TestCmd.py index 708fdc4..0c42ab5 100644 --- a/QMTest/TestCmd.py +++ b/QMTest/TestCmd.py @@ -654,68 +654,20 @@ else: +import subprocess + try: - import subprocess -except ImportError: - # The subprocess module doesn't exist in this version of Python, - # so we're going to cobble up something that looks just enough - # like its API for our purposes below. - import popen2 - subprocess = types.ModuleType('subprocess') - - subprocess.PIPE = 'PIPE' - subprocess.STDOUT = 'STDOUT' - subprocess.mswindows = (sys.platform == 'win32') - - class Popen(popen2.Popen3, popen2.Popen4): - universal_newlines = 1 - def __init__(self, command, **kw): - if kw.get('stderr') == 'STDOUT': - popen2.Popen4.__init__(self, command, 1) - else: - popen2.Popen3.__init__(self, command, 1) - self.stdin = self.tochild - self.stdout = self.fromchild - self.stderr = self.childerr - def communicate(self, input=None): - if input: - self.stdin.write(input) - self.stdin.close() - out = self.stdout.read() - if self.stderr is None: - err = None - else: - err = self.stderr.read() - self.stdout.close() - if self.stderr is not None: - self.stderr.close() - self.returncode = self.wait() - return (out, err) + subprocess.Popen.terminate +except AttributeError: + if sys.platform == 'win32': + import win32process + def terminate(self): + win32process.TerminateProcess(self._handle, 1) + else: def terminate(self): os.kill(self.pid, signal.SIGTERM) - def wait(self, *args, **kw): - resultcode = popen2.Popen3.wait(self, *args, **kw) - if os.WIFSIGNALED(resultcode): - return (- os.WTERMSIG(resultcode)) - elif os.WIFEXITED(resultcode): - return os.WEXITSTATUS(resultcode) - else: - return None - - subprocess.Popen = Popen -else: - try: - subprocess.Popen.terminate - except AttributeError: - if sys.platform == 'win32': - import win32process - def terminate(self): - win32process.TerminateProcess(self._handle, 1) - else: - def terminate(self): - os.kill(self.pid, signal.SIGTERM) - method = types.MethodType(terminate, None, subprocess.Popen) - setattr(subprocess.Popen, 'terminate', method) + method = types.MethodType(terminate, None, subprocess.Popen) + setattr(subprocess.Popen, 'terminate', method) diff --git a/QMTest/TestCmdTests.py b/QMTest/TestCmdTests.py index 1fe328c..1044ed1 100644 --- a/QMTest/TestCmdTests.py +++ b/QMTest/TestCmdTests.py @@ -58,68 +58,20 @@ def _clear_dict(dict, *keys): except KeyError: pass +import subprocess + try: - import subprocess -except ImportError: - # The subprocess module doesn't exist in this version of Python, - # so we're going to cobble up something that looks just enough - # like its API for our purposes below. - import popen2 - subprocess = types.ModuleType('subprocess') - - subprocess.PIPE = 'PIPE' - subprocess.STDOUT = 'STDOUT' - subprocess.mswindows = (sys.platform == 'win32') - - class Popen(popen2.Popen3, popen2.Popen4): - universal_newlines = 1 - def __init__(self, command, **kw): - if kw.get('stderr') == 'STDOUT': - popen2.Popen4.__init__(self, command, 1) - else: - popen2.Popen3.__init__(self, command, 1) - self.stdin = self.tochild - self.stdout = self.fromchild - self.stderr = self.childerr - def communicate(self, input=None): - if input: - self.stdin.write(input) - self.stdin.close() - out = self.stdout.read() - if self.stderr is None: - err = None - else: - err = self.stderr.read() - self.stdout.close() - if self.stderr is not None: - self.stderr.close() - self.returncode = self.wait() - return (out, err) + subprocess.Popen.terminate +except AttributeError: + if sys.platform == 'win32': + import win32process + def terminate(self): + win32process.TerminateProcess(self._handle, 1) + else: def terminate(self): os.kill(self.pid, signal.SIGTERM) - def wait(self, *args, **kw): - resultcode = popen2.Popen3.wait(self, *args, **kw) - if os.WIFEXITED(resultcode): - return os.WEXITSTATUS(resultcode) - elif os.WIFSIGNALED(resultcode): - return os.WTERMSIG(resultcode) - else: - return None - - subprocess.Popen = Popen -else: - try: - subprocess.Popen.terminate - except AttributeError: - if sys.platform == 'win32': - import win32process - def terminate(self): - win32process.TerminateProcess(self._handle, 1) - else: - def terminate(self): - os.kill(self.pid, signal.SIGTERM) - method = types.MethodType(terminate, None, subprocess.Popen) - setattr(subprocess.Popen, 'terminate', method) + method = types.MethodType(terminate, None, subprocess.Popen) + setattr(subprocess.Popen, 'terminate', method) class ExitError(Exception): pass |