def get_uid_gid(username, groupname=None):
  """Try to change UID and GID to the provided values.
  The parameters are given as names like 'nobody' not integer.
  May raise KeyError.

  Src: http://mail.mems-exchange.org/durusmail/quixote-users/4940/1/
  """
  try:
    uid, default_grp = pwd.getpwnam(username)[2:4]
  except __HOLE__:
    raise KeyError("Couldn't get user id for user %s" % (username,))
  if groupname is None:
    gid = default_grp
  else:
    try:
      gid = grp.getgrnam(groupname)[2]
    except KeyError:
      raise KeyError("Couldn't get group id for group %s" % (groupname,))
  return (uid, gid)
dataset/ETHPy150Open cloudera/hue/desktop/core/src/desktop/lib/daemon_utils.py/get_uid_gid