155
def signature_policy_from_unicode(signature_string):
156
"""Convert a string to a signing policy."""
157
if signature_string.lower() == 'check-available':
158
return CHECK_IF_POSSIBLE
159
if signature_string.lower() == 'ignore':
161
if signature_string.lower() == 'require':
163
raise ValueError("Invalid signatures policy '%s'"
167
def signing_policy_from_unicode(signature_string):
168
"""Convert a string to a signing policy."""
169
if signature_string.lower() == 'when-required':
170
return SIGN_WHEN_REQUIRED
171
if signature_string.lower() == 'never':
173
if signature_string.lower() == 'always':
175
raise ValueError("Invalid signing policy '%s'"
155
179
class ConfigObj(configobj.ConfigObj):
157
181
def __init__(self, infile=None, **kwargs):
417
441
# add) the final ','
421
def get_user_option_as_int_from_SI(self, option_name, default=None):
445
def get_user_option_as_int_from_SI(self, option_name, default=None):
422
446
"""Get a generic option from a human readable size in SI units, e.g 10MB
424
448
Accepted suffixes are K,M,G. It is case-insensitive and may be followed
425
449
by a trailing b (i.e. Kb, MB). This is intended to be practical and not
428
452
:return Integer, expanded to its base-10 value if a proper SI unit is
429
453
found. If the option doesn't exist, or isn't a value in
430
454
SI units, return default (which defaults to None)
925
947
"""See Config.post_commit."""
926
948
return self._get_user_option('post_commit')
928
def _string_to_signature_policy(self, signature_string):
929
"""Convert a string to a signing policy."""
930
if signature_string.lower() == 'check-available':
931
return CHECK_IF_POSSIBLE
932
if signature_string.lower() == 'ignore':
934
if signature_string.lower() == 'require':
936
raise errors.BzrError("Invalid signatures policy '%s'"
939
def _string_to_signing_policy(self, signature_string):
940
"""Convert a string to a signing policy."""
941
if signature_string.lower() == 'when-required':
942
return SIGN_WHEN_REQUIRED
943
if signature_string.lower() == 'never':
945
if signature_string.lower() == 'always':
947
raise errors.BzrError("Invalid signing policy '%s'"
950
950
def _get_alias(self, value):
952
952
return self._get_parser().get_value("ALIASES",
1638
def default_email():
1639
v = os.environ.get('BZR_EMAIL')
1641
return v.decode(osutils.get_user_encoding())
1642
v = os.environ.get('EMAIL')
1644
return v.decode(osutils.get_user_encoding())
1645
name, email = _auto_user_id()
1647
return u'%s <%s>' % (name, email)
1650
raise errors.NoWhoami()
1653
def email_from_store(unicode_str):
1654
"""Unlike other env vars, BZR_EMAIL takes precedence over config settings.
1656
Whatever comes from a config file is then overridden.
1658
value = os.environ.get('BZR_EMAIL')
1660
return value.decode(osutils.get_user_encoding())
1645
1664
def _auto_user_id():
1646
1665
"""Calculate automatic user identification.
2325
2344
def __init__(self, name, default=None, default_from_env=None,
2327
from_unicode=None, invalid=None):
2345
help=None, from_unicode=None, invalid=None):
2328
2346
"""Build an option definition.
2330
2348
:param name: the name used to refer to the option.
2332
2350
:param default: the default value to use when none exist in the config
2333
2351
stores. This is either a string that ``from_unicode`` will convert
2334
into the proper type or a python object that can be stringified (so
2335
only the empty list is supported for example).
2352
into the proper type, a callable returning a unicode string so that
2353
``from_unicode`` can be used on the return value, or a python
2354
object that can be stringified (so only the empty list is supported
2337
2357
:param default_from_env: A list of environment variables which can
2338
2358
provide a default value. 'default' will be used only if none of the
2401
2423
for var in self.default_from_env:
2403
2425
# If the env variable is defined, its value is the default one
2404
value = os.environ[var]
2426
value = os.environ[var].decode(osutils.get_user_encoding())
2406
2428
except KeyError:
2408
2430
if value is None:
2409
2431
# Otherwise, fallback to the value defined at registration
2410
value = self.default
2432
if callable(self.default):
2433
value = self.default()
2434
if not isinstance(value, unicode):
2435
raise AssertionError(
2436
'Callable default values should be unicode')
2438
value = self.default
2413
2441
def get_help_text(self, additional_see_also=None, plain=True):
2508
2535
# Registered options in lexicographical order
2510
2537
option_registry.register(
2538
Option('append_revisions_only',
2539
default=None, from_unicode=bool_from_store, invalid='warning',
2541
Whether to only append revisions to the mainline.
2543
If this is set to true, then it is not possible to change the
2544
existing mainline of the branch.
2546
option_registry.register(
2547
Option('acceptable_keys',
2548
default=None, from_unicode=list_from_store,
2550
List of GPG key patterns which are acceptable for verification.
2552
option_registry.register(
2511
2553
Option('bzr.workingtree.worth_saving_limit', default=10,
2512
2554
from_unicode=int_from_store, invalid='warning',
2520
2562
a file has been touched.
2522
2564
option_registry.register(
2565
Option('check_signatures', default=CHECK_IF_POSSIBLE,
2566
from_unicode=signature_policy_from_unicode,
2568
GPG checking policy.
2570
Possible values: require, ignore, check-available (default)
2572
this option will control whether bzr will require good gpg
2573
signatures, ignore them, or check them if they are
2576
option_registry.register(
2577
Option('create_signatures', default=SIGN_WHEN_REQUIRED,
2578
from_unicode=signing_policy_from_unicode,
2582
Possible values: always, never, when-required (default)
2584
This option controls whether bzr will always create
2585
gpg signatures or not on commits.
2587
option_registry.register(
2523
2588
Option('dirstate.fdatasync', default=True,
2524
2589
from_unicode=bool_from_store,
2549
2614
Option('editor',
2550
2615
help='The command called to launch an editor to enter a message.'))
2551
2616
option_registry.register(
2617
Option('email', default=default_email,
2618
from_unicode=email_from_store,
2619
help='The users identity'))
2620
option_registry.register(
2621
Option('gpg_signing_command',
2624
Program to use use for creating signatures.
2626
This should support at least the -u and --clearsign options.
2628
option_registry.register(
2629
Option('gpg_signing_key',
2632
GPG key to use for signing.
2634
This defaults to the first key associated with the users email.
2636
option_registry.register(
2552
2637
Option('ignore_missing_extensions', default=False,
2553
2638
from_unicode=bool_from_store,
2584
2669
help= 'Unicode encoding for output'
2585
2670
' (terminal encoding if not specified).'))
2586
2671
option_registry.register(
2672
Option('post_commit', default=None,
2674
Post commit functions.
2676
An ordered list of python functions to call, separated by spaces.
2678
Each function takes branch, rev_id as parameters.
2680
option_registry.register(
2587
2681
Option('push_strict', default=None,
2588
2682
from_unicode=bool_from_store,
2602
2696
to physical disk. This is somewhat slower, but means data should not be
2603
2697
lost if the machine crashes. See also dirstate.fdatasync.
2700
option_registry.register(
2701
Option('selftest.timeout',
2703
from_unicode=int_from_store,
2704
help='Abort selftest if one test takes longer than this many seconds',
2605
2707
option_registry.register(
2606
2708
Option('send_strict', default=None,
2607
2709
from_unicode=bool_from_store,
3381
3483
class GlobalStack(_CompatibleStack):
3382
"""Global options only stack."""
3484
"""Global options only stack.
3486
The following sections are queried:
3488
* command-line overrides,
3490
* the 'DEFAULT' section in bazaar.conf
3492
This stack will use the ``DEFAULT`` section in bazaar.conf as its
3384
3496
def __init__(self):
3386
3497
gstore = GlobalStore()
3387
3498
super(GlobalStack, self).__init__(
3388
[self._get_overrides, NameMatcher(gstore, 'DEFAULT').get_sections],
3499
[self._get_overrides,
3500
NameMatcher(gstore, 'DEFAULT').get_sections],
3389
3501
gstore, mutable_section_id='DEFAULT')
3392
3504
class LocationStack(_CompatibleStack):
3393
"""Per-location options falling back to global options stack."""
3505
"""Per-location options falling back to global options stack.
3508
The following sections are queried:
3510
* command-line overrides,
3512
* the sections matching ``location`` in ``locations.conf``, the order being
3513
defined by the number of path components in the section glob, higher
3514
numbers first (from most specific section to most generic).
3516
* the 'DEFAULT' section in bazaar.conf
3518
This stack will use the ``location`` section in locations.conf as its
3395
3522
def __init__(self, location):
3396
3523
"""Make a new stack for a location and global configuration.
3398
3525
:param location: A URL prefix to """
3399
3526
lstore = LocationStore()
3400
3527
if location.startswith('file://'):
3401
3528
location = urlutils.local_path_from_url(location)
3402
matcher = LocationMatcher(lstore, location)
3403
3529
gstore = GlobalStore()
3404
3530
super(LocationStack, self).__init__(
3405
3531
[self._get_overrides,
3406
matcher.get_sections, NameMatcher(gstore, 'DEFAULT').get_sections],
3532
LocationMatcher(lstore, location).get_sections,
3533
NameMatcher(gstore, 'DEFAULT').get_sections],
3407
3534
lstore, mutable_section_id=location)
3410
3537
class BranchStack(_CompatibleStack):
3411
"""Per-location options falling back to branch then global options stack."""
3538
"""Per-location options falling back to branch then global options stack.
3540
The following sections are queried:
3542
* command-line overrides,
3544
* the sections matching ``location`` in ``locations.conf``, the order being
3545
defined by the number of path components in the section glob, higher
3546
numbers first (from most specific section to most generic),
3548
* the no-name section in branch.conf,
3550
* the ``DEFAULT`` section in ``bazaar.conf``.
3552
This stack will use the no-name section in ``branch.conf`` as its
3413
3556
def __init__(self, branch):
3557
lstore = LocationStore()
3414
3558
bstore = branch._get_config_store()
3415
lstore = LocationStore()
3416
matcher = LocationMatcher(lstore, branch.base)
3417
3559
gstore = GlobalStore()
3418
3560
super(BranchStack, self).__init__(
3419
3561
[self._get_overrides,
3420
matcher.get_sections, bstore.get_sections,
3562
LocationMatcher(lstore, branch.base).get_sections,
3563
NameMatcher(bstore, None).get_sections,
3421
3564
NameMatcher(gstore, 'DEFAULT').get_sections],
3423
3566
self.branch = branch