Change the home directory of the user

    CLI Example:

    .. code-block:: bash

        salt '*' user.chhome foo /Users/foo
184245
def chhome(name, home, **kwargs):
    '''
    
    '''
    kwargs = salt.utils.args.clean_kwargs(**kwargs)
    persist = kwargs.pop('persist', False)
    if kwargs:
        salt.utils.args.invalid_kwargs(kwargs)
    if persist:
        log.info('Ignoring unsupported \'persist\' argument to user.chhome')

    pre_info = info(name)
    if not pre_info:
        raise CommandExecutionError('User \'{0}\' does not exist'.format(name))
    if home == pre_info['home']:
        return True
    _dscl(
        ['/Users/{0}'.format(name), 'NFSHomeDirectory',
         pre_info['home'], home],
        ctype='change'
    )
    # dscl buffers changes, sleep 1 second before checking if new value
    # matches desired value
    time.sleep(1)
    return info(name).get('home') == home
497240
def change_directory(path=None):
    
    if path is not None:
        try:
            oldpwd = getcwd()
            logger.debug('changing directory from %s to %s' % (oldpwd, path))
            chdir(path)
            yield
        finally:
            chdir(oldpwd)
    else:
        yield
618340
def change_dir(self, session, path):
        
        if path == "-":
            # Previous directory
            path = self._previous_path or "."

        try:
            previous = os.getcwd()
            os.chdir(path)
        except IOError as ex:
            # Can't change directory
            session.write_line("Error changing directory: {0}", ex)
        else:
            # Store previous path
            self._previous_path = previous
            session.write_line(os.getcwd())
83958
function cmd_SITE($fd, $cmd)
    {
        if (substr($cmd[1], 0, 6) == "CHMOD ")
        {
            $user = $this->getUser($fd);
            $chmod = explode(" ", $cmd[1], 3);
            $file = $this->fillDirName($user, $chmod[2]);
            $this->debug("CHMOD: $file to {$chmod[1]}");
            if (chmod($file, octdec($chmod[1])))
            {
                $this->send($fd, "200 Permissions changed on {$chmod[2]}");
            }
            else
            {
                $this->send($fd, "550 Could not change perms on " . $chmod[2] . ": Permission denied");
            }
        }
        else
        {
            $this->send($fd, "500 Unknown Command");
        }
    }
60718
def expanduser(path):
    """"""
    if path[:1] != '~':
        return path
    i, n = 1, len(path)
    while i < n and path[i] not in '/\\':
        i = i + 1

    if 'HOME' in os.environ:
        userhome = os.environ['HOME']
    elif 'USERPROFILE' in os.environ:
        userhome = os.environ['USERPROFILE']
    elif not 'HOMEPATH' in os.environ:
        return path
    else:
        try:
            drive = os.environ['HOMEDRIVE']
        except KeyError:
            drive = ''
        userhome = join(drive, os.environ['HOMEPATH'])

    if i != 1:  # ~user
        userhome = join(dirname(userhome), path[1:i])

    return userhome + path[i:]
874049
def cmd_cd(self, *args):
        
        if len(args) == 0:
            path = os.environ['HOME']
        else:
            path = args[0]
        os.chdir(path)
        self.cmd_pwd()
374152
def chshell(name, shell):
    '''
    
    '''
    pre_info = info(name)
    if not pre_info:
        raise CommandExecutionError('User \'{0}\' does not exist'.format(name))
    if shell == pre_info['shell']:
        return True
    _dscl(
        ['/Users/{0}'.format(name), 'UserShell', pre_info['shell'], shell],
        ctype='change'
    )
    # dscl buffers changes, sleep 1 second before checking if new value
    # matches desired value
    time.sleep(1)
    return info(name).get('shell') == shell
139474
def rename(name, new_name):
    '''
    
    '''
    current_info = info(name)
    if not current_info:
        raise CommandExecutionError('User \'{0}\' does not exist'.format(name))
    new_info = info(new_name)
    if new_info:
        raise CommandExecutionError(
            'User \'{0}\' already exists'.format(new_name)
        )
    cmd = ['pw', 'usermod', '-l', new_name, '-n', name]
    __salt__['cmd.run'](cmd)
    post_info = info(new_name)
    if post_info['name'] != current_info['name']:
        return post_info['name'] == new_name
    return False
813356
def dir_attribs(location, mode=None, owner=None,
                group=None, recursive=False, use_sudo=False):
    
    recursive = recursive and "-R " or ""
    if mode:
        if use_sudo:
            sudo('chmod %s %s %s' % (recursive, mode,  location))
        else:
            run('chmod %s %s %s' % (recursive, mode,  location))
    if owner:
        if use_sudo:
            sudo('chown %s %s %s' % (recursive, owner, location))
        else:
            run('chown %s %s %s' % (recursive, owner, location))
    if group:
        if use_sudo:
            sudo('chgrp %s %s %s' % (recursive, group, location))
        else:
            run('chgrp %s %s %s' % (recursive, group, location))
413468
def _set_symlink_ownership(path, user, group, win_owner):
    '''
    
    '''
    if salt.utils.platform.is_windows():
        try:
            salt.utils.win_dacl.set_owner(path, win_owner)
        except CommandExecutionError:
            pass
    else:
        try:
            __salt__['file.lchown'](path, user, group)
        except OSError:
            pass
    return _check_symlink_ownership(path, user, group, win_owner)
1328466
def guess_user_home(other_user=nil)
      this_user = other_user || opts[:user]
      @rye_guessed_homes ||= {}
      
      # A simple cache. 
      return @rye_guessed_homes[this_user] if @rye_guessed_homes.has_key?(this_user)
      
      # Some junk to determine where user home directories are by default.
      # We're relying on the command "useradd -D" so this may not work on
      # different Linuxen and definitely won't work on Windows.
      # This code will be abstracted out once I find a decent home for it.
      # /etc/default/useradd, HOME=/home OR useradd -D
      # /etc/adduser.config, DHOME=/home OR ??
      user_defaults = {}
      ostmp = self.ostype
      ostmp &&= ostype.to_s
      
      if ostmp == "sunos"
        #nv.scan(/([\w_-]+?)=(.+?)\s/).each do |n, v|
        #  n = 'HOME' if n == 'basedir'
        #  user_defaults[n.upcase] = v.strip
        #end
        # In Solaris, useradd -D says the default home path is /home
        # but that directory is not writable. See: http://bit.ly/IJDD0
        user_defaults['HOME'] = '/export/home'
      elsif ostmp == "darwin"
        user_defaults['HOME'] = '/Users'
      elsif ostmp == "windows"
        user_defaults['HOME'] = 'C:/Documents and Settings'
      else
        raw = self.quietly { useradd(:D) } rescue []
        raw = ["HOME=/home"] if raw.nil? || raw.empty?
        raw.each do |nv|
          n, v = nv.scan(/\A([\w_-]+?)=(.+)\z/).flatten
          user_defaults[n] = v
        end
      end
      
      @rye_guessed_homes[this_user] = "#{user_defaults['HOME']}/#{this_user}"
    end
750296
public static function changeOwnerAndMode()
    {
        $dirs = \Deployer\get('change_owner_mode_dirs');

        if (empty($dirs)) {
            return;
        }

        foreach ($dirs as $key => $dirData) {
            $dir = $dirData['dir'];
            $owner = $dirData['owner'];
            $mode = $dirData['mode'];

            \Deployer\run("sudo chown -RH $owner $dir");
            \Deployer\run("sudo chmod -R $mode $dir");
        }
    }
61001
def find_home
      ['HOME', 'USERPROFILE'].each {|e| return ENV[e] if ENV[e] }
      return "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}" if ENV['HOMEDRIVE'] && ENV['HOMEPATH']
      File.expand_path("~")
    rescue
      File::ALT_SEPARATOR ? "C:/" : "/"
    end
424592
def collapseuser(path):
    """"""
    home = os.path.join(os.path.expanduser("~"), "")
    if path.startswith(home):
        path = os.path.join("~", path[len(home):])
    return path
430443
public static void makehome(String home) throws Exception {
		File homedir = new File(home);
		if (!homedir.exists()) {
			try {
				homedir.mkdirs();
			} catch (Exception ex) {
				throw new Exception("Can not mkdir :" + home + " Maybe include special charactor!");
			}
		}
	}
215888
def home
      ['HOME', 'USERPROFILE'].each {|e| return ENV[e] if ENV[e] }
      return "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}" if ENV['HOMEDRIVE'] && ENV['HOMEPATH']
      File.expand_path("~")
    rescue
      File::ALT_SEPARATOR ? "C:/" : "/"
    end
1070396
def expand_dir(_dir, cwd=os.getcwd()):
    
    _dir = os.path.expanduser(os.path.expandvars(_dir))
    if not os.path.isabs(_dir):
        _dir = os.path.normpath(os.path.join(cwd, _dir))
    return _dir