[PATCH] python2.6: use subprocess if available
Dirkjan Ochtman
dirkjan at ochtman.nl
Sun Oct 5 19:39:59 UTC 2008
# HG changeset patch
# User Dirkjan Ochtman <dirkjan at ochtman.nl>
# Date 1223235326 -7200
# Node ID 070d038a50c52cedcdc8209895237744a045ce13
# Parent 8b874f8cd29f46f9412cf97352cc5ba5528f10f3
python2.6: use subprocess if available
diff --git a/hgext/convert/cvs.py b/hgext/convert/cvs.py
--- a/hgext/convert/cvs.py
+++ b/hgext/convert/cvs.py
@@ -252,7 +252,7 @@
# popen2 does not support argument lists under Windows
cmd = [util.shellquote(arg) for arg in cmd]
cmd = util.quotecommand(' '.join(cmd))
- self.writep, self.readp = os.popen2(cmd, 'b')
+ self.writep, self.readp = util.popen2(cmd, 'b')
self.realroot = root
diff --git a/hgext/convert/subversion.py b/hgext/convert/subversion.py
--- a/hgext/convert/subversion.py
+++ b/hgext/convert/subversion.py
@@ -912,7 +912,7 @@
arg = encodeargs(args)
hgexe = util.hgexecutable()
cmd = '%s debugsvnlog' % util.shellquote(hgexe)
- stdin, stdout = os.popen2(cmd, 'b')
+ stdin, stdout = util.popen2(cmd, 'b')
stdin.write(arg)
stdin.close()
return logstream(stdout)
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -9,7 +9,7 @@
from i18n import _
from node import hex, nullid, short
import base85, cmdutil, mdiff, util, revlog, diffhelpers, copies
-import cStringIO, email.Parser, os, popen2, re, errno
+import cStringIO, email.Parser, os, re, errno
import sys, tempfile, zlib
class PatchError(Exception):
@@ -1311,7 +1311,7 @@
return
fd, name = tempfile.mkstemp(prefix="hg-patchbomb-", suffix=".txt")
try:
- p = popen2.Popen3('diffstat -p1 -w79 2>/dev/null > ' + name)
+ p = util.Popen3('diffstat -p1 -w79 2>/dev/null > ' + name)
try:
for line in patchlines:
p.tochild.write(line + "\n")
diff --git a/mercurial/sshrepo.py b/mercurial/sshrepo.py
--- a/mercurial/sshrepo.py
+++ b/mercurial/sshrepo.py
@@ -61,7 +61,7 @@
cmd = util.quotecommand(cmd)
ui.note(_('running %s\n') % cmd)
- self.pipeo, self.pipei, self.pipee = os.popen3(cmd, 'b')
+ self.pipeo, self.pipei, self.pipee = util.popen3(cmd, 'b')
# skip any noise generated by remote shell
self.do_cmd("hello")
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -48,6 +48,33 @@
import sha
_sha1 = sha.sha
return _sha1(s)
+
+try:
+ import subprocess
+ def popen2(cmd, mode='t', bufsize=-1):
+ p = subprocess.Popen(cmd, shell=True, bufsize=bufsize, close_fds=True,
+ 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=True,
+ 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=True,
+ 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
+ import popen2 as _popen2
+ popen2 = _popen2.popen2
+ Popen3 = _popen2.Popen3
+
try:
_encoding = os.environ.get("HGENCODING")
@@ -183,7 +210,7 @@
def pipefilter(s, cmd):
'''filter string S through command CMD, returning its output'''
- (pin, pout) = os.popen2(cmd, 'b')
+ (pin, pout) = popen2(cmd, 'b')
def writer():
try:
pin.write(s)
More information about the Mercurial-devel
mailing list