259
264
'sha1': s.hexdigest()}
263
"""Return per-user configuration directory.
265
By default this is ~/.bzr.conf/
267
TODO: Global option --config-dir to override this.
269
return os.path.join(os.path.expanduser("~"), ".bzr.conf")
273
"""Calculate automatic user identification.
275
Returns (realname, email).
277
Only used when none is set in the environment or the id file.
279
This previously used the FQDN as the default domain, but that can
280
be very slow on machines where DNS is broken. So now we simply
285
# XXX: Any good way to get real user name on win32?
290
w = pwd.getpwuid(uid)
291
gecos = w.pw_gecos.decode(bzrlib.user_encoding)
292
username = w.pw_name.decode(bzrlib.user_encoding)
293
comma = gecos.find(',')
297
realname = gecos[:comma]
303
realname = username = getpass.getuser().decode(bzrlib.user_encoding)
305
return realname, (username + '@' + socket.gethostname())
308
def _get_user_id(branch):
309
"""Return the full user id from a file or environment variable.
311
e.g. "John Hacker <jhacker@foo.org>"
314
A branch to use for a per-branch configuration, or None.
316
The following are searched in order:
319
2. .bzr/email for this branch.
323
v = os.environ.get('BZREMAIL')
325
return v.decode(bzrlib.user_encoding)
329
return (branch.controlfile("email", "r")
331
.decode(bzrlib.user_encoding)
334
if e.errno != errno.ENOENT:
340
return (open(os.path.join(config_dir(), "email"))
342
.decode(bzrlib.user_encoding)
345
if e.errno != errno.ENOENT:
348
v = os.environ.get('EMAIL')
350
return v.decode(bzrlib.user_encoding)
355
def username(branch):
356
"""Return email-style username.
358
Something similar to 'Martin Pool <mbp@sourcefrog.net>'
360
TODO: Check it's reasonably well-formed.
362
v = _get_user_id(branch)
366
name, email = _auto_user_id()
368
return '%s <%s>' % (name, email)
373
def user_email(branch):
374
"""Return just the email component of a username."""
375
e = _get_user_id(branch)
377
m = re.search(r'[\w+.-]+@[\w+.-]+', e)
379
raise BzrError("%r doesn't seem to contain "
380
"a reasonable email address" % e)
383
return _auto_user_id()[1]
386
267
def compare_files(a, b):
387
268
"""Returns true if equal in contents"""
511
392
return os.path.join(p1, p2)
514
def _read_config_value(name):
515
"""Read a config value from the file ~/.bzr.conf/<name>
516
Return None if the file does not exist"""
518
f = file(os.path.join(config_dir(), name), "r")
519
return f.read().decode(bzrlib.user_encoding).rstrip("\r\n")
521
if e.errno == errno.ENOENT:
526
395
def split_lines(s):
527
396
"""Split s into lines, but without removing the newline characters."""
528
397
return StringIO(s).readlines()