def get_uid_gid(cp, section):
    uid = cp.get(section, 'uid')
    if uid:
        try:
            int(uid)
        except ValueError:
            # convert user name to uid
            try:
                uid = pwd.getpwnam(uid)[2]
            except KeyError:
                raise ValueError("user is not in password database: %s" % uid)

    gid = cp.get(section, 'gid')
    if gid:
        try:
            int(gid)
        except ValueError:
            # convert group name to gid
            try:
                gid = grp.getgrnam(gid)[2]
            except KeyError:
                raise ValueError("group is not in group database: %s" % gid)

    return uid, gid
Get a numeric uid/gid from a configuration file.
dataset/ETHPy150Open kiberpipa/Intranet/pipa/ltsp/src/ltsp_usage_monitor/daemon.py/get_uid_gid