~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

[merge] win32

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
 
411
430
def config_dir():
412
431
    """Return per-user configuration directory.
413
432
 
423
442
            base = os.environ.get('HOME', None)
424
443
        if base is None:
425
444
            raise BzrError('You must have one of BZR_HOME, APPDATA, or HOME set')
426
 
        return os.path.join(base, 'bazaar', '2.0')
 
445
        return pathjoin(base, 'bazaar', '2.0')
427
446
    else:
428
447
        # cygwin, linux, and darwin all have a $HOME directory
429
448
        if base is None:
430
449
            base = os.path.expanduser("~")
431
 
        return os.path.join(base, ".bazaar")
 
450
        return pathjoin(base, ".bazaar")
432
451
 
433
452
 
434
453
def config_filename():
435
454
    """Return per-user configuration ini file filename."""
436
 
    return os.path.join(config_dir(), 'bazaar.conf')
 
455
    return pathjoin(config_dir(), 'bazaar.conf')
437
456
 
438
457
 
439
458
def branches_config_filename():
440
459
    """Return per-user configuration ini file filename."""
441
 
    return os.path.join(config_dir(), 'branches.conf')
 
460
    return pathjoin(config_dir(), 'branches.conf')
442
461
 
443
462
 
444
463
def _auto_user_id():