Change the gid for a named group

    CLI Example:

    .. code-block:: bash

        salt '*' group.chgid foo 4376
550888
def chgid(name, gid):
    '''
    
    '''
    if not isinstance(gid, int):
        raise SaltInvocationError('gid must be an integer')
    pre_gid = __salt__['file.group_to_gid'](name)
    pre_info = info(name)
    if not pre_info:
        raise CommandExecutionError(
            'Group \'{0}\' does not exist'.format(name)
        )
    if gid == pre_info['gid']:
        return True
    cmd = ['dseditgroup', '-o', 'edit', '-i', gid, name]
    return __salt__['cmd.retcode'](cmd, python_shell=False) == 0
254948
def chugid(runas, group=None):
    '''
    
    '''
    uinfo = pwd.getpwnam(runas)
    supgroups = []
    supgroups_seen = set()

    if group:
        try:
            target_pw_gid = grp.getgrnam(group).gr_gid
        except KeyError as err:
            raise CommandExecutionError(
                'Failed to fetch the GID for {0}. Error: {1}'.format(
                    group, err
                )
            )
    else:
        target_pw_gid = uinfo.pw_gid

    # The line below used to exclude the current user's primary gid.
    # However, when root belongs to more than one group
    # this causes root's primary group of '0' to be dropped from
    # his grouplist.  On FreeBSD, at least, this makes some
    # command executions fail with 'access denied'.
    #
    # The Python documentation says that os.setgroups sets only
    # the supplemental groups for a running process.  On FreeBSD
    # this does not appear to be strictly true.
    group_list = get_group_dict(runas, include_default=True)
    if sys.platform == 'darwin':
        group_list = dict((k, v) for k, v in six.iteritems(group_list)
                          if not k.startswith('_'))
    for group_name in group_list:
        gid = group_list[group_name]
        if (gid not in supgroups_seen
           and not supgroups_seen.add(gid)):
            supgroups.append(gid)

    if os.getgid() != target_pw_gid:
        try:
            os.setgid(target_pw_gid)
        except OSError as err:
            raise CommandExecutionError(
                'Failed to change from gid {0} to {1}. Error: {2}'.format(
                    os.getgid(), target_pw_gid, err
                )
            )

    # Set supplemental groups
    if sorted(os.getgroups()) != sorted(supgroups):
        try:
            os.setgroups(supgroups)
        except OSError as err:
            raise CommandExecutionError(
                'Failed to set supplemental groups to {0}. Error: {1}'.format(
                    supgroups, err
                )
            )

    if os.getuid() != uinfo.pw_uid:
        try:
            os.setuid(uinfo.pw_uid)
        except OSError as err:
            raise CommandExecutionError(
                'Failed to change from uid {0} to {1}. Error: {2}'.format(
                    os.getuid(), uinfo.pw_uid, err
                )
            )
229845
function rename_group($gid, $name, &$new_gid)
    {
        // make sure we have a unique name
        $name = $this->unique_groupname($name);

        $sql_result = $this->db->query(
            "UPDATE " . $this->db->table_name($this->db_groups, true).
            " SET `name` = ?, `changed` = ".$this->db->now().
            " WHERE `contactgroup_id` = ?".
                " AND `user_id` = ?",
            $name, $gid, $this->user_id
        );

        return $this->db->affected_rows($sql_result) ? $name : false;
    }
421428
def change_group(self, name, group):
		
		m1 = OmapiMessage.open(b"host")
		m1.update_object(dict(name=name))
		r1 = self.query_server(m1)
		if r1.opcode != OMAPI_OP_UPDATE:
			raise OmapiError("opening host %s failed" % name)
		m2 = OmapiMessage.update(r1.handle)
		m2.update_object(dict(group=group))
		r2 = self.query_server(m2)
		if r2.opcode != OMAPI_OP_UPDATE:
			raise OmapiError("changing group of host %s to %s failed" % (name, group))
489276
def chgrp(path, group):
    '''
    
    '''
    path = os.path.expanduser(path)

    user = get_user(path)
    return chown(path, user, group)
433064
private void configureUserName(JobConf job) throws IOException {
    UnixUserGroupInformation ugi = getUGI(job);
   // Set the user's name, group and working directory
    job.setUser(ugi.getUserName());
    if (ugi.getGroupNames() != null && ugi.getGroupNames().length > 0) {
      job.set("group.name", ugi.getGroupNames()[0]);
    }
    if (job.getWorkingDirectory() == null) {
      job.setWorkingDirectory(fs.getWorkingDirectory());
    }
  }
220379
@NotNull
    @ObjectiveCName("requestIntegrationTokenCommandWithGid:")
    public Command<String> requestIntegrationToken(int gid) {
        return callback -> modules.getGroupsModule().requestIntegrationToken(gid)
                .then(v -> callback.onResult(v))
                .failure(e -> callback.onError(e));
    }
1356935
def cli(ctx, group_id, users=None):
    
    return ctx.gi.groups.update_membership(group_id, users=users)
74072
def add(name, gid=None, system=False, root=None):
    '''
    
    '''
    cmd = 'mkgroup '
    if system and root is not None:
        cmd += '-a '

    if gid:
        cmd += 'id={0} '.format(gid)

    cmd += name

    ret = __salt__['cmd.run_all'](cmd, python_shell=False)

    return not ret['retcode']
46300
def _list_gids():
    '''
    
    '''
    output = __salt__['cmd.run'](
        ['dscacheutil', '-q', 'group'],
        output_loglevel='quiet',
        python_shell=False
    )
    ret = set()
    for line in salt.utils.itertools.split(output, '\n'):
        if line.startswith('gid:'):
            ret.update(line.split()[1:])
    return sorted(ret)
57511
@ObjectiveCName("doCallWithGid:")
    public Command<Long> doGroupCall(int gid) {
        return modules.getCallsModule().makeCall(Peer.group(gid), false);
    }
252468
def get_default_group(user):
    '''
    
    '''
    return grp.getgrgid(pwd.getpwnam(user).pw_gid).gr_name \
        if HAS_GRP and HAS_PWD \
        else None
514112
def cli(ctx, group, user):
    
    return ctx.gi.users.add_to_group(group, user)
723039
def add_user_to_group(username, group):
    """"""
    cmd = ['gpasswd', '-a', username, group]
    log("Adding user {} to group {}".format(username, group))
    subprocess.check_call(cmd)
24231
@ObjectiveCName("changeGroupAvatarWithGid:withDescriptor:")
    public void changeGroupAvatar(int gid, String descriptor) {
        modules.getGroupsModule().changeAvatar(gid, descriptor);
    }
1307632
def chgid(name, gid):
    '''
    
    '''
    if not isinstance(gid, int):
        raise SaltInvocationError('gid must be an integer')
    pre_info = info(name)
    if not pre_info:
        raise CommandExecutionError('User \'{0}\' does not exist'.format(name))
    if gid == pre_info['gid']:
        return True
    _dscl(
        ['/Users/{0}'.format(name), 'PrimaryGroupID', pre_info['gid'], gid],
        ctype='change'
    )
    # dscl buffers changes, sleep 1 second before checking if new value
    # matches desired value
    time.sleep(1)
    return info(name).get('gid') == gid
794884
public function updateGroup($gid, $name = null) {
		$group = WechatUserGroup::findOne($gid);
		if(!$group) {
			throw new ErrorException('数据查询失败');
		}

		$data = $this->getData('/cgi-bin/groups/update', [
			'access_token' => $this->getAccessToken(),
		], Json::encode([
			'group' => ['id' => $group->gid, 'name' => $name ? : $group->name],
		]));

		$result = $this->errcode == 0;
		if($result && $name) {
			$group->name = $name;
			$group->save();
		}

		return $result;
	}