comparison mercurial/util.py @ 8280:0b02d98d44d0

util: always use subprocess
author Martin Geisler <mg@lazybytes.net>
date Sat, 02 May 2009 23:05:35 +0200
parents e745063b94dd
children 3e1e499db9d7
comparison
equal deleted inserted replaced
8279:602ed4982f36 8280:0b02d98d44d0
42 except ImportError: 42 except ImportError:
43 import sha 43 import sha
44 _sha1 = sha.sha 44 _sha1 = sha.sha
45 return _sha1(s) 45 return _sha1(s)
46 46
47 try: 47 import subprocess
48 import subprocess 48 closefds = os.name == 'posix'
49 subprocess.Popen # trigger ImportError early 49 def popen2(cmd, mode='t', bufsize=-1):
50 closefds = os.name == 'posix' 50 p = subprocess.Popen(cmd, shell=True, bufsize=bufsize,
51 def popen2(cmd, mode='t', bufsize=-1): 51 close_fds=closefds,
52 p = subprocess.Popen(cmd, shell=True, bufsize=bufsize, 52 stdin=subprocess.PIPE, stdout=subprocess.PIPE)
53 close_fds=closefds, 53 return p.stdin, p.stdout
54 stdin=subprocess.PIPE, stdout=subprocess.PIPE) 54 def popen3(cmd, mode='t', bufsize=-1):
55 return p.stdin, p.stdout 55 p = subprocess.Popen(cmd, shell=True, bufsize=bufsize,
56 def popen3(cmd, mode='t', bufsize=-1): 56 close_fds=closefds,
57 p = subprocess.Popen(cmd, shell=True, bufsize=bufsize, 57 stdin=subprocess.PIPE, stdout=subprocess.PIPE,
58 close_fds=closefds, 58 stderr=subprocess.PIPE)
59 stdin=subprocess.PIPE, stdout=subprocess.PIPE, 59 return p.stdin, p.stdout, p.stderr
60 stderr=subprocess.PIPE) 60 def Popen3(cmd, capturestderr=False, bufsize=-1):
61 return p.stdin, p.stdout, p.stderr 61 stderr = capturestderr and subprocess.PIPE or None
62 def Popen3(cmd, capturestderr=False, bufsize=-1): 62 p = subprocess.Popen(cmd, shell=True, bufsize=bufsize,
63 stderr = capturestderr and subprocess.PIPE or None 63 close_fds=closefds,
64 p = subprocess.Popen(cmd, shell=True, bufsize=bufsize, 64 stdin=subprocess.PIPE, stdout=subprocess.PIPE,
65 close_fds=closefds, 65 stderr=stderr)
66 stdin=subprocess.PIPE, stdout=subprocess.PIPE, 66 p.fromchild = p.stdout
67 stderr=stderr) 67 p.tochild = p.stdin
68 p.fromchild = p.stdout 68 p.childerr = p.stderr
69 p.tochild = p.stdin 69 return p
70 p.childerr = p.stderr
71 return p
72 except ImportError:
73 subprocess = None
74 from popen2 import Popen3
75 popen2 = os.popen2
76 popen3 = os.popen3
77
78 70
79 def version(): 71 def version():
80 """Return version information if available.""" 72 """Return version information if available."""
81 try: 73 try:
82 import __version__ 74 import __version__