~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Aaron Bentley
  • Date: 2006-06-15 03:10:51 UTC
  • mto: This revision was merged to the branch mainline in revision 1771.
  • Revision ID: aaron.bentley@utoronto.ca-20060615031051-94c53f386edc1f8c
Ignore lines that start with '#' in patch parser

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.
52
53
log_format - This options set the default log format.  Options are long, 
53
54
             short, line, or a plugin can register new formats
54
55
 
63
64
 
64
65
 
65
66
import errno
 
67
import os
 
68
import sys
66
69
from fnmatch import fnmatch
67
 
import os
68
70
import re
69
 
import sys
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, warning
 
75
from bzrlib.trace import mutter
76
76
import bzrlib.util.configobj.configobj as configobj
77
 
 
 
77
from StringIO import StringIO
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
 
 
89
84
class ConfigObj(configobj.ConfigObj):
90
85
 
91
86
    def get_bool(self, section, key):
111
106
    def _get_signature_checking(self):
112
107
        """Template method to override signature checking policy."""
113
108
 
114
 
    def _get_signing_policy(self):
115
 
        """Template method to override signature creation policy."""
116
 
 
117
109
    def _get_user_option(self, option_name):
118
110
        """Template method to provide a user option."""
119
111
        return None
200
192
            return policy
201
193
        return CHECK_IF_POSSIBLE
202
194
 
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
 
 
210
195
    def signature_needed(self):
211
196
        """Is a signature needed when committing ?."""
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:
 
197
        policy = self._get_signature_checking()
 
198
        if policy == CHECK_ALWAYS:
221
199
            return True
222
200
        return False
223
201
 
254
232
        if policy:
255
233
            return self._string_to_signature_policy(policy)
256
234
 
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
 
 
263
235
    def _get_user_id(self):
264
236
        """Get the user id from the 'email' key in the current section."""
265
237
        return self._get_user_option('email')
300
272
        raise errors.BzrError("Invalid signatures policy '%s'"
301
273
                              % signature_string)
302
274
 
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
 
 
314
275
    def _get_alias(self, value):
315
276
        try:
316
277
            return self._get_parser().get_value("ALIASES", 
418
379
            return check
419
380
        return self._get_global_config()._get_signature_checking()
420
381
 
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
 
 
428
382
    def _post_commit(self):
429
383
        """See Config.post_commit."""
430
384
        hook = self._get_user_option('post_commit')
478
432
        """See Config._get_signature_checking."""
479
433
        return self._get_location_config()._get_signature_checking()
480
434
 
481
 
    def _get_signing_policy(self):
482
 
        """See Config._get_signing_policy."""
483
 
        return self._get_location_config()._get_signing_policy()
484
 
 
485
435
    def _get_user_option(self, option_name):
486
436
        """See Config._get_user_option."""
487
437
        return self._get_location_config()._get_user_option(option_name)