-def get_operator_info():
- """
- Returns tuple of ``(realname, email)`` about the person running
- the script. If run from a scripts server, get info from Hesiod.
- Otherwise, use the passwd database (email generated probably won't
- actually accept mail). Useful when generating commit messages.
- """
- username = get_operator_name_from_gssapi()
- if username:
- # scripts approach
- hesinfo = subprocess.Popen(["hesinfo", username, "passwd"],stdout=subprocess.PIPE).communicate()[0]
- fields = hesinfo.partition(",")[0]
- realname = fields.rpartition(":")[2]
- return realname, username + "@mit.edu"
- else:
- # more traditional approach, but the email probably doesn't work
- uid = os.getuid()
- if not uid:
- # since root isn't actually a useful designation, but maybe
- # SUDO_USER contains something helpful
- sudo_user = os.getenv("SUDO_USER")
- if not sudo_user:
- raise NoOperatorInfo
- pwdentry = pwd.getpwnam(sudo_user)
- else:
- pwdentry = pwd.getpwuid(uid)
- # XXX: error checking might be nice
- # We follow the Ubuntu convention of gecos being a comma split field
- # with the person's realname being the first entry.
- return pwdentry.pw_gecos.split(",")[0], pwdentry.pw_name + "@" + socket.gethostname()
-