258
258
Something similar to 'Martin Pool <mbp@sourcefrog.net>'
260
$BZR_EMAIL can be set to override this, then
260
$BZR_EMAIL can be set to override this (as well as the
261
deprecated $BZREMAIL), then
261
262
the concrete policy type is checked, and finally
262
263
$EMAIL is examined.
263
If no username can be found, errors.NoWhoami exception is raised.
264
If none is found, a reasonable default is (hopefully)
265
267
TODO: Check it's reasonably well-formed.
277
279
return v.decode(osutils.get_user_encoding())
279
raise errors.NoWhoami()
281
def ensure_username(self):
282
"""Raise errors.NoWhoami if username is not set.
284
This method relies on the username() function raising the error.
281
name, email = _auto_user_id()
283
return '%s <%s>' % (name, email)
288
287
def signature_checking(self):
289
288
"""What is the current policy for signature checking?."""
900
899
return os.path.expanduser('~/.cache')
903
"""Calculate automatic user identification.
905
Returns (realname, email).
907
Only used when none is set in the environment or the id file.
909
This previously used the FQDN as the default domain, but that can
910
be very slow on machines where DNS is broken. So now we simply
915
if sys.platform == 'win32':
916
name = win32utils.get_user_name_unicode()
918
raise errors.BzrError("Cannot autodetect user name.\n"
919
"Please, set your name with command like:\n"
920
'bzr whoami "Your Name <name@domain.com>"')
921
host = win32utils.get_host_name_unicode()
923
host = socket.gethostname()
924
return name, (name + '@' + host)
930
w = pwd.getpwuid(uid)
932
raise errors.BzrCommandError('Unable to determine your name. '
933
'Please use "bzr whoami" to set it.')
935
# we try utf-8 first, because on many variants (like Linux),
936
# /etc/passwd "should" be in utf-8, and because it's unlikely to give
937
# false positives. (many users will have their user encoding set to
938
# latin-1, which cannot raise UnicodeError.)
940
gecos = w.pw_gecos.decode('utf-8')
944
encoding = osutils.get_user_encoding()
945
gecos = w.pw_gecos.decode(encoding)
947
raise errors.BzrCommandError('Unable to determine your name. '
948
'Use "bzr whoami" to set it.')
950
username = w.pw_name.decode(encoding)
952
raise errors.BzrCommandError('Unable to determine your name. '
953
'Use "bzr whoami" to set it.')
955
comma = gecos.find(',')
959
realname = gecos[:comma]
966
user_encoding = osutils.get_user_encoding()
967
realname = username = getpass.getuser().decode(user_encoding)
968
except UnicodeDecodeError:
969
raise errors.BzrError("Can't decode username as %s." % \
972
return realname, (username + '@' + socket.gethostname())
903
975
def parse_username(username):
904
976
"""Parse e-mail username and return a (name, address) tuple."""
905
977
match = re.match(r'(.*?)\s*<?([\w+.-]+@[\w+.-]+)>?', username)