~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/gpg.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-07-01 11:45:59 UTC
  • mfrom: (5971.1.87 bzr-gpgme)
  • Revision ID: pqm@pqm.ubuntu.com-20110701114559-gshz8uv6hr0x0pax
(jr) Various small improvements to GPG support
 - improve LoopbackGPGStrategy doc string - use unicode strings for UI
 - add doc string to verify_signatures_available()
 - add process_events_callback argument to do_verifications() to keep GUIs
 responsive (Jonathan Riddell)

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