當前位置: 首頁>>代碼示例>>Python>>正文


Python os.X_OK屬性代碼示例

本文整理匯總了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 '' 
開發者ID:godotengine,項目名稱:godot-mono-builds,代碼行數:23,代碼來源:os_utils.py

示例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 
開發者ID:ethereum,項目名稱:py-solc,代碼行數:18,代碼來源:install_solc.py

示例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 
開發者ID:getavalon,項目名稱:core,代碼行數:24,代碼來源:lib.py

示例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 
開發者ID:BD2KGenomics,項目名稱:toil-scripts,代碼行數:20,代碼來源:rnaseq_unc_tcga_versions.py

示例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 
開發者ID:BD2KGenomics,項目名稱:toil-scripts,代碼行數:20,代碼來源:rnaseq_unc_pipeline.py

示例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 
開發者ID:CharlesShang,項目名稱:TFFRCNN,代碼行數:19,代碼來源:__init__.py

示例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)) 
開發者ID:google,項目名稱:rtc-video-quality,代碼行數:21,代碼來源:generate_data.py

示例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 
開發者ID:google,項目名稱:rekall,代碼行數:26,代碼來源:cache.py

示例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
        ) 
開發者ID:mendix,項目名稱:cf-mendix-buildpack,代碼行數:21,代碼來源:util.py

示例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 
開發者ID:izacus,項目名稱:RoboGif,代碼行數:19,代碼來源:utilities.py

示例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 
開發者ID:rsmusllp,項目名稱:king-phisher,代碼行數:21,代碼來源:startup.py

示例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) 
開發者ID:rsmusllp,項目名稱:king-phisher,代碼行數:21,代碼來源:letsencrypt.py

示例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 
開發者ID:rsmusllp,項目名稱:king-phisher,代碼行數:27,代碼來源:letsencrypt.py

示例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) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:19,代碼來源:uuid.py

示例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 
開發者ID:virtualrealitysystems,項目名稱:aumfor,代碼行數:27,代碼來源:cache.py


注:本文中的os.X_OK屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。