~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

MergeĀ fromĀ martin

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
 
61
61
import bzrlib
62
62
import bzrlib.errors as errors
 
63
from bzrlib.osutils import pathjoin
 
64
from bzrlib.trace import mutter
63
65
import bzrlib.util.configobj.configobj as configobj
64
66
from StringIO import StringIO
65
67
 
348
350
        """Save option and its value in the configuration."""
349
351
        # FIXME: RBC 20051029 This should refresh the parser and also take a
350
352
        # file lock on branches.conf.
351
 
        if not os.path.isdir(os.path.dirname(self._get_filename())):
352
 
            os.mkdir(os.path.dirname(self._get_filename()))
 
353
        conf_dir = os.path.dirname(self._get_filename())
 
354
        ensure_config_dir_exists(conf_dir)
353
355
        location = self.location
354
356
        if location.endswith('/'):
355
357
            location = location[:-1]
408
410
        return self._get_location_config()._post_commit()
409
411
 
410
412
 
 
413
def ensure_config_dir_exists(path=None):
 
414
    """Make sure a configuration directory exists.
 
415
    This makes sure that the directory exists.
 
416
    On windows, since configuration directories are 2 levels deep,
 
417
    it makes sure both the directory and the parent directory exists.
 
418
    """
 
419
    if path is None:
 
420
        path = config_dir()
 
421
    if not os.path.isdir(path):
 
422
        if sys.platform == 'win32':
 
423
            parent_dir = os.path.dirname(path)
 
424
            if not os.path.isdir(parent_dir):
 
425
                mutter('creating config parent directory: %r', parent_dir)
 
426
            os.mkdir(parent_dir)
 
427
        mutter('creating config directory: %r', path)
 
428
        os.mkdir(path)
 
429
 
 
430
 
411
431
def config_dir():
412
432
    """Return per-user configuration directory.
413
433
 
423
443
            base = os.environ.get('HOME', None)
424
444
        if base is None:
425
445
            raise BzrError('You must have one of BZR_HOME, APPDATA, or HOME set')
426
 
        return os.path.join(base, 'bazaar', '2.0')
 
446
        return pathjoin(base, 'bazaar', '2.0')
427
447
    else:
428
448
        # cygwin, linux, and darwin all have a $HOME directory
429
449
        if base is None:
430
450
            base = os.path.expanduser("~")
431
 
        return os.path.join(base, ".bazaar")
 
451
        return pathjoin(base, ".bazaar")
432
452
 
433
453
 
434
454
def config_filename():
435
455
    """Return per-user configuration ini file filename."""
436
 
    return os.path.join(config_dir(), 'bazaar.conf')
 
456
    return pathjoin(config_dir(), 'bazaar.conf')
437
457
 
438
458
 
439
459
def branches_config_filename():
440
460
    """Return per-user configuration ini file filename."""
441
 
    return os.path.join(config_dir(), 'branches.conf')
 
461
    return pathjoin(config_dir(), 'branches.conf')
442
462
 
443
463
 
444
464
def _auto_user_id():