def run_all(self):
# check that a compiled binary exists to run on the testcases
argv = os.path.abspath(os.path.join(self.answer_dir, self.run_program))
if not (os.path.isfile(argv) and os.access(argv, os.X_OK)):
logging.error("executable missing: {0}".format(argv))
print >>sys.stderr, "Compile your source file to create an executable {0}".format(argv)
sys.exit(1)
# check if testcases has subdirectories
testcase_subdirs = iocollect.getdirs(os.path.abspath(self.testcase_dir))
if len(testcase_subdirs) > 0:
for subdir in testcase_subdirs:
files = iocollect.getfiles(os.path.abspath(os.path.join(self.testcase_dir, subdir)))
self.run_path(subdir, files)
else:
files = iocollect.getfiles(os.path.abspath(self.testcase_dir))
self.run_path(None, files)
return True
python类X_OK的实例源码
def run_all(self):
# check that a compiled binary exists to run on the testcases
argv = os.path.abspath(os.path.join(self.answer_dir, self.run_program))
if not (os.path.isfile(argv) and os.access(argv, os.X_OK)):
logging.error("executable missing: {}".format(argv))
print >>sys.stderr, "Compile your source file to create an executable {}".format(argv)
sys.exit(1)
# check if testcases has subdirectories
testcase_subdirs = iocollect.getdirs(os.path.abspath(self.testcase_dir))
if len(testcase_subdirs) > 0:
for subdir in testcase_subdirs:
files = iocollect.getfiles(os.path.abspath(os.path.join(self.testcase_dir, subdir)))
self.run_path(subdir, files)
else:
files = iocollect.getfiles(os.path.abspath(self.testcase_dir))
self.run_path(None, files)
return True
def run_all(self):
# check that a compiled binary exists to run on the testcases
argv = os.path.abspath(os.path.join(self.answer_dir, self.run_program))
if not (os.path.isfile(argv) and os.access(argv, os.X_OK)):
logging.error("executable missing: {0}".format(argv))
print >>sys.stderr, "Compile your source file to create an executable {0}".format(argv)
sys.exit(1)
# check if testcases has subdirectories
testcase_subdirs = iocollect.getdirs(os.path.abspath(self.testcase_dir))
if len(testcase_subdirs) > 0:
for subdir in testcase_subdirs:
files = iocollect.getfiles(os.path.abspath(os.path.join(self.testcase_dir, subdir)))
self.run_path(subdir, files)
else:
files = iocollect.getfiles(os.path.abspath(self.testcase_dir))
self.run_path(None, files)
return True
def run_all(self):
# check that a compiled binary exists to run on the testcases
argv = os.path.abspath(os.path.join(self.answer_dir, self.run_program))
if not (os.path.isfile(argv) and os.access(argv, os.X_OK)):
logging.error("executable missing: {0}".format(argv))
print >>sys.stderr, "Compile your source file to create an executable {0}".format(argv)
sys.exit(1)
# check if testcases has subdirectories
testcase_subdirs = iocollect.getdirs(os.path.abspath(self.testcase_dir))
if len(testcase_subdirs) > 0:
for subdir in testcase_subdirs:
files = iocollect.getfiles(os.path.abspath(os.path.join(self.testcase_dir, subdir)))
self.run_path(subdir, files)
else:
files = iocollect.getfiles(os.path.abspath(self.testcase_dir))
self.run_path(None, files)
return True
def run_all(self):
# check that a compiled binary exists to run on the testcases
argv = os.path.abspath(os.path.join(self.answer_dir, self.run_program))
if not (os.path.isfile(argv) and os.access(argv, os.X_OK)):
logging.error("executable missing: {}".format(argv))
print >>sys.stderr, "Compile your source file to create an executable {}".format(argv)
sys.exit(1)
# check if testcases has subdirectories
testcase_subdirs = iocollect.getdirs(os.path.abspath(self.testcase_dir))
if len(testcase_subdirs) > 0:
for subdir in testcase_subdirs:
files = iocollect.getfiles(os.path.abspath(os.path.join(self.testcase_dir, subdir)))
self.run_path(subdir, files)
else:
files = iocollect.getfiles(os.path.abspath(self.testcase_dir))
self.run_path(None, files)
return True
def run_all(self):
# check that a compiled binary exists to run on the testcases
argv = os.path.abspath(os.path.join(self.answer_dir, self.run_program))
if not (os.path.isfile(argv) and os.access(argv, os.X_OK)):
logging.error("executable missing: {}".format(argv))
print >>sys.stderr, "Compile your source file to create an executable {}".format(argv)
sys.exit(1)
# check if testcases has subdirectories
testcase_subdirs = iocollect.getdirs(os.path.abspath(self.testcase_dir))
if len(testcase_subdirs) > 0:
for subdir in testcase_subdirs:
files = iocollect.getfiles(os.path.abspath(os.path.join(self.testcase_dir, subdir)))
self.run_path(subdir, files)
else:
files = iocollect.getfiles(os.path.abspath(self.testcase_dir))
self.run_path(None, files)
return True
def which(program):
"""
Checks if executable exists and is on the path.
Thanks http://stackoverflow.com/a/377028/119592
"""
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
def which(program):
import os
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
def which(program):
""" Emulates the unix ``which`` command. Snatched from:
`http://stackoverflow.com/questions/377017/
test-if-executable-exists-in-python`
:param program: executable
:type program: string
:returns: path-to-executable or None
"""
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
def py_where(program, path=None):
# From: http://stackoverflow.com/a/377028/548792
try:
winprog_exts = tuple(p.upper() for p in os.environ['PATHEXT'].split(os.pathsep))
except:
winprog_exts = is_win and ('.BAT', 'COM', '.EXE') or ()
def is_exec(fpath):
return osp.isfile(fpath) and os.access(fpath, os.X_OK) and (
os.name != 'nt' or not winprog_exts or any(fpath.upper().endswith(ext)
for ext in winprog_exts))
progs = []
if not path:
path = os.environ["PATH"]
for folder in path.split(os.pathsep):
folder = folder.strip('"')
if folder:
exe_path = osp.join(folder, program)
for f in [exe_path] + ['%s%s' % (exe_path, e) for e in winprog_exts]:
if is_exec(f):
progs.append(f)
return progs
def which(program):
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
def which(program):
"""
Check if a program/executable exists
:param program:
:return:
"""
def is_exe(f_path):
return os.path.isfile(f_path) and os.access(f_path, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
def _popen(command, args):
import os
path = os.environ.get("PATH", os.defpath).split(os.pathsep)
path.extend(('/sbin', '/usr/sbin'))
for dir in path:
executable = os.path.join(dir, command)
if (os.path.exists(executable) and
os.access(executable, os.F_OK | os.X_OK) and
not os.path.isdir(executable)):
break
else:
return None
# LC_ALL to ensure English output, 2>/dev/null to prevent output on
# stderr (Note: we don't have an example where the words we search for
# are actually localized, but in theory some system could do so.)
cmd = 'LC_ALL=C %s %s 2>/dev/null' % (executable, args)
return os.popen(cmd)
def _which(program):
import os
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
def which(program):
"""Determine full path of executable *program* on :envvar:`PATH`.
(Jay at http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python)
"""
def is_exe(fpath):
"""
Returns True is the path points to an executable file.
"""
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, _ = os.path.split(program)
if fpath:
real_program = realpath(program)
if is_exe(real_program):
return real_program
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
def _popen(command, args):
import os
path = os.environ.get("PATH", os.defpath).split(os.pathsep)
path.extend(('/sbin', '/usr/sbin'))
for dir in path:
executable = os.path.join(dir, command)
if (os.path.exists(executable) and
os.access(executable, os.F_OK | os.X_OK) and
not os.path.isdir(executable)):
break
else:
return None
# LC_ALL to ensure English output, 2>/dev/null to prevent output on
# stderr (Note: we don't have an example where the words we search for
# are actually localized, but in theory some system could do so.)
cmd = 'LC_ALL=C %s %s 2>/dev/null' % (executable, args)
return os.popen(cmd)
def ensure_requirements(self):
"""Make sure kubectl and minikube are available."""
uname = run_result("uname").lower()
for path, url in zip([MINIKUBE, KUBECTL], [
"https://storage.googleapis.com/minikube/releases/"
"v0.15.0/minikube-{}-amd64",
"https://storage.googleapis.com/kubernetes-release/"
"release/v1.5.1/bin/{}/amd64/kubectl"
]):
if path.exists() and not os.access(str(path), os.X_OK):
# Apparently failed halfway through previous download
os.remove(str(path))
if not path.exists():
self.echo("Downloading {}...".format(path.name))
check_call([
"curl", "--create-dirs", "--silent", "--output", str(path),
url.format(uname)
])
path.chmod(0o755)
def _which(program):
import os
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
def _popen(command, args):
import os
path = os.environ.get("PATH", os.defpath).split(os.pathsep)
path.extend(('/sbin', '/usr/sbin'))
for dir in path:
executable = os.path.join(dir, command)
if (os.path.exists(executable) and
os.access(executable, os.F_OK | os.X_OK) and
not os.path.isdir(executable)):
break
else:
return None
# LC_ALL to ensure English output, 2>/dev/null to prevent output on
# stderr (Note: we don't have an example where the words we search for
# are actually localized, but in theory some system could do so.)
cmd = 'LC_ALL=C %s %s 2>/dev/null' % (executable, args)
return os.popen(cmd)
def _popen(command, args):
import os
path = os.environ.get("PATH", os.defpath).split(os.pathsep)
path.extend(('/sbin', '/usr/sbin'))
for dir in path:
executable = os.path.join(dir, command)
if (os.path.exists(executable) and
os.access(executable, os.F_OK | os.X_OK) and
not os.path.isdir(executable)):
break
else:
return None
# LC_ALL to ensure English output, 2>/dev/null to prevent output on
# stderr (Note: we don't have an example where the words we search for
# are actually localized, but in theory some system could do so.)
cmd = 'LC_ALL=C %s %s 2>/dev/null' % (executable, args)
return os.popen(cmd)