本文整理汇总了Python中os.X_OK属性的典型用法代码示例。如果您正苦于以下问题:Python os.X_OK属性的具体用法?Python os.X_OK怎么用?Python os.X_OK使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类os
的用法示例。
在下文中一共展示了os.X_OK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_executable
# 需要导入模块: import os [as 别名]
# 或者: from os import X_OK [as 别名]
def find_executable(name) -> str:
is_windows = os.name == 'nt'
windows_exts = os.environ['PATHEXT'].split(ENV_PATH_SEP) if is_windows else None
path_dirs = os.environ['PATH'].split(ENV_PATH_SEP)
search_dirs = path_dirs + [os.getcwd()] # cwd is last in the list
for dir in search_dirs:
path = os.path.join(dir, name)
if is_windows:
for extension in windows_exts:
path_with_ext = path + extension
if os.path.isfile(path_with_ext) and os.access(path_with_ext, os.X_OK):
return path_with_ext
else:
if os.path.isfile(path) and os.access(path, os.X_OK):
return path
return ''
示例2: is_executable_available
# 需要导入模块: import os [as 别名]
# 或者: from os import X_OK [as 别名]
def is_executable_available(program):
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath = os.path.dirname(program)
if fpath:
if is_exe(program):
return True
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 True
return False
示例3: which
# 需要导入模块: import os [as 别名]
# 或者: from os import X_OK [as 别名]
def which(program):
"""Locate `program` in PATH
Arguments:
program (str): Name of program, e.g. "python"
"""
def is_exe(fpath):
if os.path.isfile(fpath) and os.access(fpath, os.X_OK):
return True
return False
for path in os.environ["PATH"].split(os.pathsep):
for ext in os.getenv("PATHEXT", "").split(os.pathsep):
fname = program + ext.lower()
abspath = os.path.join(path.strip('"'), fname)
if is_exe(abspath):
return abspath
return None
示例4: which
# 需要导入模块: import os [as 别名]
# 或者: from os import X_OK [as 别名]
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
示例5: which
# 需要导入模块: import os [as 别名]
# 或者: from os import X_OK [as 别名]
def which(program):
import os
def is_exe(f):
return os.path.isfile(f) and os.access(f, 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
示例6: _which
# 需要导入模块: import os [as 别名]
# 或者: from os import X_OK [as 别名]
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
示例7: find_absolute_path
# 需要导入模块: import os [as 别名]
# 或者: from os import X_OK [as 别名]
def find_absolute_path(use_system_path, binary):
global binary_absolute_paths
if binary in binary_absolute_paths:
return binary_absolute_paths[binary]
if use_system_path:
for path in os.environ["PATH"].split(os.pathsep):
target = os.path.join(path.strip('"'), os.path.basename(binary))
if os.path.isfile(target) and os.access(target, os.X_OK):
binary_absolute_paths[binary] = target
return target
target = os.path.join(os.path.dirname(os.path.abspath(__file__)), binary)
if os.path.isfile(target) and os.access(target, os.X_OK):
if use_system_path:
print "WARNING: '%s' not in PATH (using --use-system-path), falling back on locally-compiled binary." % os.path.basename(binary)
binary_absolute_paths[binary] = target
return target
sys.exit("ERROR: '%s' missing, did you run the corresponding setup script?" % (os.path.basename(binary) if use_system_path else target))
示例8: GetCacheDir
# 需要导入模块: import os [as 别名]
# 或者: from os import X_OK [as 别名]
def GetCacheDir(session):
"""Returns the path of a usable cache directory."""
cache_dir = session.GetParameter("cache_dir")
if cache_dir == None:
return cache_dir
cache_dir = os.path.expandvars(cache_dir)
if not cache_dir:
raise io_manager.IOManagerError(
"Local profile cache is not configured - "
"add a cache_dir parameter to ~/.rekallrc.")
# Cache dir may be specified relative to the home directory.
cache_dir = os.path.join(config.GetHomeDir(session), cache_dir)
if not os.access(cache_dir, os.F_OK | os.R_OK | os.W_OK | os.X_OK):
try:
os.makedirs(cache_dir)
except (IOError, OSError):
raise io_manager.IOManagerError(
"Unable to create or access cache directory %s" % cache_dir)
return cache_dir
示例9: run_post_unpack_hook
# 需要导入模块: import os [as 别名]
# 或者: from os import X_OK [as 别名]
def run_post_unpack_hook(post_unpack_hook):
if os.path.isfile(post_unpack_hook):
if os.access(post_unpack_hook, os.X_OK):
logger.info("Running post-unpack-hook: %s" % post_unpack_hook)
retcode = subprocess.call((post_unpack_hook,))
if retcode != 0:
logger.error(
"The post-unpack-hook returned a "
"non-zero exit code: %d" % retcode
)
else:
logger.error(
"post-unpack-hook script %s is not "
"executable." % post_unpack_hook
)
else:
logger.error(
"post-unpack-hook script %s does not exist." % post_unpack_hook
)
示例10: which
# 需要导入模块: import os [as 别名]
# 或者: from os import X_OK [as 别名]
def which(program):
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, _ = 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
示例11: which
# 需要导入模块: import os [as 别名]
# 或者: from os import X_OK [as 别名]
def which(program):
"""
Examine the ``PATH`` environment variable to determine the location for the
specified program. If it can not be found None is returned. This is
fundamentally similar to the Unix utility of the same name.
:param str program: The name of the program to search for.
:return: The absolute path to the program if found.
:rtype: str
"""
is_exe = lambda fpath: (os.path.isfile(fpath) and os.access(fpath, os.X_OK))
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
if is_exe(program):
return os.path.abspath(program)
return None
示例12: _sync_hostnames
# 需要导入模块: import os [as 别名]
# 或者: from os import X_OK [as 别名]
def _sync_hostnames(unified_directory):
directory = os.path.join(unified_directory, 'etc', 'live')
if not os.path.isdir(directory):
logger.warning('can not enumerate available letsencrypt data (directory not found)')
return
if not os.access(directory, os.R_OK | os.X_OK):
logger.warning('can not enumerate available letsencrypt data (invalid permissions)')
return
for subdirectory in os.listdir(directory):
match = _HOSTNAME_DIRECTORY_REGEX.match(subdirectory)
if match is None:
continue
hostname = match.group('hostname')
if hostname in _sni_hostnames:
continue
certfile, keyfile = _get_files(directory, match.group('hostname'))
if not (certfile and keyfile):
continue
set_sni_hostname(hostname, certfile, keyfile)
示例13: get_certbot_bin_path
# 需要导入模块: import os [as 别名]
# 或者: from os import X_OK [as 别名]
def get_certbot_bin_path(config=None):
"""
Get the path to Let's Encrypt's ``certbot`` command line utility. If the
path is found, it is verified to be both a file and executable. If the
path verification fails, ``None`` is returned.
.. versionadded:: 1.14.0
:param config: Configuration to retrieve settings from.
:type config: :py:class:`smoke_zephyr.configuration.Configuration`
:return: The path to the certbot binary.
:rtype: str
"""
if config:
letsencrypt_config = config.get_if_exists('server.letsencrypt', {})
else:
letsencrypt_config = {}
bin_path = letsencrypt_config.get('certbot_path') or startup.which('certbot')
if bin_path is None:
return None
if not os.path.isfile(bin_path):
return None
if not os.access(bin_path, os.R_OK | os.X_OK):
return None
return bin_path
示例14: _popen
# 需要导入模块: import os [as 别名]
# 或者: from os import X_OK [as 别名]
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)
示例15: dump
# 需要导入模块: import os [as 别名]
# 或者: from os import X_OK [as 别名]
def dump(self, url, payload):
# TODO: Ensure a better check for ieee1394/non-cachable address spaces than a bad URL
try:
filename = self.filename(url)
except exceptions.CacheRelativeURLException:
debug.debug("NOT Dumping url {0} - relative URLs are not yet supported".format(url))
return
## Check that the directory exists
directory = os.path.dirname(filename)
if not os.access(directory, os.R_OK | os.W_OK | os.X_OK):
os.makedirs(directory)
## Ensure that the payload is flattened - i.e. all generators are converted to lists for pickling
try:
data = pickle.dumps(payload)
debug.debug("Dumping filename {0}".format(filename))
fd = open(filename, 'w')
fd.write(data)
fd.close()
except (pickle.PickleError, TypeError):
# Do nothing if the pickle fails
debug.debug("NOT Dumping filename {0} - contained a non-picklable class".format(filename))
## This is the central cache object