Exemple #1
0
def get_home_dir():
    """Return user home directory."""
    try:
        # expanduser() returns a raw byte string which needs to be
        # decoded with the codec that the OS is using to represent file paths.
        path = encoding.to_unicode_from_fs(osp.expanduser('~'))
    except:
        path = ''
    for env_var in ('HOME', 'USERPROFILE', 'TMP'):
        if osp.isdir(path):
            break
        # os.environ.get() returns a raw byte string which needs to be
        # decoded with the codec that the OS is using to represent environment
        # variables.
        path = encoding.to_unicode_from_fs(os.environ.get(env_var, ''))
    if path:
        return path
    else:
        raise RuntimeError('Please define environment variable $HOME')
Exemple #2
0
def get_home_dir():
    """Return user home directory."""
    path = None
    if os.name == 'nt':
        path_env_vars = ('HOME', 'APPDATA', 'USERPROFILE', 'TMP')
        # prefer locations that already have .anaconda/navigator folders
        for env_var in path_env_vars:
            path = os.path.join(
                encoding.to_unicode_from_fs(os.environ.get(env_var, '')),
                SUBFOLDER)
            if osp.isdir(path):
                break
            path = None

        # did not find .anaconda/navigator folder; find first existing variable
        if not path:
            for env_var in path_env_vars:
                # os.environ.get() returns a raw byte string which needs to be
                # decoded with the codec that the OS is using to represent environment
                # variables.
                path = encoding.to_unicode_from_fs(os.environ.get(env_var, ''))
                if osp.isdir(path):
                    break
                path = None

    else:
        try:
            # expanduser() returns a raw byte string which needs to be
            # decoded with the codec that the OS is using to represent file paths.
            path = encoding.to_unicode_from_fs(osp.expanduser('~'))
        except Exception:
            path = ''
    if path:
        return path
    else:
        raise RuntimeError('Please define environment variable $HOME')
from anaconda_navigator.utils import encoding
from anaconda_navigator.utils.py3compat import (PY2, is_text_string,
                                                to_text_string)


# yapf: enable


class ProgramError(Exception):
    pass


if os.name == 'nt':
    TEMPDIR = tempfile.gettempdir() + osp.sep + 'spyder'
else:
    username = encoding.to_unicode_from_fs(os.environ.get('USER'))
    TEMPDIR = tempfile.gettempdir() + osp.sep + 'spyder-' + username


def is_program_installed(basename):
    """
    Return program absolute path if installed in PATH.

    Otherwise, return None
    """
    for path in os.environ["PATH"].split(os.pathsep):
        abspath = osp.join(path, basename)
        if osp.isfile(abspath):
            return abspath