tests/hghave.py
changeset 41388 fabb0224a599
parent 41013 87c98ffbc8c7
child 41403 423a6b2ddafa
equal deleted inserted replaced
41387:876494fd967d 41388:fabb0224a599
     1 from __future__ import absolute_import
     1 from __future__ import absolute_import
     2 
     2 
     3 import errno
       
     4 import os
     3 import os
     5 import re
     4 import re
     6 import socket
     5 import socket
     7 import stat
     6 import stat
     8 import subprocess
     7 import subprocess
   116 def matchoutput(cmd, regexp, ignorestatus=False):
   115 def matchoutput(cmd, regexp, ignorestatus=False):
   117     """Return the match object if cmd executes successfully and its output
   116     """Return the match object if cmd executes successfully and its output
   118     is matched by the supplied regular expression.
   117     is matched by the supplied regular expression.
   119     """
   118     """
   120     r = re.compile(regexp)
   119     r = re.compile(regexp)
   121     try:
   120     p = subprocess.Popen(
   122         p = subprocess.Popen(
   121         cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
   123             cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
       
   124     except OSError as e:
       
   125         if e.errno != errno.ENOENT:
       
   126             raise
       
   127         ret = -1
       
   128     s = p.communicate()[0]
   122     s = p.communicate()[0]
   129     ret = p.returncode
   123     ret = p.returncode
   130     return (ignorestatus or not ret) and r.search(s)
   124     return (ignorestatus or not ret) and r.search(s)
   131 
   125 
   132 @check("baz", "GNU Arch baz client")
   126 @check("baz", "GNU Arch baz client")