~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

Merge from integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
 
55
55
import errno
56
56
import os
 
57
import sys
57
58
from fnmatch import fnmatch
58
59
import re
59
60
 
133
134
 
134
135
    def user_email(self):
135
136
        """Return just the email component of a username."""
136
 
        e = self.username()
137
 
        m = re.search(r'[\w+.-]+@[\w+.-]+', e)
138
 
        if not m:
139
 
            raise BzrError("%r doesn't seem to contain "
140
 
                           "a reasonable email address" % e)
141
 
        return m.group(0)
 
137
        return extract_email_address(self.username())
142
138
 
143
139
    def username(self):
144
140
        """Return email-style username.
147
143
        
148
144
        $BZREMAIL can be set to override this, then
149
145
        the concrete policy type is checked, and finally
150
 
        $EMAIL is examinged.
151
 
        but if none is found, a reasonable default is (hopefully)
 
146
        $EMAIL is examined.
 
147
        If none is found, a reasonable default is (hopefully)
152
148
        created.
153
149
    
154
150
        TODO: Check it's reasonably well-formed.
419
415
    
420
416
    TODO: Global option --config-dir to override this.
421
417
    """
422
 
    return os.path.join(os.path.expanduser("~"), ".bazaar")
 
418
    base = os.environ.get('BZR_HOME', None)
 
419
    if sys.platform == 'win32':
 
420
        if base is None:
 
421
            base = os.environ.get('APPDATA', None)
 
422
        if base is None:
 
423
            base = os.environ.get('HOME', None)
 
424
        if base is None:
 
425
            raise BzrError('You must have one of BZR_HOME, APPDATA, or HOME set')
 
426
        return os.path.join(base, 'bazaar', '2.0')
 
427
    else:
 
428
        # cygwin, linux, and darwin all have a $HOME directory
 
429
        if base is None:
 
430
            base = os.path.expanduser("~")
 
431
        return os.path.join(base, ".bazaar")
423
432
 
424
433
 
425
434
def config_filename():
480
489
    """
481
490
    m = re.search(r'[\w+.-]+@[\w+.-]+', e)
482
491
    if not m:
483
 
        raise BzrError("%r doesn't seem to contain "
484
 
                       "a reasonable email address" % e)
 
492
        raise errors.BzrError("%r doesn't seem to contain "
 
493
                              "a reasonable email address" % e)
485
494
    return m.group(0)
486
495
 
487
496
class TreeConfig(object):