1504
1511
raise errors.BzrError('You must have one of BZR_HOME, APPDATA,'
1505
1512
' or HOME set')
1506
1513
return osutils.pathjoin(base, 'bazaar', '2.0')
1507
elif sys.platform == 'darwin':
1515
if base is not None:
1516
base = base.decode(osutils._fs_enc)
1517
if sys.platform == 'darwin':
1508
1518
if base is None:
1509
1519
# this takes into account $HOME
1510
1520
base = os.path.expanduser("~")
1511
1521
return osutils.pathjoin(base, '.bazaar')
1513
1523
if base is None:
1515
1524
xdg_dir = os.environ.get('XDG_CONFIG_HOME', None)
1516
1525
if xdg_dir is None:
1517
1526
xdg_dir = osutils.pathjoin(os.path.expanduser("~"), ".config")
2265
2273
value, in which config files it can be stored, etc (TBC).
2268
def __init__(self, name, default=None):
2276
def __init__(self, name, default=None, help=None):
2269
2277
self.name = name
2270
2278
self.default = default
2272
2281
def get_default(self):
2273
2282
return self.default
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.')
2285
option_registry.register(
2286
'dirstate.fdatasync', Option('dirstate.fdatasync', default=True),
2287
help='Flush dirstate changes onto physical disk?')
2289
option_registry.register(
2290
'repository.fdatasync',
2291
Option('repository.fdatasync', default=True),
2292
help='Flush repository changes onto physical disk?')
2285
class OptionRegistry(registry.Registry):
2286
"""Register config options by their name.
2288
This overrides ``registry.Registry`` to simplify registration by acquiring
2289
some information from the option object itself.
2292
def register(self, option):
2293
"""Register a new option to its name.
2295
:param option: The option to register. Its name is used as the key.
2297
super(OptionRegistry, self).register(option.name, option,
2300
def register_lazy(self, key, module_name, member_name):
2301
"""Register a new option to be loaded on request.
2303
:param key: This is the key to use to request the option later. Since
2304
the registration is lazy, it should be provided and match the
2307
:param module_name: The python path to the module. Such as 'os.path'.
2309
:param member_name: The member of the module to return. If empty or
2310
None, get() will return the module itself.
2312
super(OptionRegistry, self).register_lazy(key,
2313
module_name, member_name)
2315
def get_help(self, key=None):
2316
"""Get the help text associated with the given key"""
2317
option = self.get(key)
2318
the_help = option.help
2319
if callable(the_help):
2320
return the_help(self, key)
2324
option_registry = OptionRegistry()
2327
# Registered options in lexicographical order
2329
option_registry.register(
2330
Option('dirstate.fdatasync', default=True,
2332
Flush dirstate changes onto physical disk?
2334
If true (default), working tree metadata changes are flushed through the
2335
OS buffers to physical disk. This is somewhat slower, but means data
2336
should not be lost if the machine crashes. See also repository.fdatasync.
2338
option_registry.register(
2339
Option('default_format', default='2a',
2340
help='Format used when creating branches.'))
2341
option_registry.register(
2343
help='The command called to launch an editor to enter a message.'))
2344
option_registry.register(
2346
help='Language to translate messages into.'))
2347
option_registry.register(
2348
Option('output_encoding',
2349
help= 'Unicode encoding for output'
2350
' (terminal encoding if not specified).'))
2351
option_registry.register(
2352
Option('repository.fdatasync', default=True,
2354
Flush repository changes onto physical disk?
2356
If true (default), repository changes are flushed through the OS buffers
2357
to physical disk. This is somewhat slower, but means data should not be
2358
lost if the machine crashes. See also dirstate.fdatasync.
2295
2362
class Section(object):
2562
2629
class GlobalStore(LockableIniFileStore):
2564
2631
def __init__(self, possible_transports=None):
2565
t = transport.get_transport(config_dir(),
2566
possible_transports=possible_transports)
2632
t = transport.get_transport_from_path(
2633
config_dir(), possible_transports=possible_transports)
2567
2634
super(GlobalStore, self).__init__(t, 'bazaar.conf')
2570
2637
class LocationStore(LockableIniFileStore):
2572
2639
def __init__(self, possible_transports=None):
2573
t = transport.get_transport(config_dir(),
2574
possible_transports=possible_transports)
2640
t = transport.get_transport_from_path(
2641
config_dir(), possible_transports=possible_transports)
2575
2642
super(LocationStore, self).__init__(t, 'locations.conf')