~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

Convert some gpg options to config stacks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
                   turns on create_signatures.
56
56
create_signatures - this option controls whether bzr will always create
57
57
                    gpg signatures or not on commits.  There is an unused
58
 
                    option which in future is expected to work if               
 
58
                    option which in future is expected to work if
59
59
                    branch settings require signatures.
60
60
log_format - this option sets the default log format.  Possible values are
61
61
             long, short, line, or a plugin can register new formats.
73
73
"""
74
74
 
75
75
import os
76
 
import string
77
76
import sys
78
77
 
79
78
 
152
151
STORE_GLOBAL = 4
153
152
 
154
153
 
 
154
def signature_policy_from_unicode(signature_string):
 
155
    """Convert a string to a signing policy."""
 
156
    if signature_string.lower() == 'check-available':
 
157
        return CHECK_IF_POSSIBLE
 
158
    if signature_string.lower() == 'ignore':
 
159
        return CHECK_NEVER
 
160
    if signature_string.lower() == 'require':
 
161
        return CHECK_ALWAYS
 
162
    raise ValueError("Invalid signatures policy '%s'"
 
163
                     % signature_string)
 
164
 
 
165
 
 
166
def signing_policy_from_unicode(signature_string):
 
167
    """Convert a string to a signing policy."""
 
168
    if signature_string.lower() == 'when-required':
 
169
        return SIGN_WHEN_REQUIRED
 
170
    if signature_string.lower() == 'never':
 
171
        return SIGN_NEVER
 
172
    if signature_string.lower() == 'always':
 
173
        return SIGN_ALWAYS
 
174
    raise ValueError("Invalid signing policy '%s'"
 
175
                     % signature_string)
 
176
 
 
177
 
155
178
class ConfigObj(configobj.ConfigObj):
156
179
 
157
180
    def __init__(self, infile=None, **kwargs):
493
516
        """See validate_signatures_in_log()."""
494
517
        return None
495
518
 
 
519
    @deprecated_method(deprecated_in((2, 5, 0)))
496
520
    def acceptable_keys(self):
497
521
        """Comma separated list of key patterns acceptable to 
498
522
        verify-signatures command"""
551
575
        """
552
576
        self.username()
553
577
 
 
578
    @deprecated_method(deprecated_in((2, 5, 0)))
554
579
    def signature_checking(self):
555
580
        """What is the current policy for signature checking?."""
556
581
        policy = self._get_signature_checking()
558
583
            return policy
559
584
        return CHECK_IF_POSSIBLE
560
585
 
 
586
    @deprecated_method(deprecated_in((2, 5, 0)))
561
587
    def signing_policy(self):
562
588
        """What is the current policy for signature checking?."""
563
589
        policy = self._get_signing_policy()
565
591
            return policy
566
592
        return SIGN_WHEN_REQUIRED
567
593
 
 
594
    @deprecated_method(deprecated_in((2, 5, 0)))
568
595
    def signature_needed(self):
569
596
        """Is a signature needed when committing ?."""
570
597
        policy = self._get_signing_policy()
579
606
            return True
580
607
        return False
581
608
 
 
609
    @deprecated_method(deprecated_in((2, 5, 0)))
582
610
    def gpg_signing_key(self):
583
611
        """GPG user-id to sign commits"""
584
612
        key = self.get_user_option('gpg_signing_key')
869
897
        """See Config._get_signature_checking."""
870
898
        policy = self._get_user_option('check_signatures')
871
899
        if policy:
872
 
            return self._string_to_signature_policy(policy)
 
900
            return signature_policy_from_unicode(policy)
873
901
 
874
902
    def _get_signing_policy(self):
875
903
        """See Config._get_signing_policy"""
876
904
        policy = self._get_user_option('create_signatures')
877
905
        if policy:
878
 
            return self._string_to_signing_policy(policy)
 
906
            return signing_policy_from_unicode(policy)
879
907
 
880
908
    def _get_user_id(self):
881
909
        """Get the user id from the 'email' key in the current section."""
926
954
        """See Config.post_commit."""
927
955
        return self._get_user_option('post_commit')
928
956
 
929
 
    def _string_to_signature_policy(self, signature_string):
930
 
        """Convert a string to a signing policy."""
931
 
        if signature_string.lower() == 'check-available':
932
 
            return CHECK_IF_POSSIBLE
933
 
        if signature_string.lower() == 'ignore':
934
 
            return CHECK_NEVER
935
 
        if signature_string.lower() == 'require':
936
 
            return CHECK_ALWAYS
937
 
        raise errors.BzrError("Invalid signatures policy '%s'"
938
 
                              % signature_string)
939
 
 
940
 
    def _string_to_signing_policy(self, signature_string):
941
 
        """Convert a string to a signing policy."""
942
 
        if signature_string.lower() == 'when-required':
943
 
            return SIGN_WHEN_REQUIRED
944
 
        if signature_string.lower() == 'never':
945
 
            return SIGN_NEVER
946
 
        if signature_string.lower() == 'always':
947
 
            return SIGN_ALWAYS
948
 
        raise errors.BzrError("Invalid signing policy '%s'"
949
 
                              % signature_string)
950
 
 
951
957
    def _get_alias(self, value):
952
958
        try:
953
959
            return self._get_parser().get_value("ALIASES",
2509
2515
# Registered options in lexicographical order
2510
2516
 
2511
2517
option_registry.register(
 
2518
    Option('acceptable_keys',
 
2519
           default=None, from_unicode=list_from_store,
 
2520
           help="""\
 
2521
List of GPG key patterns which are acceptable for verification.
 
2522
"""))
 
2523
option_registry.register(
2512
2524
    Option('bzr.workingtree.worth_saving_limit', default=10,
2513
2525
           from_unicode=int_from_store,  invalid='warning',
2514
2526
           help='''\
2521
2533
a file has been touched.
2522
2534
'''))
2523
2535
option_registry.register(
 
2536
    Option('check_signatures', default=CHECK_IF_POSSIBLE,
 
2537
           from_unicode=signature_policy_from_unicode,
 
2538
           help='''\
 
2539
GPG checking policy.
 
2540
 
 
2541
Possible values: require, ignore, check-available (default)
 
2542
 
 
2543
this option will control whether bzr will require good gpg
 
2544
signatures, ignore them, or check them if they are
 
2545
present.
 
2546
'''))
 
2547
option_registry.register(
 
2548
    Option('create_signatures', default=SIGN_WHEN_REQUIRED,
 
2549
           from_unicode=signing_policy_from_unicode,
 
2550
           help='''\
 
2551
GPG Signing policy.
 
2552
 
 
2553
Possible values: always, never, when-required (default)
 
2554
 
 
2555
This option controls whether bzr will always create
 
2556
gpg signatures or not on commits.
 
2557
'''))
 
2558
option_registry.register(
2524
2559
    Option('dirstate.fdatasync', default=True,
2525
2560
           from_unicode=bool_from_store,
2526
2561
           help='''\
2552
2587
option_registry.register(
2553
2588
    Option('gpg_signing_command',
2554
2589
           default='gpg',
2555
 
           help="Program to use use for creating signatures."""))
 
2590
           help="""\
 
2591
Program to use use for creating signatures.
 
2592
 
 
2593
This should support at least the -u and --clearsign options.
 
2594
"""))
 
2595
option_registry.register(
 
2596
    Option('gpg_signing_key',
 
2597
           default=None,
 
2598
           help="""\
 
2599
GPG key to use for signing.
 
2600
 
 
2601
This defaults to the first key associated with the users email.
 
2602
"""))
2556
2603
option_registry.register(
2557
2604
    Option('ignore_missing_extensions', default=False,
2558
2605
           from_unicode=bool_from_store,