1513
1504
raise errors.BzrError('You must have one of BZR_HOME, APPDATA,'
1514
1505
' or HOME set')
1515
1506
return osutils.pathjoin(base, 'bazaar', '2.0')
1517
if base is not None:
1518
base = base.decode(osutils._fs_enc)
1519
if sys.platform == 'darwin':
1507
elif sys.platform == 'darwin':
1520
1508
if base is None:
1521
1509
# this takes into account $HOME
1522
1510
base = os.path.expanduser("~")
1523
1511
return osutils.pathjoin(base, '.bazaar')
1525
1513
if base is None:
1526
1515
xdg_dir = os.environ.get('XDG_CONFIG_HOME', None)
1527
1516
if xdg_dir is None:
1528
1517
xdg_dir = osutils.pathjoin(os.path.expanduser("~"), ".config")
2275
2265
value, in which config files it can be stored, etc (TBC).
2278
def __init__(self, name, default=None, help=None):
2268
def __init__(self, name, default=None):
2279
2269
self.name = name
2280
2270
self.default = default
2283
2272
def get_default(self):
2284
2273
return self.default
2287
class OptionRegistry(registry.Registry):
2288
"""Register config options by their name.
2290
This overrides ``registry.Registry`` to simplify registration by acquiring
2291
some information from the option object itself.
2294
def register(self, option):
2295
"""Register a new option to its name.
2297
:param option: The option to register. Its name is used as the key.
2299
super(OptionRegistry, self).register(option.name, option,
2302
def register_lazy(self, key, module_name, member_name):
2303
"""Register a new option to be loaded on request.
2305
:param key: This is the key to use to request the option later. Since
2306
the registration is lazy, it should be provided and match the
2309
:param module_name: The python path to the module. Such as 'os.path'.
2311
:param member_name: The member of the module to return. If empty or
2312
None, get() will return the module itself.
2314
super(OptionRegistry, self).register_lazy(key,
2315
module_name, member_name)
2317
def get_help(self, key=None):
2318
"""Get the help text associated with the given key"""
2319
option = self.get(key)
2320
the_help = option.help
2321
if callable(the_help):
2322
return the_help(self, key)
2326
option_registry = OptionRegistry()
2329
# Registered options in lexicographical order
2331
option_registry.register(
2332
Option('dirstate.fdatasync', default=True,
2334
Flush dirstate changes onto physical disk?
2336
If true (default), working tree metadata changes are flushed through the
2337
OS buffers to physical disk. This is somewhat slower, but means data
2338
should not be lost if the machine crashes. See also repository.fdatasync.
2340
option_registry.register(
2341
Option('default_format', default='2a',
2342
help='Format used when creating branches.'))
2343
option_registry.register(
2345
help='The command called to launch an editor to enter a message.'))
2346
option_registry.register(
2348
help='Language to translate messages into.'))
2349
option_registry.register(
2350
Option('output_encoding',
2351
help= 'Unicode encoding for output'
2352
' (terminal encoding if not specified).'))
2353
option_registry.register(
2354
Option('repository.fdatasync', default=True,
2356
Flush repository changes onto physical disk?
2358
If true (default), repository changes are flushed through the OS buffers
2359
to physical disk. This is somewhat slower, but means data should not be
2360
lost if the machine crashes. See also dirstate.fdatasync.
2278
option_registry = registry.Registry()
2281
option_registry.register(
2282
'editor', Option('editor'),
2283
help='The command called to launch an editor to enter a message.')
2364
2286
class Section(object):
2631
2553
class GlobalStore(LockableIniFileStore):
2633
2555
def __init__(self, possible_transports=None):
2634
t = transport.get_transport_from_path(
2635
config_dir(), possible_transports=possible_transports)
2556
t = transport.get_transport(config_dir(),
2557
possible_transports=possible_transports)
2636
2558
super(GlobalStore, self).__init__(t, 'bazaar.conf')
2639
2561
class LocationStore(LockableIniFileStore):
2641
2563
def __init__(self, possible_transports=None):
2642
t = transport.get_transport_from_path(
2643
config_dir(), possible_transports=possible_transports)
2564
t = transport.get_transport(config_dir(),
2565
possible_transports=possible_transports)
2644
2566
super(LocationStore, self).__init__(t, 'locations.conf')