Returns the user dir or None
964654
def _get_userdir(user=None):
    """"""

    if user is not None and not isinstance(user, fsnative):
        raise TypeError

    if is_win:
        if "HOME" in environ:
            path = environ["HOME"]
        elif "USERPROFILE" in environ:
            path = environ["USERPROFILE"]
        elif "HOMEPATH" in environ and "HOMEDRIVE" in environ:
            path = os.path.join(environ["HOMEDRIVE"], environ["HOMEPATH"])
        else:
            return

        if user is None:
            return path
        else:
            return os.path.join(os.path.dirname(path), user)
    else:
        import pwd

        if user is None:
            if "HOME" in environ:
                return environ["HOME"]
            else:
                try:
                    return path2fsn(pwd.getpwuid(os.getuid()).pw_dir)
                except KeyError:
                    return
        else:
            try:
                return path2fsn(pwd.getpwnam(user).pw_dir)
            except KeyError:
                return
555078
def _username():
    '''
    
    '''
    if pwd:
        username = pwd.getpwuid(os.getuid()).pw_name
    else:
        username = getpass.getuser()

    return username
1227348
def dir_attribs(location, mode=None, owner=None,
                group=None, recursive=False, use_sudo=False):
    
    args = ''
    if recursive:
        args = args + ' -R '

    if mode:
        if use_sudo:
            sudo('chmod %s %s %s' % (args, mode,  location))
        else:
            run('chmod %s %s %s' % (args, mode,  location))
    if owner:
        if use_sudo:
            sudo('chown %s %s %s' % (args, owner, location))
        else:
            run('chown %s %s %s' % (args, owner, location))
    if group:
        if use_sudo:
            sudo('chgrp %s %s %s' % (args, group, location))
        else:
            run('chgrp %s %s %s' % (args, group, location))
    return True
483958
def owner(self, pathobj):
        
        stat = self.stat(pathobj)

        if not stat.is_dir:
            return stat.modified_by
        else:
            return 'nobody'
446411
def _setup_user_dir(self):
        """"""
        user_dir = self._get_user_dir_path()

        rules_dir = user_dir.joinpath('rules')
        if not rules_dir.is_dir():
            rules_dir.mkdir(parents=True)
        self.user_dir = user_dir
900424
def dir():
        
        dir = [
            'abspath', 'dirname', 'exists', 'expanduser', 'getatime',
            'getctime', 'getmtime', 'getsize', 'isabs', 'isdir', 'isfile',
            'islink', 'ismount', 'join', 'lexists', 'normcase', 'normpath',
            'realpath', 'relpath', 'split', 'splitdrive'
        ]
        if IS_PY2:
            dir.append('walk')
        if sys.platform != 'win32' or not IS_PY2:
            dir.append('samefile')
        return dir
678109
def get_path_matching(name):
    
    # first try looking in the user folder
    p = os.path.join(os.path.expanduser("~"), name)
    # then try expanding upwards from cwd
    if not os.path.isdir(p):
        p = None
        drive, folders = os.path.splitdrive(os.getcwd())
        folders = folders.split(os.sep)
        folders.insert(0, os.sep)
        if name in folders:
            p = os.path.join(drive, *folders[: folders.index(name) + 1])
    # TODO: something more robust to catch the rest of the cases?
    return p
76021
def _get(self):
        '''
        

        '''
        user = self.USER
        try:
            uid = pwd.getpwnam(user).pw_uid
        except KeyError:
            log.info('User does not exist')
            return False

        cmd = self.gsetting_command + ['get', str(self.SCHEMA), str(self.KEY)]
        environ = {}
        environ['XDG_RUNTIME_DIR'] = '/run/user/{0}'.format(uid)
        result = __salt__['cmd.run_all'](cmd, runas=user, env=environ, python_shell=False)

        if 'stdout' in result:
            if 'uint32' in result['stdout']:
                return re.sub('uint32 ', '', result['stdout'])
            else:
                return result['stdout']
        else:
            return False
1350578
def IsDir(v):
    
    try:
        if v:
            v = str(v)
            return os.path.isdir(v)
        else:
            raise DirInvalid("Not a directory")
    except TypeError:
        raise DirInvalid("Not a directory")
556521
def get_profile_dir ():
    """"""
    basedir = unicode(os.environ["HOME"])
    return os.path.join(basedir, u"Library", u"Safari")
308071
def root_dir(relpath)
      r = relpath.match(%r(^[/]?.+?[/$]))
      return relpath if r.nil?
      r[0] || relpath
    end
814732
def user_cache_dir(self):
        """"""
        directory = appdirs.user_cache_dir(self.appname, self.appauthor,
                              version=self.version)
        if self.create:
            self._ensure_directory_exists(directory)
        return directory
246039
def get_pwd
      return Dir.pwd if ENV['PWD'].nil?
      env_stat = File.stat(ENV['PWD'])
      pwd_stat = File.stat(Dir.pwd)
      if env_stat.ino == pwd_stat.ino && env_stat.dev == pwd_stat.dev
        ENV['PWD']
      else
        Dir.pwd
      end
    end
664930
def get_user(self, username):
        
        for user in self.users:
            if user.id.name == username:
                return user
        return None
1120569
def _GetDirectory(self):
    
    if self.entry_type != definitions.FILE_ENTRY_TYPE_DIRECTORY:
      return None
    return LVMDirectory(self._file_system, self.path_spec)
1213269
def user_config_dir():
    
    """
    if WINDOWS:
        path = os.environ.get('APPDATA')
    elif MACOS:
        path = os.path.expanduser('~/Library/Application Support')
    else:
        path = os.environ.get('XDG_CONFIG_HOME') or os.path.expanduser('~/.config')
    if path is None:
        path = ''
    else:
        path = os.path.join(path, 'glances')

    return path
1003952
def dirname(path: Optional[str]) -> Optional[str]:
    
    if path is not None:
        return os.path.dirname(path)