1557
1556
def xdg_cache_dir():
1558
1557
# See http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html
1559
1558
# Possibly this should be different on Windows?
1560
e = os.environ.get('XDG_CACHE_HOME', None)
1559
e = os.environ.get('XDG_CACHE_DIR', None)
2136
2135
class Base64CredentialStore(CredentialStore):
2137
2136
__doc__ = """Base64 credential store for the authentication.conf file"""
2139
2138
def decode_password(self, credentials):
2140
2139
"""See CredentialStore.decode_password."""
2141
2140
# GZ 2012-07-28: Will raise binascii.Error if password is not base64,
2161
2160
for those under repositories.
2163
2162
if self._config is None:
2164
raise errors.BzrError("Cannot set configuration in %s"
2163
raise errors.BzrError("Cannot set configuration in %s" % self._bzrdir)
2166
2164
if value is None:
2167
2165
self._config.set_option('', 'default_stack_on')
2316
2314
:param help: a doc string to explain the option to the user.
2318
2316
:param from_unicode: a callable to convert the unicode string
2319
representing the option value in a store or its default value.
2317
representing the option value in a store. This is not called for
2321
2320
:param invalid: the action to be taken when an invalid value is
2322
2321
encountered in a store. This is called only when from_unicode is
2473
2472
return float(unicode_str)
2476
# Use an empty dict to initialize an empty configobj avoiding all parsing and
2475
# Use a an empty dict to initialize an empty configobj avoiding all
2476
# parsing and encoding checks
2478
2477
_list_converter_config = configobj.ConfigObj(
2479
2478
{}, encoding='utf-8', list_values=True, interpolation=False)
2552
2551
return "".join(ret)
2555
_option_ref_re = lazy_regex.lazy_compile('({[^\d\W](?:\.\w|\w)*})')
2556
"""Describes an expandable option reference.
2558
We want to match the most embedded reference first.
2560
I.e. for '{{foo}}' we will get '{foo}',
2561
for '{bar{baz}}' we will get '{baz}'
2564
def iter_option_refs(string):
2565
# Split isolate refs so every other chunk is a ref
2567
for chunk in _option_ref_re.split(string):
2572
2554
class OptionRegistry(registry.Registry):
2573
2555
"""Register config options by their name.
2576
2558
some information from the option object itself.
2579
def _check_option_name(self, option_name):
2580
"""Ensures an option name is valid.
2582
:param option_name: The name to validate.
2584
if _option_ref_re.match('{%s}' % option_name) is None:
2585
raise errors.IllegalOptionName(option_name)
2587
2561
def register(self, option):
2588
2562
"""Register a new option to its name.
2590
2564
:param option: The option to register. Its name is used as the key.
2592
self._check_option_name(option.name)
2593
2566
super(OptionRegistry, self).register(option.name, option,
2594
2567
help=option.help)
2604
2577
:param member_name: the member of the module to return. If empty or
2605
2578
None, get() will return the module itself.
2607
self._check_option_name(key)
2608
2580
super(OptionRegistry, self).register_lazy(key,
2609
2581
module_name, member_name)
2830
2802
Each function takes branch, rev_id as parameters.
2832
option_registry.register_lazy('progress_bar', 'bzrlib.ui.text',
2834
2804
option_registry.register(
2835
2805
Option('public_branch',
2973
2943
self.options[name] = value
2975
2945
def remove(self, name):
2976
if name not in self.orig and name in self.options:
2946
if name not in self.orig:
2977
2947
self.orig[name] = self.get(name, None)
2978
2948
del self.options[name]
3413
3382
# on the relevant parts of the API that needs testing -- vila 20110503 (based
3414
3383
# on a poolie's remark)
3415
3384
class GlobalStore(LockableIniFileStore):
3416
"""A config store for global options.
3418
There is a single GlobalStore for a given process.
3421
3386
def __init__(self, possible_transports=None):
3422
3387
t = transport.get_transport_from_path(
3428
3393
class LocationStore(LockableIniFileStore):
3429
"""A config store for options specific to a location.
3431
There is a single LocationStore for a given process.
3434
3395
def __init__(self, possible_transports=None):
3435
3396
t = transport.get_transport_from_path(
3441
3402
class BranchStore(TransportIniFileStore):
3442
"""A config store for branch options.
3444
There is a single BranchStore for a given branch.
3447
3404
def __init__(self, branch):
3448
3405
super(BranchStore, self).__init__(branch.control_transport,
3649
3606
yield self.store, section
3652
# FIXME: _shared_stores should be an attribute of a library state once a
3653
# library_state object is always available.
3655
_shared_stores_at_exit_installed = False
3609
_option_ref_re = lazy_regex.lazy_compile('({[^{}\n]+})')
3610
"""Describes an expandable option reference.
3612
We want to match the most embedded reference first.
3614
I.e. for '{{foo}}' we will get '{foo}',
3615
for '{bar{baz}}' we will get '{baz}'
3618
def iter_option_refs(string):
3619
# Split isolate refs so every other chunk is a ref
3621
for chunk in _option_ref_re.split(string):
3657
3626
class Stack(object):
3658
3627
"""A stack of configurations where an option can be defined"""
3847
3816
return "<config.%s(%s)>" % (self.__class__.__name__, id(self))
3849
3818
def _get_overrides(self):
3850
# FIXME: Hack around library_state.initialize never called
3819
# Hack around library_state.initialize never called
3851
3820
if bzrlib.global_state is not None:
3852
3821
return bzrlib.global_state.cmdline_overrides.get_sections()
3855
def get_shared_store(self, store, state=None):
3856
"""Get a known shared store.
3858
Store urls uniquely identify them and are used to ensure a single copy
3859
is shared across all users.
3861
:param store: The store known to the caller.
3863
:param state: The library state where the known stores are kept.
3865
:returns: The store received if it's not a known one, an already known
3869
state = bzrlib.global_state
3871
global _shared_stores_at_exit_installed
3872
stores = _shared_stores
3873
def save_config_changes():
3874
for k, store in stores.iteritems():
3875
store.save_changes()
3876
if not _shared_stores_at_exit_installed:
3877
# FIXME: Ugly hack waiting for library_state to always be
3878
# available. -- vila 20120731
3880
atexit.register(save_config_changes)
3881
_shared_stores_at_exit_installed = True
3883
stores = state.config_stores
3884
url = store.external_url()
3892
3825
class MemoryStack(Stack):
3893
3826
"""A configuration stack defined from a string.
3959
3892
def __init__(self):
3960
gstore = self.get_shared_store(GlobalStore())
3893
gstore = GlobalStore()
3961
3894
super(GlobalStack, self).__init__(
3962
3895
[self._get_overrides,
3963
3896
NameMatcher(gstore, 'DEFAULT').get_sections],
3964
3897
gstore, mutable_section_id='DEFAULT')
3967
class LocationStack(Stack):
3900
class LocationStack(_CompatibleStack):
3968
3901
"""Per-location options falling back to global options stack.
3986
3919
"""Make a new stack for a location and global configuration.
3988
3921
:param location: A URL prefix to """
3989
lstore = self.get_shared_store(LocationStore())
3922
lstore = LocationStore()
3990
3923
if location.startswith('file://'):
3991
3924
location = urlutils.local_path_from_url(location)
3992
gstore = self.get_shared_store(GlobalStore())
3925
gstore = GlobalStore()
3993
3926
super(LocationStack, self).__init__(
3994
3927
[self._get_overrides,
3995
3928
LocationMatcher(lstore, location).get_sections,
4019
3952
def __init__(self, branch):
4020
lstore = self.get_shared_store(LocationStore())
3953
lstore = LocationStore()
4021
3954
bstore = branch._get_config_store()
4022
gstore = self.get_shared_store(GlobalStore())
3955
gstore = GlobalStore()
4023
3956
super(BranchStack, self).__init__(
4024
3957
[self._get_overrides,
4025
3958
LocationMatcher(lstore, branch.base).get_sections,
4047
3980
# unlock saves all the changes.
4050
class RemoteControlStack(Stack):
3983
class RemoteControlStack(_CompatibleStack):
4051
3984
"""Remote control-only options stack."""
4053
3986
# FIXME 2011-11-22 JRV This should probably be renamed to avoid confusion
4098
4031
class cmd_config(commands.Command):
4099
4032
__doc__ = """Display, set or remove a configuration option.
4101
Display the active value for option NAME.
4034
Display the active value for a given option.
4103
4036
If --all is specified, NAME is interpreted as a regular expression and all
4104
matching options are displayed mentioning their scope and without resolving
4105
option references in the value). The active value that bzr will take into
4106
account is the first one displayed for each option.
4108
If NAME is not given, --all .* is implied (all options are displayed for the
4111
Setting a value is achieved by using NAME=value without spaces. The value
4037
matching options are displayed mentioning their scope. The active value
4038
that bzr will take into account is the first one displayed for each option.
4040
If no NAME is given, --all .* is implied.
4042
Setting a value is achieved by using name=value without spaces. The value
4112
4043
is set in the most relevant scope and can be checked by displaying the
4115
Removing a value is achieved by using --remove NAME.
4118
4047
takes_args = ['name?']