Python os.pathsep() Examples

The following are code examples for showing how to use os.pathsep(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the ones you don't like. You can also save this page to your account.

Example 1
Project: python-   Author: secondtonone1   File: appdirs.py    (license) View Source Project 9 votes vote down vote up
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 -- 
Example 2
Project: my-first-blog   Author: AnkurBegining   File: easy_install.py    (license) View Source Project 7 votes vote down vote up
def _pythonpath():
    items = os.environ.get('PYTHONPATH', '').split(os.pathsep)
    return filter(None, items) 
Example 3
Project: howmanypeoplearearound   Author: wi-fi-analyzer   File: __main__.py    (license) View Source Project 7 votes vote down vote up
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 
Example 4
Project: kinect-2-libras   Author: inessadl   File: build_clib.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
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' ? 
Example 5
Project: kinect-2-libras   Author: inessadl   File: spawn.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
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 
Example 6
Project: kinect-2-libras   Author: inessadl   File: webbrowser.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
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 
Example 7
Project: whatstyle   Author: mikr   File: whatstyle.py    (MIT License) View Source Project 6 votes vote down vote up
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

# ---------------------------------------------------------------------- 
Example 8
Project: Flask_Blog   Author: sugarguo   File: util.py    (GNU General Public License v3.0) View Source Project 6 votes vote down vote up
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) 
Example 9
Project: shadowsocksR-b   Author: hao35954514   File: util.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
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 
Example 10
Project: SoCFoundationFlow   Author: mattaw   File: javaw.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
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) 
Example 11
Project: SoCFoundationFlow   Author: mattaw   File: javaw.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
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'] = [] 
Example 12
Project: SoCFoundationFlow   Author: mattaw   File: scala.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
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') 
Example 13
Project: SoCFoundationFlow   Author: mattaw   File: sas.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
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 
Example 14
Project: SoCFoundationFlow   Author: mattaw   File: javaw.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
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'] = [] 
Example 15
Project: SoCFoundationFlow   Author: mattaw   File: scala.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
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') 
Example 16
Project: SoCFoundationFlow   Author: mattaw   File: sas.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
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 
Example 17
Project: SoCFoundationFlow   Author: mattaw   File: Utils.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
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 
Example 18
Project: SoCFoundationFlow   Author: mattaw   File: javaw.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
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) 
Example 19
Project: SoCFoundationFlow   Author: mattaw   File: javaw.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
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'] = [] 
Example 20
Project: SoCFoundationFlow   Author: mattaw   File: Utils.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
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 
Example 21
Project: static_analysis   Author: lprat   File: analysis.py    (license) View Source Project 6 votes vote down vote up
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 
Example 22
Project: sublime-text-3-packages   Author: nickjj   File: util.py    (MIT License) View Source Project 6 votes vote down vote up
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 
Example 23
Project: CodingDojo   Author: ComputerSocietyUNB   File: utils.py    (license) View Source Project 6 votes vote down vote up
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 
Example 24
Project: dappled   Author: lhon   File: utils.py    (license) View Source Project 6 votes vote down vote up
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 
Example 25
Project: UPBGE-CommunityAddon   Author: elmeunick9   File: utils.py    (license) View Source Project 6 votes vote down vote up
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 
Example 26
Project: NarshaTech   Author: KimJangHyeon   File: utils.py    (license) View Source Project 6 votes vote down vote up
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 
Example 27
Project: py-solc   Author: ethereum   File: install_solc.py    (license) View Source Project 6 votes vote down vote up
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 
Example 28
Project: py-solc   Author: ethereum   File: install.py    (license) View Source Project 6 votes vote down vote up
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 
Example 29
Project: py-solc   Author: ethereum   File: filesystem.py    (license) View Source Project 6 votes vote down vote up
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 
Example 30
Project: hostapd-mana   Author: adde88   File: util.py    (license) View Source Project 6 votes vote down vote up
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) 
Example 31
Project: hostapd-mana   Author: adde88   File: build_clib.py    (license) View Source Project 6 votes vote down vote up
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' ? 
Example 32
Project: hostapd-mana   Author: adde88   File: uuid.py    (license) View Source Project 6 votes vote down vote up
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) 
Example 33
Project: 3ds-to-cia   Author: drizzt   File: 3ds-to-cia.py    (license) View Source Project 6 votes vote down vote up
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 
Example 34
Project: pc-ble-driver-py   Author: NordicSemiconductor   File: ble_driver.py    (license) View Source Project 6 votes vote down vote up
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 
Example 35
Project: Sci-Finder   Author: snverse   File: msvc.py    (license) View Source Project 6 votes vote down vote up
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 
Example 36
Project: shadowsocksr   Author: shadowsocksr-backup   File: util.py    (license) View Source Project 6 votes vote down vote up
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 
Example 37
Project: ShadowSocks   Author: immqy   File: util.py    (license) View Source Project 6 votes vote down vote up
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 
Example 38
Project: ascii-art-py   Author: blinglnav   File: msvc.py    (license) View Source Project 6 votes vote down vote up
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 
Example 39
Project: Scrum   Author: prakharchoudhary   File: utils.py    (license) View Source Project 6 votes vote down vote up
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 
Example 40
Project: radar   Author: amoose136   File: build_ext.py    (license) View Source Project 6 votes vote down vote up
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')) 
Example 41
Project: radar   Author: amoose136   File: system_info.py    (license) View Source Project 6 votes vote down vote up
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) 
Example 42
Project: pygrunt   Author: elementbound   File: platform.py    (GNU General Public License v3.0) View Source Project 5 votes vote down vote up
def path(klass):
        return os.environ['PATH'].split(os.pathsep) 
Example 43
Project: python-   Author: secondtonone1   File: easy_install.py    (license) View Source Project 5 votes vote down vote up
def _pythonpath():
    items = os.environ.get('PYTHONPATH', '').split(os.pathsep)
    return filter(None, items) 
Example 44
Project: python-   Author: secondtonone1   File: __init__.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 45
Project: kas   Author: siemens   File: libkas.py    (license) View Source Project 5 votes vote down vote up
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 
Example 46
Project: my-first-blog   Author: AnkurBegining   File: appdirs.py    (license) View Source Project 5 votes vote down vote up
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 -- 
Example 47
Project: my-first-blog   Author: AnkurBegining   File: __init__.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 48
Project: core-framework   Author: RedhawkSDR   File: scatest.py    (license) View Source Project 5 votes vote down vote up
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 
Example 49
Project: kinect-2-libras   Author: inessadl   File: os.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
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 
Example 50
Project: kinect-2-libras   Author: inessadl   File: config.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
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)