128
128
'sha1': s.hexdigest()}
133
"""Return email-style username.
135
Something similar to 'Martin Pool <mbp@sourcefrog.net>'
137
:todo: Check it's reasonably well-formed.
139
:todo: Allow taking it from a dotfile to help people on windows
140
who can't easily set variables.
142
:todo: Cope without pwd module, which is only on unix.
132
"""Calculate automatic user identification.
134
Returns (realname, email).
136
Only used when none is set in the environment.
144
e = os.environ.get('BZREMAIL') or os.environ.get('EMAIL')
139
import socket, locale
141
# XXX: Any good way to get real user name on win32?
143
# XXX: can the FQDN be non-ascii?
145
enc = locale.getpreferredencoding()
151
149
uid = os.getuid()
152
150
w = pwd.getpwuid(uid)
151
gecos = w.pw_gecos.decode(enc)
152
username = w.pw_name.decode(enc)
154
153
comma = gecos.find(',')
158
157
realname = gecos[:comma]
159
return '%s <%s@%s>' % (realname, w.pw_name, socket.getfqdn())
159
return realname, (username + '@' + socket.getfqdn())
160
161
except ImportError:
163
import getpass, socket
164
return '<%s@%s>' % (getpass.getuser(), socket.getfqdn())
163
return '', (getpass.getuser().decode(enc) + '@' + socket.getfqdn())
168
"""Return email-style username.
170
Something similar to 'Martin Pool <mbp@sourcefrog.net>'
172
:todo: Check it's reasonably well-formed.
174
:todo: Allow taking it from a dotfile to help people on windows
175
who can't easily set variables.
178
e = os.environ.get('BZREMAIL') or os.environ.get('EMAIL')
180
return e.decode(locale.getpreferredencoding())
182
name, email = auto_user_id()
184
return '%s <%s>' % (name, email)
167
189
_EMAIL_RE = re.compile(r'[\w+.-]+@[\w+.-]+')
168
190
def user_email():
169
191
"""Return just the email component of a username."""
170
192
e = os.environ.get('BZREMAIL') or os.environ.get('EMAIL')
194
e = e.decode(locale.getpreferredencoding())
172
196
m = _EMAIL_RE.search(e)
174
198
bailout('%r is not a reasonable email address' % e)
175
199
return m.group(0)
178
import getpass, socket
179
return '%s@%s' % (getpass.getuser(), socket.getfqdn())
201
return auto_user_id()[1]