summaryrefslogtreecommitdiff
path: root/buildscripts/utils.py
diff options
context:
space:
mode:
authorDan Crosta <dcrosta@10gen.com>2012-02-16 21:49:02 -0500
committerDan Crosta <dcrosta@10gen.com>2012-02-16 21:49:02 -0500
commit31991afed8aa8302d649b6079ab9c6dd0d52650c (patch)
tree7216abbc6af8ba5a8df982b40969a826c8edea95 /buildscripts/utils.py
parent7cf238c22c663ee87bcc2a5ff2416cd5cb41f5a4 (diff)
downloadmongo-31991afed8aa8302d649b6079ab9c6dd0d52650c.tar.gz
ALL smoke.py invocations are done through smoke_command()
This function returns a string command with fully qualified paths to a valid (>= 2.5) Python interpreter and to the smoke.py file.
Diffstat (limited to 'buildscripts/utils.py')
-rw-r--r--buildscripts/utils.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/buildscripts/utils.py b/buildscripts/utils.py
index 8021d8779da..d293d89c4e3 100644
--- a/buildscripts/utils.py
+++ b/buildscripts/utils.py
@@ -3,6 +3,10 @@ import re
import socket
import time
import os
+import os.path
+import itertools
+import subprocess
+import sys
# various utilities that are handy
def getAllSourceFiles( arr=None , prefix="." ):
@@ -134,3 +138,47 @@ def didMongodStart( port=27017 , timeout=20 ):
timeout = timeout - 1
return False
+def which(executable):
+ if sys.platform == 'win32':
+ paths = os.environ.get('Path', '').split(';')
+ else:
+ paths = os.environ.get('PATH', '').split(':')
+
+ for path in paths:
+ path = os.path.expandvars(path)
+ path = os.path.expanduser(path)
+ path = os.path.abspath(path)
+ executable_path = os.path.join(path, executable)
+ if os.path.exists(executable_path):
+ return executable_path
+
+ return executable
+
+def find_python(min_version=(2, 5)):
+ # if this script is being run by py2.5 or greater,
+ # then we assume that "python" points to a 2.5 or
+ # greater python VM. otherwise, explicitly use 2.5
+ # which we assume to be installed.
+ version = re.compile(r'[Pp]ython ([\d\.]+)', re.MULTILINE)
+ binaries = ('python27', 'python2.7', 'python26', 'python2.6', 'python25', 'python2.5', 'python')
+ for binary in binaries:
+ try:
+ out, err = subprocess.Popen([binary, '-V'], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
+ for stream in (out, err):
+ match = version.search(stream)
+ if match:
+ versiontuple = tuple(map(int, match.group(1).split('.')))
+ if versiontuple >= (2, 5):
+ return which(binary)
+ except:
+ pass
+
+ raise Exception('could not find suitable Python (version >= %s)' % '.'.join(min_version))
+
+def smoke_command(*args):
+ here = os.path.dirname(__file__)
+ smoke_py = os.path.join(here, 'smoke.py')
+ return ' '.join(itertools.chain(
+ (find_python(), smoke_py),
+ args))
+