Python os 模块,pathsep() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用os.pathsep()

项目:my-first-blog    作者:AnkurBegining    | 项目源码 | 文件源码
def _pythonpath():
    items = os.environ.get('PYTHONPATH', '').split(os.pathsep)
    return filter(None, items)
项目:howmanypeoplearearound    作者:wi-fi-analyzer    | 项目源码 | 文件源码
def which(program):
    """Determines whether program exists
    """
    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
    raise
项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
def site_config_dirs(appname):
    """Return a list of potential user-shared config dirs for this application.

        "appname" is the name of application.

    Typical user config directories are:
        macOS:      /Library/Application Support/<AppName>/
        Unix:       /etc or $XDG_CONFIG_DIRS[i]/<AppName>/ for each value in
                    $XDG_CONFIG_DIRS
        Win XP:     C:\Documents and Settings\All Users\Application ...
                    ...Data\<AppName>\
        Vista:      (Fail! "C:\ProgramData" is a hidden *system* directory
                    on Vista.)
        Win 7:      Hidden, but writeable on Win 7:
                    C:\ProgramData\<AppName>\
    """
    if WINDOWS:
        path = os.path.normpath(_get_win_folder("CSIDL_COMMON_APPDATA"))
        pathlist = [os.path.join(path, appname)]
    elif sys.platform == 'darwin':
        pathlist = [os.path.join('/Library/Application Support', appname)]
    else:
        # try looking in $XDG_CONFIG_DIRS
        xdg_config_dirs = os.getenv('XDG_CONFIG_DIRS', '/etc/xdg')
        if xdg_config_dirs:
            pathlist = [
                os.path.join(expanduser(x), appname)
                for x in xdg_config_dirs.split(os.pathsep)
            ]
        else:
            pathlist = []

        # always look in /etc directly as well
        pathlist.append('/etc')

    return pathlist


# -- Windows support functions --
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def finalize_options(self):
        # This might be confusing: both build-clib and build-temp default
        # to build-temp as defined by the "build" command.  This is because
        # I think that C libraries are really just temporary build
        # by-products, at least from the point of view of building Python
        # extensions -- but I want to keep my options open.
        self.set_undefined_options('build',
                                   ('build_temp', 'build_clib'),
                                   ('build_temp', 'build_temp'),
                                   ('compiler', 'compiler'),
                                   ('debug', 'debug'),
                                   ('force', 'force'))

        self.libraries = self.distribution.libraries
        if self.libraries:
            self.check_library_list(self.libraries)

        if self.include_dirs is None:
            self.include_dirs = self.distribution.include_dirs or []
        if isinstance(self.include_dirs, str):
            self.include_dirs = self.include_dirs.split(os.pathsep)

        # XXX same as for build_ext -- what about 'self.define' and
        # 'self.undef' ?
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def find_executable(executable, path=None):
    """Tries to find 'executable' in the directories listed in 'path'.

    A string listing directories separated by 'os.pathsep'; defaults to
    os.environ['PATH'].  Returns the complete filename or None if not found.
    """
    if path is None:
        path = os.environ['PATH']
    paths = path.split(os.pathsep)
    base, ext = os.path.splitext(executable)

    if (sys.platform == 'win32' or os.name == 'os2') and (ext != '.exe'):
        executable = executable + '.exe'

    if not os.path.isfile(executable):
        for p in paths:
            f = os.path.join(p, executable)
            if os.path.isfile(f):
                # the file exists, we have a shot at spawn working
                return f
        return None
    else:
        return executable
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def _iscommand(cmd):
    """Return True if cmd is executable or can be found on the executable
    search path."""
    if _isexecutable(cmd):
        return True
    path = os.environ.get("PATH")
    if not path:
        return False
    for d in path.split(os.pathsep):
        exe = os.path.join(d, cmd)
        if _isexecutable(exe):
            return True
    return False


# General parent classes
项目:whatstyle    作者:mikr    | 项目源码 | 文件源码
def which(program):
    # type: (str) -> Optional[str]
    program = exename(program)
    fpath, _ = os.path.split(program)
    if fpath:
        if is_executable(program):
            return program
    else:
        for path in [os.path.abspath(os.curdir)] + os.environ['PATH'].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(unifilename(path), unifilename(program))
            if is_executable(exe_file):
                return exe_file

    return None

# ----------------------------------------------------------------------
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def find_command(cmd, paths=None, pathext=None):
    """Searches the PATH for the given command and returns its path"""
    if paths is None:
        paths = os.environ.get('PATH', '').split(os.pathsep)
    if isinstance(paths, string_types):
        paths = [paths]
    # check if there are funny path extensions for executables, e.g. Windows
    if pathext is None:
        pathext = get_pathext()
    pathext = [ext for ext in pathext.lower().split(os.pathsep) if len(ext)]
    # don't use extensions if the command ends with one of them
    if os.path.splitext(cmd)[1].lower() in pathext:
        pathext = ['']
    # check if we find the command on PATH
    for path in paths:
        # try without extension first
        cmd_path = os.path.join(path, cmd)
        for ext in pathext:
            # then including the extension
            cmd_path_ext = cmd_path + ext
            if os.path.isfile(cmd_path_ext):
                return cmd_path_ext
        if os.path.isfile(cmd_path):
            return cmd_path
    raise BadCommand('Cannot find command %r' % cmd)
项目:shadowsocksR-b    作者:hao35954514    | 项目源码 | 文件源码
def find_library_nt(name):
    # modified from ctypes.util
    # ctypes.util.find_library just returns first result he found
    # but we want to try them all
    # because on Windows, users may have both 32bit and 64bit version installed
    results = []
    for directory in os.environ['PATH'].split(os.pathsep):
        fname = os.path.join(directory, name)
        if os.path.isfile(fname):
            results.append(fname)
        if fname.lower().endswith(".dll"):
            continue
        fname = fname + ".dll"
        if os.path.isfile(fname):
            results.append(fname)
    return results
项目:SoCFoundationFlow    作者:mattaw    | 项目源码 | 文件源码
def run(self):
        env = self.env
        bld = self.generator.bld
        wd = bld.bldnode.abspath()

        #add src node + bld node (for generated java code)
        srcpath = self.generator.path.abspath() + os.sep + self.generator.srcdir
        srcpath += os.pathsep
        srcpath += self.generator.path.get_bld().abspath() + os.sep + self.generator.srcdir

        classpath = env.CLASSPATH
        classpath += os.pathsep
        classpath += os.pathsep.join(self.classpath)
        classpath = "".join(classpath)

        self.last_cmd = lst = []
        lst.extend(Utils.to_list(env['JAVADOC']))
        lst.extend(['-d', self.generator.javadoc_output.abspath()])
        lst.extend(['-sourcepath', srcpath])
        lst.extend(['-classpath', classpath])
        lst.extend(['-subpackages'])
        lst.extend(self.generator.javadoc_package)
        lst = [x for x in lst if x]

        self.generator.bld.cmd_and_log(lst, cwd=wd, env=env.env or None, quiet=0)
项目:SoCFoundationFlow    作者:mattaw    | 项目源码 | 文件源码
def configure(self):
    """
    Detect the javac, java and jar programs
    """
    # If JAVA_PATH is set, we prepend it to the path list
    java_path = self.environ['PATH'].split(os.pathsep)
    v = self.env

    if 'JAVA_HOME' in self.environ:
        java_path = [os.path.join(self.environ['JAVA_HOME'], 'bin')] + java_path
        self.env['JAVA_HOME'] = [self.environ['JAVA_HOME']]

    for x in 'javac java jar javadoc'.split():
        self.find_program(x, var=x.upper(), path_list=java_path)

    if 'CLASSPATH' in self.environ:
        v['CLASSPATH'] = self.environ['CLASSPATH']

    if not v['JAR']: self.fatal('jar is required for making java packages')
    if not v['JAVAC']: self.fatal('javac is required for compiling java classes')

    v['JARCREATE'] = 'cf' # can use cvf
    v['JAVACFLAGS'] = []
项目:SoCFoundationFlow    作者:mattaw    | 项目源码 | 文件源码
def configure(self):
    """
    Detect the scalac program
    """
    # If SCALA_HOME is set, we prepend it to the path list
    java_path = self.environ['PATH'].split(os.pathsep)
    v = self.env

    if 'SCALA_HOME' in self.environ:
        java_path = [os.path.join(self.environ['SCALA_HOME'], 'bin')] + java_path
        self.env['SCALA_HOME'] = [self.environ['SCALA_HOME']]

    for x in 'scalac scala'.split():
        self.find_program(x, var=x.upper(), path_list=java_path)

    if 'CLASSPATH' in self.environ:
        v['CLASSPATH'] = self.environ['CLASSPATH']

    v.SCALACFLAGS = ['-verbose']
    if not v['SCALAC']: self.fatal('scalac is required for compiling scala classes')
项目:SoCFoundationFlow    作者:mattaw    | 项目源码 | 文件源码
def run(task):
        command = 'SAS'
        fun = sas_fun

        node = task.inputs[0]
        logfilenode = node.change_ext('.log')
        lstfilenode = node.change_ext('.lst')

        # set the cwd
        task.cwd = task.inputs[0].parent.get_src().abspath()
        Logs.debug('runner: %s on %s' % (command, node.abspath))

        SASINPUTS = node.parent.get_bld().abspath() + os.pathsep + node.parent.get_src().abspath() + os.pathsep
        task.env.env = {'SASINPUTS': SASINPUTS}

        task.env.SRCFILE = node.abspath()
        task.env.LOGFILE = logfilenode.abspath()
        task.env.LSTFILE = lstfilenode.abspath()
        ret = fun(task)
        if ret:
            Logs.error('Running %s on %r returned a non-zero exit' % (command, node))
            Logs.error('SRCFILE = %r' % node)
            Logs.error('LOGFILE = %r' % logfilenode)
            Logs.error('LSTFILE = %r' % lstfilenode)
        return ret
项目:SoCFoundationFlow    作者:mattaw    | 项目源码 | 文件源码
def configure(self):
    """
    Detect the javac, java and jar programs
    """
    # If JAVA_PATH is set, we prepend it to the path list
    java_path = self.environ['PATH'].split(os.pathsep)
    v = self.env

    if 'JAVA_HOME' in self.environ:
        java_path = [os.path.join(self.environ['JAVA_HOME'], 'bin')] + java_path
        self.env['JAVA_HOME'] = [self.environ['JAVA_HOME']]

    for x in 'javac java jar javadoc'.split():
        self.find_program(x, var=x.upper(), path_list=java_path)

    if 'CLASSPATH' in self.environ:
        v['CLASSPATH'] = self.environ['CLASSPATH']

    if not v['JAR']: self.fatal('jar is required for making java packages')
    if not v['JAVAC']: self.fatal('javac is required for compiling java classes')

    v['JARCREATE'] = 'cf' # can use cvf
    v['JAVACFLAGS'] = []
项目:SoCFoundationFlow    作者:mattaw    | 项目源码 | 文件源码
def configure(self):
    """
    Detect the scalac program
    """
    # If SCALA_HOME is set, we prepend it to the path list
    java_path = self.environ['PATH'].split(os.pathsep)
    v = self.env

    if 'SCALA_HOME' in self.environ:
        java_path = [os.path.join(self.environ['SCALA_HOME'], 'bin')] + java_path
        self.env['SCALA_HOME'] = [self.environ['SCALA_HOME']]

    for x in 'scalac scala'.split():
        self.find_program(x, var=x.upper(), path_list=java_path)

    if 'CLASSPATH' in self.environ:
        v['CLASSPATH'] = self.environ['CLASSPATH']

    v.SCALACFLAGS = ['-verbose']
    if not v['SCALAC']: self.fatal('scalac is required for compiling scala classes')
项目:SoCFoundationFlow    作者:mattaw    | 项目源码 | 文件源码
def run(task):
        command = 'SAS'
        fun = sas_fun

        node = task.inputs[0]
        logfilenode = node.change_ext('.log')
        lstfilenode = node.change_ext('.lst')

        # set the cwd
        task.cwd = task.inputs[0].parent.get_src().abspath()
        Logs.debug('runner: %s on %s' % (command, node.abspath))

        SASINPUTS = node.parent.get_bld().abspath() + os.pathsep + node.parent.get_src().abspath() + os.pathsep
        task.env.env = {'SASINPUTS': SASINPUTS}

        task.env.SRCFILE = node.abspath()
        task.env.LOGFILE = logfilenode.abspath()
        task.env.LSTFILE = lstfilenode.abspath()
        ret = fun(task)
        if ret:
            Logs.error('Running %s on %r returned a non-zero exit' % (command, node))
            Logs.error('SRCFILE = %r' % node)
            Logs.error('LOGFILE = %r' % logfilenode)
            Logs.error('LSTFILE = %r' % lstfilenode)
        return ret
项目:SoCFoundationFlow    作者:mattaw    | 项目源码 | 文件源码
def check_exe(name, env=None):
    """
    Ensure that a program exists

    :type name: string
    :param name: name or path to program
    :return: path of the program or None
    """
    if not name:
        raise ValueError('Cannot execute an empty string!')
    def is_exe(fpath):
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

    fpath, fname = os.path.split(name)
    if fpath and is_exe(name):
        return os.path.abspath(name)
    else:
        env = env or os.environ
        for path in env["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, name)
            if is_exe(exe_file):
                return os.path.abspath(exe_file)
    return None
项目:SoCFoundationFlow    作者:mattaw    | 项目源码 | 文件源码
def run(self):
        env = self.env
        bld = self.generator.bld
        wd = bld.bldnode.abspath()

        #add src node + bld node (for generated java code)
        srcpath = self.generator.path.abspath() + os.sep + self.generator.srcdir
        srcpath += os.pathsep
        srcpath += self.generator.path.get_bld().abspath() + os.sep + self.generator.srcdir

        classpath = env.CLASSPATH
        classpath += os.pathsep
        classpath += os.pathsep.join(self.classpath)
        classpath = "".join(classpath)

        self.last_cmd = lst = []
        lst.extend(Utils.to_list(env['JAVADOC']))
        lst.extend(['-d', self.generator.javadoc_output.abspath()])
        lst.extend(['-sourcepath', srcpath])
        lst.extend(['-classpath', classpath])
        lst.extend(['-subpackages'])
        lst.extend(self.generator.javadoc_package)
        lst = [x for x in lst if x]

        self.generator.bld.cmd_and_log(lst, cwd=wd, env=env.env or None, quiet=0)
项目:SoCFoundationFlow    作者:mattaw    | 项目源码 | 文件源码
def configure(self):
    """
    Detect the javac, java and jar programs
    """
    # If JAVA_PATH is set, we prepend it to the path list
    java_path = self.environ['PATH'].split(os.pathsep)
    v = self.env

    if 'JAVA_HOME' in self.environ:
        java_path = [os.path.join(self.environ['JAVA_HOME'], 'bin')] + java_path
        self.env['JAVA_HOME'] = [self.environ['JAVA_HOME']]

    for x in 'javac java jar javadoc'.split():
        self.find_program(x, var=x.upper(), path_list=java_path)

    if 'CLASSPATH' in self.environ:
        v['CLASSPATH'] = self.environ['CLASSPATH']

    if not v['JAR']: self.fatal('jar is required for making java packages')
    if not v['JAVAC']: self.fatal('javac is required for compiling java classes')

    v['JARCREATE'] = 'cf' # can use cvf
    v['JAVACFLAGS'] = []
项目:SoCFoundationFlow    作者:mattaw    | 项目源码 | 文件源码
def check_exe(name, env=None):
    """
    Ensure that a program exists
    :type name: string
    :param name: name or path to program
    :return: path of the program or None
    """
    if not name:
        raise ValueError('Cannot execute an empty string!')
    def is_exe(fpath):
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

    fpath, fname = os.path.split(name)
    if fpath and is_exe(name):
        return os.path.abspath(name)
    else:
        env = env or os.environ
        for path in env["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, name)
            if is_exe(exe_file):
                return os.path.abspath(exe_file)
    return None
项目:static_analysis    作者:lprat    | 项目源码 | 文件源码
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

#source: https://stackoverflow.com/questions/3431825/generating-an-md5-checksum-of-a-file
项目:sublime-text-3-packages    作者:nickjj    | 项目源码 | 文件源码
def find_executable(executable):
    """
    Return the path to the given executable, or None if not found.

    create_environment is used to augment PATH before searching
    for the executable.

    """

    env = create_environment()

    for base in env.get('PATH', '').split(os.pathsep):
        path = os.path.join(os.path.expanduser(base), executable)

        # On Windows, if path does not have an extension, try .exe, .cmd, .bat
        if sublime.platform() == 'windows' and not os.path.splitext(path)[1]:
            for extension in ('.exe', '.cmd', '.bat'):
                path_ext = path + extension

                if can_exec(path_ext):
                    return path_ext
        elif can_exec(path):
            return path

    return None
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def find_command(cmd, path=None, pathext=None):
    if path is None:
        path = os.environ.get('PATH', '').split(os.pathsep)
    if isinstance(path, six.string_types):
        path = [path]
    # check if there are funny path extensions for executables, e.g. Windows
    if pathext is None:
        pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD').split(os.pathsep)
    # don't use extensions if the command ends with one of them
    for ext in pathext:
        if cmd.endswith(ext):
            pathext = ['']
            break
    # check if we find the command on PATH
    for p in path:
        f = os.path.join(p, cmd)
        if os.path.isfile(f):
            return f
        for ext in pathext:
            fext = f + ext
            if os.path.isfile(fext):
                return fext
    return None
项目:dappled    作者:lhon    | 项目源码 | 文件源码
def which1(program, pathstr=None):
    if pathstr is None:
        pathstr = os.environ["PATH"]

    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 pathstr.split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return exe_file

    return None
项目:UPBGE-CommunityAddon    作者:elmeunick9    | 项目源码 | 文件源码
def loadProjectFile(path):
    global project_data, project_path
    try:
        with open(path) as json_file: project_data = json.load(json_file)
        project_path=os.path.dirname(path) + os.sep
        com_path = project_path + "project" + os.sep + "core" + os.sep + "com"
        sys.path.append(com_path)

    except Exception as e: 
        print("LOAD ERROR")
        print(str(e))

    env_path = os.getenv("PYTHONPATH")
    if env_path:
        if not com_path in env_path:
            os.environ["PYTHONPATH"] += os.pathsep + com_path
    else:
        os.environ["PYTHONPATH"] = com_path
项目:NarshaTech    作者:KimJangHyeon    | 项目源码 | 文件源码
def find_command(cmd, path=None, pathext=None):
    if path is None:
        path = os.environ.get('PATH', '').split(os.pathsep)
    if isinstance(path, six.string_types):
        path = [path]
    # check if there are funny path extensions for executables, e.g. Windows
    if pathext is None:
        pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD').split(os.pathsep)
    # don't use extensions if the command ends with one of them
    for ext in pathext:
        if cmd.endswith(ext):
            pathext = ['']
            break
    # check if we find the command on PATH
    for p in path:
        f = os.path.join(p, cmd)
        if os.path.isfile(f):
            return f
        for ext in pathext:
            fext = f + ext
            if os.path.isfile(fext):
                return fext
    return None
项目:py-solc    作者:ethereum    | 项目源码 | 文件源码
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
项目:py-solc    作者:ethereum    | 项目源码 | 文件源码
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
项目:py-solc    作者:ethereum    | 项目源码 | 文件源码
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
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def find_command(cmd, paths=None, pathext=None):
    """Searches the PATH for the given command and returns its path"""
    if paths is None:
        paths = os.environ.get('PATH', '').split(os.pathsep)
    if isinstance(paths, string_types):
        paths = [paths]
    # check if there are funny path extensions for executables, e.g. Windows
    if pathext is None:
        pathext = get_pathext()
    pathext = [ext for ext in pathext.lower().split(os.pathsep) if len(ext)]
    # don't use extensions if the command ends with one of them
    if os.path.splitext(cmd)[1].lower() in pathext:
        pathext = ['']
    # check if we find the command on PATH
    for path in paths:
        # try without extension first
        cmd_path = os.path.join(path, cmd)
        for ext in pathext:
            # then including the extension
            cmd_path_ext = cmd_path + ext
            if os.path.isfile(cmd_path_ext):
                return cmd_path_ext
        if os.path.isfile(cmd_path):
            return cmd_path
    raise BadCommand('Cannot find command %r' % cmd)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def finalize_options(self):
        # This might be confusing: both build-clib and build-temp default
        # to build-temp as defined by the "build" command.  This is because
        # I think that C libraries are really just temporary build
        # by-products, at least from the point of view of building Python
        # extensions -- but I want to keep my options open.
        self.set_undefined_options('build',
                                   ('build_temp', 'build_clib'),
                                   ('build_temp', 'build_temp'),
                                   ('compiler', 'compiler'),
                                   ('debug', 'debug'),
                                   ('force', 'force'))

        self.libraries = self.distribution.libraries
        if self.libraries:
            self.check_library_list(self.libraries)

        if self.include_dirs is None:
            self.include_dirs = self.distribution.include_dirs or []
        if isinstance(self.include_dirs, str):
            self.include_dirs = self.include_dirs.split(os.pathsep)

        # XXX same as for build_ext -- what about 'self.define' and
        # 'self.undef' ?
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
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)
项目:3ds-to-cia    作者:drizzt    | 项目源码 | 文件源码
def which(cmd):
    path = os.environ.get("PATH", os.defpath)
    if not path:
        return None
    path = [get_tools_path()] + path.split(os.pathsep) + ["."]
    if sys.platform == "win32":
        pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
        files = [cmd + ext for ext in pathext]
    else:
        files = [cmd]

    seen = set()
    for dir in path:
    normdir = os.path.normcase(dir)
    if normdir not in seen:
        seen.add(normdir)
        for thefile in files:
        name = os.path.join(dir, thefile)
        if os.path.exists(name):
            return name
    return None
项目:pc-ble-driver-py    作者:NordicSemiconductor    | 项目源码 | 文件源码
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
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
def _build_paths(self, name, spec_path_lists, exists):
        """
        Given an environment variable name and specified paths,
        return a pathsep-separated string of paths containing
        unique, extant, directories from those paths and from
        the environment variable. Raise an error if no paths
        are resolved.
        """
        # flatten spec_path_lists
        spec_paths = itertools.chain.from_iterable(spec_path_lists)
        env_paths = safe_env.get(name, '').split(os.pathsep)
        paths = itertools.chain(spec_paths, env_paths)
        extant_paths = list(filter(os.path.isdir, paths)) if exists else paths
        if not extant_paths:
            msg = "%s environment variable is empty" % name.upper()
            raise distutils.errors.DistutilsPlatformError(msg)
        unique_paths = self._unique_everseen(extant_paths)
        return os.pathsep.join(unique_paths)

    # from Python docs
项目:shadowsocksr    作者:shadowsocksr-backup    | 项目源码 | 文件源码
def find_library_nt(name):
    # modified from ctypes.util
    # ctypes.util.find_library just returns first result he found
    # but we want to try them all
    # because on Windows, users may have both 32bit and 64bit version installed
    results = []
    for directory in os.environ['PATH'].split(os.pathsep):
        fname = os.path.join(directory, name)
        if os.path.isfile(fname):
            results.append(fname)
        if fname.lower().endswith(".dll"):
            continue
        fname = fname + ".dll"
        if os.path.isfile(fname):
            results.append(fname)
    return results
项目:ShadowSocks    作者:immqy    | 项目源码 | 文件源码
def find_library_nt(name):
    # modified from ctypes.util
    # ctypes.util.find_library just returns first result he found
    # but we want to try them all
    # because on Windows, users may have both 32bit and 64bit version installed
    results = []
    for directory in os.environ['PATH'].split(os.pathsep):
        fname = os.path.join(directory, name)
        if os.path.isfile(fname):
            results.append(fname)
        if fname.lower().endswith(".dll"):
            continue
        fname = fname + ".dll"
        if os.path.isfile(fname):
            results.append(fname)
    return results
项目:ascii-art-py    作者:blinglnav    | 项目源码 | 文件源码
def _build_paths(self, name, spec_path_lists, exists):
        """
        Given an environment variable name and specified paths,
        return a pathsep-separated string of paths containing
        unique, extant, directories from those paths and from
        the environment variable. Raise an error if no paths
        are resolved.
        """
        # flatten spec_path_lists
        spec_paths = itertools.chain.from_iterable(spec_path_lists)
        env_paths = safe_env.get(name, '').split(os.pathsep)
        paths = itertools.chain(spec_paths, env_paths)
        extant_paths = list(filter(os.path.isdir, paths)) if exists else paths
        if not extant_paths:
            msg = "%s environment variable is empty" % name.upper()
            raise distutils.errors.DistutilsPlatformError(msg)
        unique_paths = self._unique_everseen(extant_paths)
        return os.pathsep.join(unique_paths)

    # from Python docs
项目:Scrum    作者:prakharchoudhary    | 项目源码 | 文件源码
def find_command(cmd, path=None, pathext=None):
    if path is None:
        path = os.environ.get('PATH', '').split(os.pathsep)
    if isinstance(path, six.string_types):
        path = [path]
    # check if there are funny path extensions for executables, e.g. Windows
    if pathext is None:
        pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD').split(os.pathsep)
    # don't use extensions if the command ends with one of them
    for ext in pathext:
        if cmd.endswith(ext):
            pathext = ['']
            break
    # check if we find the command on PATH
    for p in path:
        f = os.path.join(p, cmd)
        if os.path.isfile(f):
            return f
        for ext in pathext:
            fext = f + ext
            if os.path.isfile(fext):
                return fext
    return None
项目:radar    作者:amoose136    | 项目源码 | 文件源码
def finalize_options(self):
        if self.parallel:
            try:
                self.parallel = int(self.parallel)
            except ValueError:
                raise ValueError("--parallel/-j argument must be an integer")

        # Ensure that self.include_dirs and self.distribution.include_dirs
        # refer to the same list object. finalize_options will modify
        # self.include_dirs, but self.distribution.include_dirs is used
        # during the actual build.
        # self.include_dirs is None unless paths are specified with
        # --include-dirs.
        # The include paths will be passed to the compiler in the order:
        # numpy paths, --include-dirs paths, Python include path.
        if isinstance(self.include_dirs, str):
            self.include_dirs = self.include_dirs.split(os.pathsep)
        incl_dirs = self.include_dirs or []
        if self.distribution.include_dirs is None:
            self.distribution.include_dirs = []
        self.include_dirs = self.distribution.include_dirs
        self.include_dirs.extend(incl_dirs)

        old_build_ext.finalize_options(self)
        self.set_undefined_options('build', ('parallel', 'parallel'))
项目:radar    作者:amoose136    | 项目源码 | 文件源码
def __init__(self,
                  default_lib_dirs=default_lib_dirs,
                  default_include_dirs=default_include_dirs,
                  verbosity=1,
                  ):
        self.__class__.info = {}
        self.local_prefixes = []
        defaults = {'library_dirs': os.pathsep.join(default_lib_dirs),
                    'include_dirs': os.pathsep.join(default_include_dirs),
                    'runtime_library_dirs': os.pathsep.join(default_runtime_dirs),
                    'rpath': '',
                    'src_dirs': os.pathsep.join(default_src_dirs),
                    'search_static_first': str(self.search_static_first),
                    'extra_compile_args': '', 'extra_link_args': ''}
        self.cp = ConfigParser(defaults)
        self.files = []
        self.files.extend(get_standard_file('.numpy-site.cfg'))
        self.files.extend(get_standard_file('site.cfg'))
        self.parse_config_files()
        if self.section is not None:
            self.search_static_first = self.cp.getboolean(
                self.section, 'search_static_first')
        assert isinstance(self.search_static_first, int)
项目:pygrunt    作者:elementbound    | 项目源码 | 文件源码
def path(klass):
        return os.environ['PATH'].split(os.pathsep)
项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
def _pythonpath():
    items = os.environ.get('PYTHONPATH', '').split(os.pathsep)
    return filter(None, items)
项目:python-    作者:secondtonone1    | 项目源码 | 文件源码
def finalize_options (self):
            if self.library_dirs is None:
                self.library_dirs = []
            elif isinstance(self.library_dirs, basestring):
                self.library_dirs = self.library_dirs.split(os.pathsep)

            self.library_dirs.insert(0, os.path.join(sys.real_prefix, "Libs"))
            old_build_ext.finalize_options(self)
项目:kas    作者:siemens    | 项目源码 | 文件源码
def find_program(paths, name):
    """
        Find a file within the paths array and returns its path.
    """
    for path in paths.split(os.pathsep):
        prg = os.path.join(path, name)
        if os.path.isfile(prg):
            return prg
    return None
项目:my-first-blog    作者:AnkurBegining    | 项目源码 | 文件源码
def site_config_dirs(appname):
    """Return a list of potential user-shared config dirs for this application.

        "appname" is the name of application.

    Typical user config directories are:
        macOS:      /Library/Application Support/<AppName>/
        Unix:       /etc or $XDG_CONFIG_DIRS[i]/<AppName>/ for each value in
                    $XDG_CONFIG_DIRS
        Win XP:     C:\Documents and Settings\All Users\Application ...
                    ...Data\<AppName>\
        Vista:      (Fail! "C:\ProgramData" is a hidden *system* directory
                    on Vista.)
        Win 7:      Hidden, but writeable on Win 7:
                    C:\ProgramData\<AppName>\
    """
    if WINDOWS:
        path = os.path.normpath(_get_win_folder("CSIDL_COMMON_APPDATA"))
        pathlist = [os.path.join(path, appname)]
    elif sys.platform == 'darwin':
        pathlist = [os.path.join('/Library/Application Support', appname)]
    else:
        # try looking in $XDG_CONFIG_DIRS
        xdg_config_dirs = os.getenv('XDG_CONFIG_DIRS', '/etc/xdg')
        if xdg_config_dirs:
            pathlist = [
                os.path.join(expanduser(x), appname)
                for x in xdg_config_dirs.split(os.pathsep)
            ]
        else:
            pathlist = []

        # always look in /etc directly as well
        pathlist.append('/etc')

    return pathlist


# -- Windows support functions --
项目:my-first-blog    作者:AnkurBegining    | 项目源码 | 文件源码
def finalize_options (self):
            if self.library_dirs is None:
                self.library_dirs = []
            elif isinstance(self.library_dirs, basestring):
                self.library_dirs = self.library_dirs.split(os.pathsep)

            self.library_dirs.insert(0, os.path.join(sys.real_prefix, "Libs"))
            old_build_ext.finalize_options(self)
项目:core-framework    作者:RedhawkSDR    | 项目源码 | 文件源码
def which(command):
    """
    Searches the path for the executable specified in 'command'.
    """
    for path in os.environ['PATH'].split(os.pathsep):
        execpath = os.path.join(path, command)
        if os.path.isfile(execpath) and os.access(execpath, os.X_OK):
            return execpath
    return None
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def _execvpe(file, args, env=None):
    if env is not None:
        func = execve
        argrest = (args, env)
    else:
        func = execv
        argrest = (args,)
        env = environ

    head, tail = path.split(file)
    if head:
        func(file, *argrest)
        return
    if 'PATH' in env:
        envpath = env['PATH']
    else:
        envpath = defpath
    PATH = envpath.split(pathsep)
    saved_exc = None
    saved_tb = None
    for dir in PATH:
        fullname = path.join(dir, file)
        try:
            func(fullname, *argrest)
        except error, e:
            tb = sys.exc_info()[2]
            if (e.errno != errno.ENOENT and e.errno != errno.ENOTDIR
                and saved_exc is None):
                saved_exc = e
                saved_tb = tb
    if saved_exc:
        raise error, saved_exc, saved_tb
    raise error, e, tb

# Change environ to automatically call putenv() if it exists
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def finalize_options(self):
        if self.include_dirs is None:
            self.include_dirs = self.distribution.include_dirs or []
        elif isinstance(self.include_dirs, str):
            self.include_dirs = self.include_dirs.split(os.pathsep)

        if self.libraries is None:
            self.libraries = []
        elif isinstance(self.libraries, str):
            self.libraries = [self.libraries]

        if self.library_dirs is None:
            self.library_dirs = []
        elif isinstance(self.library_dirs, str):
            self.library_dirs = self.library_dirs.split(os.pathsep)