##// END OF EJS Templates
util: always use subprocess
Martin Geisler -
r8280:0b02d98d default
parent child Browse files
Show More
@@ -44,37 +44,29 b' def sha1(s):'
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."""
@@ -11,28 +11,24 b' import difflib'
11 import errno
11 import errno
12 import optparse
12 import optparse
13 import os
13 import os
14 try:
14 import subprocess
15 import subprocess
16 subprocess.Popen # trigger ImportError early
17 closefds = os.name == 'posix'
18 def Popen4(cmd, bufsize=-1):
19 p = subprocess.Popen(cmd, shell=True, bufsize=bufsize,
20 close_fds=closefds,
21 stdin=subprocess.PIPE, stdout=subprocess.PIPE,
22 stderr=subprocess.STDOUT)
23 p.fromchild = p.stdout
24 p.tochild = p.stdin
25 p.childerr = p.stderr
26 return p
27 except ImportError:
28 subprocess = None
29 from popen2 import Popen4
30 import shutil
15 import shutil
31 import signal
16 import signal
32 import sys
17 import sys
33 import tempfile
18 import tempfile
34 import time
19 import time
35
20
21 closefds = os.name == 'posix'
22 def Popen4(cmd, bufsize=-1):
23 p = subprocess.Popen(cmd, shell=True, bufsize=bufsize,
24 close_fds=closefds,
25 stdin=subprocess.PIPE, stdout=subprocess.PIPE,
26 stderr=subprocess.STDOUT)
27 p.fromchild = p.stdout
28 p.tochild = p.stdin
29 p.childerr = p.stderr
30 return p
31
36 # reserved exit code to skip test (used by hghave)
32 # reserved exit code to skip test (used by hghave)
37 SKIPPED_STATUS = 80
33 SKIPPED_STATUS = 80
38 SKIPPED_PREFIX = 'skipped: '
34 SKIPPED_PREFIX = 'skipped: '
General Comments 0
You need to be logged in to leave comments. Login now