1# -*- coding: utf-8 -*- 2 3#------------------------------------------------------------------------- 4# drawElements Quality Program utilities 5# -------------------------------------- 6# 7# Copyright 2015 The Android Open Source Project 8# 9# Licensed under the Apache License, Version 2.0 (the "License"); 10# you may not use this file except in compliance with the License. 11# You may obtain a copy of the License at 12# 13# http://www.apache.org/licenses/LICENSE-2.0 14# 15# Unless required by applicable law or agreed to in writing, software 16# distributed under the License is distributed on an "AS IS" BASIS, 17# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18# See the License for the specific language governing permissions and 19# limitations under the License. 20# 21#------------------------------------------------------------------------- 22 23import os 24import shlex 25import subprocess 26 27DEQP_DIR = os.path.realpath(os.path.normpath(os.path.join(os.path.dirname(__file__), "..", ".."))) 28 29def die (msg): 30 print msg 31 exit(-1) 32 33def shellquote(s): 34 return '"%s"' % s.replace('\\', '\\\\').replace('"', '\"').replace('$', '\$').replace('`', '\`') 35 36g_workDirStack = [] 37 38def pushWorkingDir (path): 39 oldDir = os.getcwd() 40 os.chdir(path) 41 g_workDirStack.append(oldDir) 42 43def popWorkingDir (): 44 assert len(g_workDirStack) > 0 45 newDir = g_workDirStack[-1] 46 g_workDirStack.pop() 47 os.chdir(newDir) 48 49def execute (args): 50 retcode = subprocess.call(args) 51 if retcode != 0: 52 raise Exception("Failed to execute '%s', got %d" % (str(args), retcode)) 53 54def readFile (filename): 55 f = open(filename, 'rb') 56 data = f.read() 57 f.close() 58 return data 59 60def writeFile (filename, data): 61 f = open(filename, 'wb') 62 f.write(data) 63 f.close() 64 65def which (binName): 66 for path in os.environ['PATH'].split(os.pathsep): 67 path = path.strip('"') 68 fullPath = os.path.join(path, binName) 69 if os.path.isfile(fullPath) and os.access(fullPath, os.X_OK): 70 return fullPath 71 72 return None 73