~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-06-16 14:33:42 UTC
  • mfrom: (1770.2.1 config)
  • Revision ID: pqm@pqm.ubuntu.com-20060616143342-8f7f4a4f77c1e4c8
Use create_signature for signing policy, deprecate check_signatures for this

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
create_signatures - this option controls whether bzr will always create 
50
50
                    gpg signatures, never create them, or create them if the
51
51
                    branch is configured to require them.
52
 
                    NB: This option is planned, but not implemented yet.
53
52
log_format - This options set the default log format.  Options are long, 
54
53
             short, line, or a plugin can register new formats
55
54
 
64
63
 
65
64
 
66
65
import errno
 
66
from fnmatch import fnmatch
67
67
import os
 
68
import re
68
69
import sys
69
 
from fnmatch import fnmatch
70
 
import re
 
70
from StringIO import StringIO
71
71
 
72
72
import bzrlib
73
73
import bzrlib.errors as errors
74
74
from bzrlib.osutils import pathjoin
75
 
from bzrlib.trace import mutter
 
75
from bzrlib.trace import mutter, warning
76
76
import bzrlib.util.configobj.configobj as configobj
77
 
from StringIO import StringIO
 
77
 
78
78
 
79
79
CHECK_IF_POSSIBLE=0
80
80
CHECK_ALWAYS=1
81
81
CHECK_NEVER=2
82
82
 
83
83
 
 
84
SIGN_WHEN_REQUIRED=0
 
85
SIGN_ALWAYS=1
 
86
SIGN_NEVER=2
 
87
 
 
88
 
84
89
class ConfigObj(configobj.ConfigObj):
85
90
 
86
91
    def get_bool(self, section, key):
106
111
    def _get_signature_checking(self):
107
112
        """Template method to override signature checking policy."""
108
113
 
 
114
    def _get_signing_policy(self):
 
115
        """Template method to override signature creation policy."""
 
116
 
109
117
    def _get_user_option(self, option_name):
110
118
        """Template method to provide a user option."""
111
119
        return None
192
200
            return policy
193
201
        return CHECK_IF_POSSIBLE
194
202
 
 
203
    def signing_policy(self):
 
204
        """What is the current policy for signature checking?."""
 
205
        policy = self._get_signing_policy()
 
206
        if policy is not None:
 
207
            return policy
 
208
        return SIGN_WHEN_REQUIRED
 
209
 
195
210
    def signature_needed(self):
196
211
        """Is a signature needed when committing ?."""
197
 
        policy = self._get_signature_checking()
198
 
        if policy == CHECK_ALWAYS:
 
212
        policy = self._get_signing_policy()
 
213
        if policy is None:
 
214
            policy = self._get_signature_checking()
 
215
            if policy is not None:
 
216
                warning("Please use create_signatures, not check_signatures "
 
217
                        "to set signing policy.")
 
218
            if policy == CHECK_ALWAYS:
 
219
                return True
 
220
        elif policy == SIGN_ALWAYS:
199
221
            return True
200
222
        return False
201
223
 
232
254
        if policy:
233
255
            return self._string_to_signature_policy(policy)
234
256
 
 
257
    def _get_signing_policy(self):
 
258
        """See Config._get_signature_checking."""
 
259
        policy = self._get_user_option('create_signatures')
 
260
        if policy:
 
261
            return self._string_to_signing_policy(policy)
 
262
 
235
263
    def _get_user_id(self):
236
264
        """Get the user id from the 'email' key in the current section."""
237
265
        return self._get_user_option('email')
272
300
        raise errors.BzrError("Invalid signatures policy '%s'"
273
301
                              % signature_string)
274
302
 
 
303
    def _string_to_signing_policy(self, signature_string):
 
304
        """Convert a string to a signing policy."""
 
305
        if signature_string.lower() == 'when-required':
 
306
            return SIGN_WHEN_REQUIRED
 
307
        if signature_string.lower() == 'never':
 
308
            return SIGN_NEVER
 
309
        if signature_string.lower() == 'always':
 
310
            return SIGN_ALWAYS
 
311
        raise errors.BzrError("Invalid signing policy '%s'"
 
312
                              % signature_string)
 
313
 
275
314
    def _get_alias(self, value):
276
315
        try:
277
316
            return self._get_parser().get_value("ALIASES", 
379
418
            return check
380
419
        return self._get_global_config()._get_signature_checking()
381
420
 
 
421
    def _get_signing_policy(self):
 
422
        """See Config._get_signing_policy."""
 
423
        sign = super(LocationConfig, self)._get_signing_policy()
 
424
        if sign is not None:
 
425
            return sign
 
426
        return self._get_global_config()._get_signing_policy()
 
427
 
382
428
    def _post_commit(self):
383
429
        """See Config.post_commit."""
384
430
        hook = self._get_user_option('post_commit')
432
478
        """See Config._get_signature_checking."""
433
479
        return self._get_location_config()._get_signature_checking()
434
480
 
 
481
    def _get_signing_policy(self):
 
482
        """See Config._get_signing_policy."""
 
483
        return self._get_location_config()._get_signing_policy()
 
484
 
435
485
    def _get_user_option(self, option_name):
436
486
        """See Config._get_user_option."""
437
487
        return self._get_location_config()._get_user_option(option_name)