53
53
email - this option sets the user id brz will use when committing.
54
54
check_signatures - this option will control whether brz will require good gpg
55
55
signatures, ignore them, or check them if they are
56
present. Currently it is unused except that check_signatures
57
turns on create_signatures.
56
present. Currently it is unused except that
57
check_signatures turns on create_signatures.
58
58
create_signatures - this option controls whether brz will always create
59
59
gpg signatures or not on commits. There is an unused
60
60
option which in future is expected to work if
236
235
class NoWhoami(errors.BzrError):
238
237
_fmt = ('Unable to determine your name.\n'
239
"Please, set your name with the 'whoami' command.\n"
240
'E.g. brz whoami "Your Name <name@example.com>"')
238
"Please, set your name with the 'whoami' command.\n"
239
'E.g. brz whoami "Your Name <name@example.com>"')
243
242
def signature_policy_from_unicode(signature_string):
628
627
# This should be done through the proposed config defaults mechanism
629
628
# when it becomes available in the future.
630
629
command_line = (self.get_user_option('bzr.mergetool.%s' % name,
632
or mergetools.known_merge_tools.get(name, None))
631
mergetools.known_merge_tools.get(name, None))
633
632
return command_line
678
679
These are all empty initially, because by default nothing should get
681
super(_OldConfigHooks, self).__init__('breezy.config', 'OldConfigHooks')
682
super(_OldConfigHooks, self).__init__(
683
'breezy.config', 'OldConfigHooks')
682
684
self.add_hook('load',
683
685
'Invoked when a config store is loaded.'
684
686
' The signature is (config).',
721
725
def from_string(cls, str_or_unicode, file_name=None, save=False):
722
726
"""Create a config object from a string.
724
:param str_or_unicode: A string representing the file content. This will
728
:param str_or_unicode: A string representing the file content. This
729
will be utf-8 encoded.
727
731
:param file_name: The configuration file path.
950
953
If several processes try to write the config file, the accesses need to be
953
Daughter classes should use the self.lock_write() decorator method when they
954
upate a config (they call, directly or indirectly, the
956
Daughter classes should use the self.lock_write() decorator method when
957
they upate a config (they call, directly or indirectly, the
955
958
``_write_config_file()`` method. These methods (typically ``set_option()``
956
959
and variants must reload the config file from disk before calling
957
960
``_write_config_file()``), this can be achieved by calling the
1009
1012
def remove_user_option(self, option_name, section_name=None):
1010
1013
with self.lock_write():
1011
1014
super(LockableConfig, self).remove_user_option(
1012
option_name, section_name)
1015
option_name, section_name)
1014
1017
def _write_config_file(self):
1015
1018
if self._lock is None or not self._lock.is_held:
1096
1099
# We need to avoid the LockableConfig implementation or we'll lock
1098
1101
super(LockableConfig, self).remove_user_option(
1099
option_name, section_name)
1102
option_name, section_name)
1102
1105
def _iter_for_location_by_parts(sections, location):
1373
1375
def set_user_option(self, name, value, store=STORE_BRANCH,
1375
1377
if store == STORE_BRANCH:
1376
1378
self._get_branch_data_config().set_option(value, name)
1377
1379
elif store == STORE_GLOBAL:
1440
1442
if sys.platform == 'win32':
1441
1443
parent_dir = os.path.dirname(path)
1442
1444
if not os.path.isdir(parent_dir):
1443
trace.mutter('creating config parent directory: %r', parent_dir)
1446
'creating config parent directory: %r', parent_dir)
1444
1447
os.mkdir(parent_dir)
1445
1448
trace.mutter('creating config directory: %r', path)
1451
1454
"""Return per-user configuration directory as unicode string
1453
1456
By default this is %APPDATA%/bazaar/2.0 on Windows, ~/.bazaar on Mac OS X
1454
and Linux. On Mac OS X and Linux, if there is a $XDG_CONFIG_HOME/bazaar directory,
1455
that will be used instead.
1457
and Linux. On Mac OS X and Linux, if there is a $XDG_CONFIG_HOME/bazaar
1458
directory, that will be used instead
1457
1460
TODO: Global option --config-dir to override this.
1614
1617
Only used when none is set in the environment or the id file.
1616
This only returns an email address if we can be fairly sure the
1619
This only returns an email address if we can be fairly sure the
1617
1620
address is reasonable, ie if /etc/mailname is set on unix.
1619
This doesn't use the FQDN as the default domain because that may be
1620
slow, and it doesn't use the hostname alone because that's not normally
1622
This doesn't use the FQDN as the default domain because that may be
1623
slow, and it doesn't use the hostname alone because that's not normally
1621
1624
a reasonable address.
1623
1626
if sys.platform == 'win32':
1658
1661
if isinstance(username, bytes):
1660
1663
username = username.decode(encoding)
1661
except UnicodeError as e:
1664
except UnicodeError:
1662
1665
trace.mutter("cannot decode passwd entry %s" % w)
1663
1666
return None, None
1699
1702
class TreeConfig(IniBasedConfig):
1700
1703
"""Branch configuration data associated with its contents, not location"""
1702
# XXX: Really needs a better name, as this is not part of the tree! -- mbp 20080507
1705
# XXX: Really needs a better name, as this is not part of the tree!
1704
1708
def __init__(self, branch):
1705
1709
self._config = branch._get_config()
1741
1745
def __init__(self, _file=None):
1742
self._config = None # The ConfigObj
1746
self._config = None # The ConfigObj
1743
1747
if _file is None:
1744
1748
self._filename = authentication_config_filename()
1745
1749
self._input = self._filename = authentication_config_filename()
1775
1779
trace.mutter('Unable to stat %r: %r', self._filename, e)
1777
1781
mode = stat.S_IMODE(st.st_mode)
1778
if ((stat.S_IXOTH | stat.S_IWOTH | stat.S_IROTH | stat.S_IXGRP |
1779
stat.S_IWGRP | stat.S_IRGRP ) & mode):
1782
if ((stat.S_IXOTH | stat.S_IWOTH | stat.S_IROTH | stat.S_IXGRP
1783
| stat.S_IWGRP | stat.S_IRGRP) & mode):
1780
1784
# Only warn once
1781
if (not self._filename in _authentication_config_permission_errors
1782
and not GlobalConfig().suppress_warning(
1785
if (self._filename not in _authentication_config_permission_errors and
1786
not GlobalConfig().suppress_warning(
1783
1787
'insecure_permissions')):
1784
1788
trace.warning("The file '%s' has insecure "
1785
"file permissions. Saved passwords may be accessible "
1786
"by other users.", self._filename)
1789
"file permissions. Saved passwords may be accessible "
1790
"by other users.", self._filename)
1787
1791
_authentication_config_permission_errors.add(self._filename)
1789
1793
def _save(self):
1790
1794
"""Save the config file, only tests should use it for now."""
1791
1795
conf_dir = os.path.dirname(self._filename)
1792
1796
ensure_config_dir_exists(conf_dir)
1793
fd = os.open(self._filename, os.O_RDWR|os.O_CREAT, 0o600)
1797
fd = os.open(self._filename, os.O_RDWR | os.O_CREAT, 0o600)
1795
1799
f = os.fdopen(fd, 'wb')
1796
1800
self._get_config().write(f)
1841
1845
credentials = None
1842
1846
for auth_def_name, auth_def in self._get_config().iteritems():
1843
1847
if not isinstance(auth_def, configobj.Section):
1844
raise ValueError("%s defined outside a section" % auth_def_name)
1848
raise ValueError("%s defined outside a section" %
1846
1851
a_scheme, a_host, a_user, a_path = map(
1847
1852
auth_def.get, ['scheme', 'host', 'user', 'path'])
1864
1869
if a_scheme is not None and scheme != a_scheme:
1866
1871
if a_host is not None:
1867
if not (host == a_host
1868
or (a_host.startswith('.') and host.endswith(a_host))):
1872
if not (host == a_host or
1873
(a_host.startswith('.') and host.endswith(a_host))):
1870
1875
if a_port is not None and port != a_port:
1872
if (a_path is not None and path is not None
1873
and not path.startswith(a_path)):
1877
if (a_path is not None and path is not None and
1878
not path.startswith(a_path)):
1875
if (a_user is not None and user is not None
1876
and a_user != user):
1880
if (a_user is not None and user is not None and
1877
1882
# Never contradict the caller about the user to be used
1879
1884
if a_user is None:
1940
1945
if realm is not None:
1941
1946
values['realm'] = realm
1942
1947
config = self._get_config()
1944
1948
for section, existing_values in config.iteritems():
1945
1949
for key in ('scheme', 'host', 'port', 'path', 'realm'):
1946
1950
if existing_values.get(key) != values.get(key):
1965
1969
:param path: the absolute path on the server (optional)
1967
:param ask: Ask the user if there is no explicitly configured username
1971
:param ask: Ask the user if there is no explicitly configured username
1970
1974
:param default: The username returned if none is defined (optional).
2025
2029
if password is None:
2026
2030
if prompt is None:
2027
2031
# Create a default prompt suitable for most cases
2028
prompt = u'%s' % scheme.upper() + u' %(user)s@%(host)s password'
2033
scheme.upper() + u' %(user)s@%(host)s password')
2029
2034
# Special handling for optional fields in the prompt
2030
2035
if port is not None:
2031
2036
prompt_host = '%s:%d' % (host, port)
2170
2174
# should probably propogate as something more useful.
2171
2175
return base64.standard_b64decode(credentials['password'])
2173
2178
credential_store_registry.register('base64', Base64CredentialStore,
2174
2179
help=Base64CredentialStore.__doc__)
2280
2285
except errors.NoSuchFile:
2281
2286
return BytesIO()
2282
except errors.PermissionDenied as e:
2283
trace.warning("Permission denied while trying to open "
2284
"configuration file %s.", urlutils.unescape_for_display(
2285
urlutils.join(self._transport.base, self._filename), "utf-8"))
2287
except errors.PermissionDenied:
2289
"Permission denied while trying to open "
2290
"configuration file %s.",
2291
urlutils.unescape_for_display(
2292
urlutils.join(self._transport.base, self._filename),
2286
2294
return BytesIO()
2288
2296
def _external_url(self):
2476
2484
_unit_suffixes = dict(K=10**3, M=10**6, G=10**9)
2478
2487
def int_SI_from_store(unicode_str):
2479
2488
"""Convert a human readable size in SI units, e.g 10MB into an integer.
2482
2491
by a trailing b (i.e. Kb, MB). This is intended to be practical and not
2485
:return Integer, expanded to its base-10 value if a proper SI unit is
2494
:return Integer, expanded to its base-10 value if a proper SI unit is
2486
2495
found, None otherwise.
2488
2497
regexp = "^(\\d+)(([" + ''.join(_unit_suffixes) + "])b?)?$"
2593
2603
for '{bar{baz}}' we will get '{baz}'
2596
2607
def iter_option_refs(string):
2597
2608
# Split isolate refs so every other chunk is a ref
2599
for chunk in _option_ref_re.split(string):
2610
for chunk in _option_ref_re.split(string):
2600
2611
yield is_ref, chunk
2601
2612
is_ref = not is_ref
2634
2645
:param module_name: the python path to the module. Such as 'os.path'.
2636
:param member_name: the member of the module to return. If empty or
2647
:param member_name: the member of the module to return. If empty or
2637
2648
None, get() will return the module itself.
2639
2650
self._check_option_name(key)
2666
2677
option_registry.register(
2667
2678
ListOption('acceptable_keys',
2670
2681
List of GPG key patterns which are acceptable for verification.
2672
2683
option_registry.register(
2702
2713
See also: bound.
2704
2715
option_registry.register(
2705
Option('branch.fetch_tags', default=False, from_unicode=bool_from_store,
2716
Option('branch.fetch_tags', default=False, from_unicode=bool_from_store,
2707
2718
Whether revisions associated with tags should be fetched.
2710
2721
'transform.orphan_policy', 'breezy.transform', 'opt_transform_orphan')
2711
2722
option_registry.register(
2712
2723
Option('bzr.workingtree.worth_saving_limit', default=10,
2713
from_unicode=int_from_store, invalid='warning',
2724
from_unicode=int_from_store, invalid='warning',
2715
2726
How many changes before saving the dirstate.
2771
2782
option_registry.register(
2772
2783
ListOption('debug_flags', default=[],
2773
help='Debug flags to activate.'))
2784
help='Debug flags to activate.'))
2774
2785
option_registry.register(
2775
2786
Option('default_format', default='2a',
2776
2787
help='Format used when creating branches.'))
2806
2817
option_registry.register(
2807
2818
Option('log_format', default='long',
2809
2820
Log format to use when displaying revisions.
2811
2822
Standard log formats are ``long``, ``short`` and ``line``. Additional formats
2812
2823
may be provided by plugins.
2814
2825
option_registry.register_lazy('mail_client', 'breezy.mail_client',
2816
2827
option_registry.register(
2817
2828
Option('output_encoding',
2818
help= 'Unicode encoding for output'
2829
help='Unicode encoding for output'
2819
2830
' (terminal encoding if not specified).'))
2820
2831
option_registry.register(
2821
2832
Option('parent_location',
2874
2885
lost if the machine crashes. See also dirstate.fdatasync.
2876
2887
option_registry.register_lazy('smtp_server',
2877
'breezy.smtp_connection', 'smtp_server')
2888
'breezy.smtp_connection', 'smtp_server')
2878
2889
option_registry.register_lazy('smtp_password',
2879
'breezy.smtp_connection', 'smtp_password')
2890
'breezy.smtp_connection', 'smtp_password')
2880
2891
option_registry.register_lazy('smtp_username',
2881
'breezy.smtp_connection', 'smtp_username')
2892
'breezy.smtp_connection', 'smtp_username')
2882
2893
option_registry.register(
2883
2894
Option('selftest.timeout',
2885
from_unicode=int_from_store,
2886
help='Abort selftest if one test takes longer than this many seconds',
2896
from_unicode=int_from_store,
2897
help='Abort selftest if one test takes longer than this many seconds',
2889
2900
option_registry.register(
2890
2901
Option('send_strict', default=None,
2919
2930
help='''Where submissions from this branch are mailed to.'''))
2920
2931
option_registry.register(
2921
2932
ListOption('suppress_warnings',
2923
help="List of warning classes to suppress."))
2934
help="List of warning classes to suppress."))
2924
2935
option_registry.register(
2925
2936
Option('validate_signatures_in_log', default=False,
2926
2937
from_unicode=bool_from_store, invalid='warning',
2927
2938
help='''Whether to validate signatures in brz log.'''))
2928
2939
option_registry.register_lazy('ssl.ca_certs',
2929
'breezy.transport.http._urllib2_wrappers', 'opt_ssl_ca_certs')
2940
'breezy.transport.http._urllib2_wrappers', 'opt_ssl_ca_certs')
2931
2942
option_registry.register_lazy('ssl.cert_reqs',
2932
'breezy.transport.http._urllib2_wrappers', 'opt_ssl_cert_reqs')
2943
'breezy.transport.http._urllib2_wrappers', 'opt_ssl_cert_reqs')
2935
2946
class Section(object):
3018
3029
# Someone changed the value since we get it from the persistent
3020
3031
trace.warning(gettext(
3021
"Option {0} in section {1} of {2} was changed"
3022
" from {3} to {4}. The {5} value will be saved.".format(
3023
k, self.id, store.external_url(), expected,
3032
"Option {0} in section {1} of {2} was changed"
3033
" from {3} to {4}. The {5} value will be saved.".format(
3034
k, self.id, store.external_url(), expected,
3025
3036
# No need to keep track of these changes
3026
3037
self.reset_changes()
3173
3184
return 'cmdline'
3175
3186
def get_sections(self):
3176
yield self, self.readonly_section_class(None, self.options)
3187
yield self, self.readonly_section_class(None, self.options)
3179
3190
class IniFileStore(Store):
3466
3477
def __init__(self, bzrdir):
3467
3478
super(ControlStore, self).__init__(bzrdir.transport,
3469
3480
lock_dir_name='branch_lock')
3470
3481
self.id = 'control'
3582
3593
# the location is already a local path or URL, convert the
3583
3594
# section id to the same format
3584
3595
section_path = urlutils.local_path_from_url(section_path)
3585
if (self.location.startswith(section_path)
3586
or fnmatch.fnmatch(self.location, section_path)):
3596
if (self.location.startswith(section_path) or
3597
fnmatch.fnmatch(self.location, section_path)):
3587
3598
section_parts = section_path.rstrip('/').split('/')
3588
3599
extra_path = '/'.join(location_parts[len(section_parts):])
3589
3600
yield store, LocationSection(section, extra_path)
3714
3726
# FIXME: No caching of options nor sections yet -- vila 20110503
3716
found_store = None # Where the option value has been found
3728
found_store = None # Where the option value has been found
3717
3729
# If the option is registered, it may provide additional info about
3718
3730
# value handling
4135
4148
' configuration file.',
4136
4149
type=text_type),
4137
4150
commands.Option('all',
4138
help='Display all the defined values for the matching options.',
4151
help='Display all the defined values for the matching options.',
4140
4153
commands.Option('remove', help='Remove the option from'
4141
4154
' the configuration file.'),