# HG changeset patch # User Martin Geisler # Date 2009-05-02 21:05:35 # Node ID 0b02d98d44d00cbf0a3b164ea6e4056e9e97032f # Parent 602ed4982f36203309511940a9081d1454bc45c5 util: always use subprocess diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -44,37 +44,29 @@ def sha1(s): _sha1 = sha.sha return _sha1(s) -try: - import subprocess - subprocess.Popen # trigger ImportError early - closefds = os.name == 'posix' - def popen2(cmd, mode='t', bufsize=-1): - p = subprocess.Popen(cmd, shell=True, bufsize=bufsize, - close_fds=closefds, - stdin=subprocess.PIPE, stdout=subprocess.PIPE) - return p.stdin, p.stdout - def popen3(cmd, mode='t', bufsize=-1): - p = subprocess.Popen(cmd, shell=True, bufsize=bufsize, - close_fds=closefds, - stdin=subprocess.PIPE, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - return p.stdin, p.stdout, p.stderr - def Popen3(cmd, capturestderr=False, bufsize=-1): - stderr = capturestderr and subprocess.PIPE or None - p = subprocess.Popen(cmd, shell=True, bufsize=bufsize, - close_fds=closefds, - stdin=subprocess.PIPE, stdout=subprocess.PIPE, - stderr=stderr) - p.fromchild = p.stdout - p.tochild = p.stdin - p.childerr = p.stderr - return p -except ImportError: - subprocess = None - from popen2 import Popen3 - popen2 = os.popen2 - popen3 = os.popen3 - +import subprocess +closefds = os.name == 'posix' +def popen2(cmd, mode='t', bufsize=-1): + p = subprocess.Popen(cmd, shell=True, bufsize=bufsize, + close_fds=closefds, + stdin=subprocess.PIPE, stdout=subprocess.PIPE) + return p.stdin, p.stdout +def popen3(cmd, mode='t', bufsize=-1): + p = subprocess.Popen(cmd, shell=True, bufsize=bufsize, + close_fds=closefds, + stdin=subprocess.PIPE, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + return p.stdin, p.stdout, p.stderr +def Popen3(cmd, capturestderr=False, bufsize=-1): + stderr = capturestderr and subprocess.PIPE or None + p = subprocess.Popen(cmd, shell=True, bufsize=bufsize, + close_fds=closefds, + stdin=subprocess.PIPE, stdout=subprocess.PIPE, + stderr=stderr) + p.fromchild = p.stdout + p.tochild = p.stdin + p.childerr = p.stderr + return p def version(): """Return version information if available.""" diff --git a/tests/run-tests.py b/tests/run-tests.py --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -11,28 +11,24 @@ import difflib import errno import optparse import os -try: - import subprocess - subprocess.Popen # trigger ImportError early - closefds = os.name == 'posix' - def Popen4(cmd, bufsize=-1): - p = subprocess.Popen(cmd, shell=True, bufsize=bufsize, - close_fds=closefds, - stdin=subprocess.PIPE, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT) - p.fromchild = p.stdout - p.tochild = p.stdin - p.childerr = p.stderr - return p -except ImportError: - subprocess = None - from popen2 import Popen4 +import subprocess import shutil import signal import sys import tempfile import time +closefds = os.name == 'posix' +def Popen4(cmd, bufsize=-1): + p = subprocess.Popen(cmd, shell=True, bufsize=bufsize, + close_fds=closefds, + stdin=subprocess.PIPE, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) + p.fromchild = p.stdout + p.tochild = p.stdin + p.childerr = p.stderr + return p + # reserved exit code to skip test (used by hghave) SKIPPED_STATUS = 80 SKIPPED_PREFIX = 'skipped: '