changeset 26137:99e8a9ff1f5f

hghave: use subprocess instead of os.popen os.popen was deprecated in Python 2.6 in favor of subprocess, so let's move into the future.
author Augie Fackler <augie@google.com>
date Mon, 31 Aug 2015 22:44:20 -0400
parents 6defc74f3066
children f77a3f27cea5
files tests/hghave.py
diffstat 1 files changed, 13 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/tests/hghave.py	Sat Aug 22 15:12:52 2015 -0700
+++ b/tests/hghave.py	Mon Aug 31 22:44:20 2015 -0400
@@ -1,6 +1,9 @@
-import os, stat
+import errno
+import os
 import re
 import socket
+import stat
+import subprocess
 import sys
 import tempfile
 
@@ -69,14 +72,16 @@
     is matched by the supplied regular expression.
     """
     r = re.compile(regexp)
-    fh = os.popen(cmd)
-    s = fh.read()
     try:
-        ret = fh.close()
-    except IOError:
-        # Happen in Windows test environment
-        ret = 1
-    return (ignorestatus or ret is None) and r.search(s)
+        p = subprocess.Popen(
+            cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+    except OSError as e:
+        if e.errno != errno.ENOENT:
+            raise
+        ret = -1
+    ret = p.wait()
+    s = p.stdout.read()
+    return (ignorestatus or not ret) and r.search(s)
 
 @check("baz", "GNU Arch baz client")
 def has_baz():