~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/gpg.py

  • Committer: Gordon Tyler
  • Date: 2011-06-30 21:00:38 UTC
  • mto: This revision was merged to the branch mainline in revision 6007.
  • Revision ID: gordon@doxxx.net-20110630210038-bzscps46jgcqtkr0
Use known executables for win32 and other platforms in test_exe_on_path.

Show diffs side-by-side

added added

removed removed

Lines of Context:
76
76
 
77
77
 
78
78
class LoopbackGPGStrategy(object):
79
 
    """A GPG Strategy that acts like 'cat' - data is just passed through.
80
 
    Used in tests.
81
 
    """
 
79
    """A GPG Strategy that acts like 'cat' - data is just passed through."""
82
80
 
83
81
    @staticmethod
84
82
    def verify_signatures_available():
121
119
        return (count, result, all_verifiable)
122
120
 
123
121
    def valid_commits_message(self, count):
124
 
        return i18n.gettext(u"{0} commits with valid signatures").format(
 
122
        return i18n.gettext("{0} commits with valid signatures").format(
125
123
                                        count[SIGNATURE_VALID])            
126
124
 
127
125
    def unknown_key_message(self, count):
128
 
        return i18n.ngettext(u"{0} commit with unknown key",
129
 
                             u"{0} commits with unknown keys",
 
126
        return i18n.ngettext("{0} commit with unknown key",
 
127
                             "{0} commits with unknown keys",
130
128
                             count[SIGNATURE_KEY_MISSING]).format(
131
129
                                        count[SIGNATURE_KEY_MISSING])
132
130
 
133
131
    def commit_not_valid_message(self, count):
134
 
        return i18n.ngettext(u"{0} commit not valid",
135
 
                             u"{0} commits not valid",
 
132
        return i18n.ngettext("{0} commit not valid",
 
133
                             "{0} commits not valid",
136
134
                             count[SIGNATURE_NOT_VALID]).format(
137
135
                                            count[SIGNATURE_NOT_VALID])
138
136
 
139
137
    def commit_not_signed_message(self, count):
140
 
        return i18n.ngettext(u"{0} commit not signed",
141
 
                             u"{0} commits not signed",
 
138
        return i18n.ngettext("{0} commit not signed",
 
139
                             "{0} commits not signed",
142
140
                             count[SIGNATURE_NOT_SIGNED]).format(
143
141
                                        count[SIGNATURE_NOT_SIGNED])
144
142
 
163
161
 
164
162
    @staticmethod
165
163
    def verify_signatures_available():
166
 
        """
167
 
        check if this strategy can verify signatures
168
 
 
169
 
        :return: boolean if this strategy can verify signatures
170
 
        """
171
164
        try:
172
165
            import gpgme
173
166
            return True
175
168
            return False
176
169
 
177
170
    def _command_line(self):
178
 
        
179
 
        return [self._config.gpg_signing_command(), '--clearsign', '-u',
180
 
                                                self._config.gpg_signing_key()]
 
171
        return [self._config.gpg_signing_command(), '--clearsign']
181
172
 
182
173
    def __init__(self, config):
183
174
        self._config = config
283
274
            if isinstance(acceptable_keys_config, unicode):
284
275
                acceptable_keys_config = str(acceptable_keys_config)
285
276
        except UnicodeEncodeError:
286
 
            #gpg Context.keylist(pattern) does not like unicode
287
277
            raise errors.BzrCommandError('Only ASCII permitted in option names')
288
278
 
289
279
        if acceptable_keys_config is not None:
306
296
                            "No GnuPG key results for pattern: {}"
307
297
                                ).format(pattern))
308
298
 
309
 
    def do_verifications(self, revisions, repository,
310
 
                            process_events_callback=None):
 
299
    def do_verifications(self, revisions, repository):
311
300
        """do verifications on a set of revisions
312
301
        
313
302
        :param revisions: list of revision ids to verify
314
303
        :param repository: repository object
315
 
        :param process_events_callback: method to call for GUI frontends that
316
 
                                                want to keep their UI refreshed
317
304
        
318
305
        :return: count dictionary of results of each type,
319
306
                 result list for each revision,
332
319
            count[verification_result] += 1
333
320
            if verification_result != SIGNATURE_VALID:
334
321
                all_verifiable = False
335
 
            if process_events_callback is not None:
336
 
                process_events_callback()
337
322
        return (count, result, all_verifiable)
338
323
 
339
324
    def verbose_valid_message(self, result):
345
330
                signers[uid] += 1
346
331
        result = []
347
332
        for uid, number in signers.items():
348
 
             result.append( i18n.ngettext(u"{0} signed {1} commit", 
349
 
                             u"{0} signed {1} commits",
 
333
             result.append( i18n.ngettext("{0} signed {1} commit", 
 
334
                             "{0} signed {1} commits",
350
335
                             number).format(uid, number) )
351
336
        return result
352
337
 
362
347
                signers[authors] += 1
363
348
        result = []
364
349
        for authors, number in signers.items():
365
 
            result.append( i18n.ngettext(u"{0} commit by author {1}", 
366
 
                                 u"{0} commits by author {1}",
 
350
            result.append( i18n.ngettext("{0} commit by author {1}", 
 
351
                                 "{0} commits by author {1}",
367
352
                                 number).format(number, authors) )
368
353
        return result
369
354
 
378
363
                signers[authors] += 1
379
364
        result = []
380
365
        for authors, number in signers.items():
381
 
            result.append( i18n.ngettext(u"{0} commit by author {1}", 
382
 
                                 u"{0} commits by author {1}",
 
366
            result.append( i18n.ngettext("{0} commit by author {1}", 
 
367
                                 "{0} commits by author {1}",
383
368
                                 number).format(number, authors) )
384
369
        return result
385
370
 
392
377
                signers[fingerprint] += 1
393
378
        result = []
394
379
        for fingerprint, number in signers.items():
395
 
            result.append( i18n.ngettext(u"Unknown key {0} signed {1} commit", 
396
 
                                 u"Unknown key {0} signed {1} commits",
 
380
            result.append( i18n.ngettext("Unknown key {0} signed {1} commit", 
 
381
                                 "Unknown key {0} signed {1} commits",
397
382
                                 number).format(fingerprint, number) )
398
383
        return result
399
384
 
400
385
    def valid_commits_message(self, count):
401
386
        """returns message for number of commits"""
402
 
        return i18n.gettext(u"{0} commits with valid signatures").format(
 
387
        return i18n.gettext("{0} commits with valid signatures").format(
403
388
                                        count[SIGNATURE_VALID])
404
389
 
405
390
    def unknown_key_message(self, count):
406
391
        """returns message for number of commits"""
407
 
        return i18n.ngettext(u"{0} commit with unknown key",
408
 
                             u"{0} commits with unknown keys",
 
392
        return i18n.ngettext("{0} commit with unknown key",
 
393
                             "{0} commits with unknown keys",
409
394
                             count[SIGNATURE_KEY_MISSING]).format(
410
395
                                        count[SIGNATURE_KEY_MISSING])
411
396
 
412
397
    def commit_not_valid_message(self, count):
413
398
        """returns message for number of commits"""
414
 
        return i18n.ngettext(u"{0} commit not valid",
415
 
                             u"{0} commits not valid",
 
399
        return i18n.ngettext("{0} commit not valid",
 
400
                             "{0} commits not valid",
416
401
                             count[SIGNATURE_NOT_VALID]).format(
417
402
                                            count[SIGNATURE_NOT_VALID])
418
403
 
419
404
    def commit_not_signed_message(self, count):
420
405
        """returns message for number of commits"""
421
 
        return i18n.ngettext(u"{0} commit not signed",
422
 
                             u"{0} commits not signed",
 
406
        return i18n.ngettext("{0} commit not signed",
 
407
                             "{0} commits not signed",
423
408
                             count[SIGNATURE_NOT_SIGNED]).format(
424
409
                                        count[SIGNATURE_NOT_SIGNED])