returns the home folder and program root depending on OS
1322
def get_root_folder():
    
    locations = {
     'linux':{'hme':'/home/duncan/', 'core_folder':'/home/duncan/dev/src/python/AIKIF'},
     'win32':{'hme':'T:\\user\\',    'core_folder':'T:\\user\\dev\\src\\python\\AIKIF'},
     'cygwin':{'hme':os.getcwd() + os.sep,    'core_folder':os.getcwd()},
     'darwin':{'hme':os.getcwd() + os.sep,    'core_folder':os.getcwd()}
    }
    hme = locations[sys.platform]['hme']
    core_folder = locations[sys.platform]['core_folder']

    if not os.path.exists(core_folder):
        hme = os.getcwd()        
        core_folder = os.getcwd()
        print('config.py : running on CI build (or you need to modify the paths in config.py)')
    return hme, core_folder
757167
def find_root(self):
        
        cmd = self
        while cmd.parent:
            cmd = cmd.parent
        return cmd
909696
def _root_path(self):
        """'"""
        if self.ROOT_PATH_FOR_DYNACONF is not None:
            return self.ROOT_PATH_FOR_DYNACONF
        elif self._loaded_files:  # called once
            root_path = os.path.dirname(self._loaded_files[0])
            self.set("ROOT_PATH_FOR_DYNACONF", root_path)
            return root_path
832055
def get_parent_dir(base_dir, level=1):
    ""
    while level > 0:
        base_dir = os.path.dirname(base_dir)
        level -= 1
    return base_dir
658426
protected static function getUserHomeDir() {
        // Cannot use $_SERVER superglobal since that's empty during UnitUnishTestCase
        // getenv('HOME') isn't set on Windows and generates a Notice.
        $home = getenv('HOME');

        if (!empty($home)) {
            // home should never end with a trailing slash.
            $home = rtrim($home, '/');
        } elseif (!empty($_SERVER['HOMEDRIVE']) && !empty($_SERVER['HOMEPATH'])) {
            // home on windows
            $home = $_SERVER['HOMEDRIVE'] . $_SERVER['HOMEPATH'];
            // If HOMEPATH is a root directory the path can end with a slash. Make sure
            // that doesn't happen.
            $home = rtrim($home, '\\/');
        }

        return empty($home) ? NULL : $home;
    }
911783
def obtainAdbPath():
    '''
    
    '''

    FORCE_FAIL = False
    ''' Sometimes, you want it to fail to check the error messages '''
    osName = platform.system()
    isWindows = False
    adb = 'adb'

    if (osName.startswith('Windows')) or (osName.startswith('Java')):
        envOSName = os.getenv('os')  # this should work as it has been set since xp.
        if envOSName.startswith('Windows'):
            adb = 'adb.exe'
            isWindows = True

    exeFile = which(adb, isWindows)
    if exeFile:
        return exeFile

    ANDROID_HOME = os.environ['ANDROID_HOME'] if os.environ.has_key('ANDROID_HOME') else '/opt/android-sdk'
    HOME = os.environ['HOME'] if os.environ.has_key('HOME') else ''

    possibleChoices = [os.path.join(ANDROID_HOME, 'platform-tools', adb),
                       os.path.join(HOME, "android", 'platform-tools', adb),
                       os.path.join(HOME, "android-sdk", 'platform-tools', adb),
                       ]

    if osName.startswith('Windows'):
        possibleChoices.append(os.path.join("""C:\Program Files\Android\android-sdk\platform-tools""", adb))
        possibleChoices.append(os.path.join("""C:\Program Files (x86)\Android\android-sdk\platform-tools""", adb))
    elif osName.startswith('Linux'):
        possibleChoices.append(os.path.join(os.sep, "opt", "android-sdk-linux", 'platform-tools', adb))
        possibleChoices.append(os.path.join(HOME, "opt", "android-sdk-linux", 'platform-tools', adb))
        possibleChoices.append(os.path.join(HOME, "android-sdk-linux", 'platform-tools', adb))
        possibleChoices.append(os.path.join(HOME, 'Android', 'Sdk', 'platform-tools', adb))
    elif osName.startswith('Mac'):
        possibleChoices.append(os.path.join(HOME, "Library", "Android", "sdk", 'platform-tools', adb))
        possibleChoices.append(os.path.join(os.sep, "opt", "android-sdk-mac_x86", 'platform-tools', adb))
        possibleChoices.append(os.path.join(HOME, "opt", "android-sdk-mac", 'platform-tools', adb))
        possibleChoices.append(os.path.join(HOME, "android-sdk-mac", 'platform-tools', adb))
        possibleChoices.append(os.path.join(HOME, "opt", "android-sdk-mac_x86", 'platform-tools', adb))
        possibleChoices.append(os.path.join(HOME, "android-sdk-mac_x86", 'platform-tools', adb))
    else:
        # Unsupported OS
        pass

    possibleChoices.append(adb)

    checkedFiles = []

    for exeFile in possibleChoices:
        checkedFiles.append(exeFile)
        if not FORCE_FAIL and os.access(exeFile, os.X_OK):
            return exeFile

    for path in os.environ["PATH"].split(os.pathsep):
        exeFile = os.path.join(path, adb)
        checkedFiles.append(exeFile)
        if not FORCE_FAIL and exeFile is not None and os.access(exeFile, os.X_OK if not isWindows else os.F_OK):
            return exeFile

    if not os.environ.has_key('ANDROID_HOME'):
        helpMsg = 'Did you forget to set ANDROID_HOME in the environment?'
    else:
        helpMsg = ''

    raise Exception('''adb="%s" is not executable. %s

These files we unsuccessfully checked to find a suitable '%s' executable:
    %s
    ''' % (adb, helpMsg, adb, "\n    ".join(checkedFiles)))
1088056
def get_system_path():
    """"""
    _bpath = []
    if is_win:
        try:
            import win32api
        except ImportError:
            logger.warn("Cannot determine your Windows or System directories")
            logger.warn("Please add them to your PATH if .dlls are not found")
            logger.warn("or install http://sourceforge.net/projects/pywin32/")
        else:
            sysdir = win32api.GetSystemDirectory()
            sysdir2 = os.path.normpath(os.path.join(sysdir, '..', 'SYSTEM'))
            windir = win32api.GetWindowsDirectory()
            _bpath = [sysdir, sysdir2, windir]
    _bpath.extend(compat.getenv('PATH', '').split(os.pathsep))
    return _bpath
1205251
def get_gpg_home( appname, config_dir=None ):
    
    assert is_valid_appname(appname)
    config_dir = get_config_dir( config_dir )
    path = os.path.join( config_dir, "gpgkeys", appname )
    return path
1160527
def user_cache_dir():
    
    """
    if WINDOWS:
        path = os.path.join(os.environ.get('LOCALAPPDATA') or os.environ.get('APPDATA'),
                            'glances', 'cache')
    elif MACOS:
        path = os.path.expanduser('~/Library/Caches/glances')
    else:
        path = os.path.join(os.environ.get('XDG_CACHE_HOME') or os.path.expanduser('~/.cache'),
                            'glances')

    return path
628278
def get_config_directory(appname):
    
    if platform.system().lower() == 'windows':
        path = os.path.join(os.getenv('APPDATA') or '~', appname, appname)
    elif platform.system().lower() == 'darwin':
        path = os.path.join('~', 'Library', 'Application Support', appname)
    else:
        path = os.path.join(os.getenv('XDG_CONFIG_HOME') or '~/.config',
                            appname.lower())
    return os.path.expanduser(path)
1223225
def get_program(name, config, ptype="cmd", default=None):
    
    # support taking in the data dictionary
    config = config.get("config", config)
    try:
        pconfig = config.get("resources", {})[name]
        # If have leftover old
    except KeyError:
        pconfig = {}
    old_config = config.get("program", {}).get(name, None)
    if old_config:
        for key in ["dir", "cmd"]:
            if not key in pconfig:
                pconfig[key] = old_config
    if ptype == "cmd":
        return _get_program_cmd(name, pconfig, config, default)
    elif ptype == "dir":
        return _get_program_dir(name, pconfig)
    else:
        raise ValueError("Don't understand program type: %s" % ptype)
1277354
def get_bin(self, arch='x86'):
        
        bin_dir = os.path.join(self.vc_dir, 'bin')
        if arch == 'x86':
            arch = ''
        cl_path = os.path.join(bin_dir, arch, 'cl.exe')
        link_path = os.path.join(bin_dir, arch, 'link.exe')
        ml_name = 'ml.exe'
        if arch in ['x86_amd64', 'amd64']:
            ml_name = 'ml64.exe'
        ml_path = os.path.join(bin_dir, arch, ml_name)
        if os.path.isfile(cl_path) \
           and os.path.isfile(link_path) \
           and os.path.isfile(ml_path):
            logging.info(_('using cl.exe: %s'), cl_path)
            logging.info(_('using link.exe: %s'), link_path)
            logging.info(_('using %s: %s'), ml_name, ml_path)
            run_cl = partial(run_program, cl_path)
            run_link = partial(run_program, link_path)
            run_ml = partial(run_program, ml_path)
            return self.Bin(run_cl, run_link, run_ml)
        logging.debug(_('cl.exe not found: %s'), cl_path)
        logging.debug(_('link.exe not found: %s'), link_path)
        logging.debug(_('%s not found: %s'), ml_name, ml_path)
        return self.Bin(None, None, None)
734079
def find_program (program):
    """"""
    if os.name == 'nt':
        # Add some well-known archiver programs to the search path
        path = os.environ['PATH']
        path = append_to_path(path, get_nt_7z_dir())
        path = append_to_path(path, get_nt_mac_dir())
        path = append_to_path(path, get_nt_winrar_dir())
    else:
        # use default path
        path = None
    return which(program, path=path)
481473
def relative_root_dir(self):
        """"""
        return Path(self.bundle.name) / str(self.created_at.date())
751582
protected static String getHomeDir(String[] args) {
        if (System.getenv(HOME_DIR) == null) {
            if (args.length > index) {
                return args[index++];
            } else {
                return ".";
            }
        } else {
            return System.getenv(HOME_DIR);
        }
    }
1345039
def home(self):
    """"""
    if not self._home:
      home = self._get_system_properties(self.java)['java.home']
      # The `jre/bin/java` executable in a JDK distribution will report `java.home` as the jre dir,
      # so we check for this and re-locate to the containing jdk dir when present.
      if os.path.basename(home) == 'jre':
        jdk_dir = os.path.dirname(home)
        if self._is_executable(os.path.join(jdk_dir, 'bin', 'javac')):
          home = jdk_dir
      self._home = home
    return text_type(self._home)
289965
def dir():
        
        dir = [
            'access', 'chdir', 'chmod', 'chown', 'close', 'fstat', 'fsync',
            'getcwd', 'lchmod', 'link', 'listdir', 'lstat', 'makedirs',
            'mkdir', 'mknod', 'open', 'read', 'readlink', 'remove',
            'removedirs', 'rename', 'rmdir', 'stat', 'symlink', 'umask',
            'unlink', 'utime', 'walk', 'write'
        ]
        if IS_PY2:
            dir += ['getcwdu']
        else:
            dir += ['getcwdb', 'replace']
            if sys.platform.startswith('linux'):
                dir += [
                    'fdatasync', 'getxattr', 'listxattr',
                    'removexattr', 'setxattr'
                ]
        if use_scandir:
            dir += ['scandir']
        return dir