~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/gpg.py

  • Committer: Jelmer Vernooij
  • Date: 2012-03-11 16:51:49 UTC
  • mto: This revision was merged to the branch mainline in revision 6494.
  • Revision ID: jelmer@samba.org-20120311165149-s2bs5pe2t160h85r
Add Repository.verify_revision_signatures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
    total = len(revids)
78
78
    pb = ui.ui_factory.nested_progress_bar()
79
79
    try:
80
 
        for i, rev_id in enumerate(revids):
 
80
        for i, (rev_id, verification_result, uid) in enumerate(
 
81
                repository.verify_revision_signatures(
 
82
                    revids, strategy)):
81
83
            pb.update("verifying signatures", i, total)
82
 
            verification_result, uid =\
83
 
                repository.verify_revision_signature(rev_id, strategy)
84
84
            result.append([rev_id, verification_result, uid])
85
85
            count[verification_result] += 1
86
86
            if verification_result != SIGNATURE_VALID:
146
146
    def do_verifications(self, revisions, repository):
147
147
        return bulk_verify_signatures(repository, revisions, self)
148
148
 
 
149
    @deprecated_method(deprecated_in((2, 6, 0)))
149
150
    def valid_commits_message(self, count):
150
 
        return gettext(u"{0} commits with valid signatures").format(
151
 
                                        count[SIGNATURE_VALID])
 
151
        return valid_commits_message(count)
152
152
 
 
153
    @deprecated_method(deprecated_in((2, 6, 0)))
153
154
    def unknown_key_message(self, count):
154
 
        return ngettext(u"{0} commit with unknown key",
155
 
                             u"{0} commits with unknown keys",
156
 
                             count[SIGNATURE_KEY_MISSING]).format(
157
 
                                        count[SIGNATURE_KEY_MISSING])
 
155
        return unknown_key_message(count)
158
156
 
 
157
    @deprecated_method(deprecated_in((2, 6, 0)))
159
158
    def commit_not_valid_message(self, count):
160
 
        return ngettext(u"{0} commit not valid",
161
 
                             u"{0} commits not valid",
162
 
                             count[SIGNATURE_NOT_VALID]).format(
163
 
                                            count[SIGNATURE_NOT_VALID])
 
159
        return commit_not_valid_message(count)
164
160
 
 
161
    @deprecated_method(deprecated_in((2, 6, 0)))
165
162
    def commit_not_signed_message(self, count):
166
 
        return ngettext(u"{0} commit not signed",
167
 
                             u"{0} commits not signed",
168
 
                             count[SIGNATURE_NOT_SIGNED]).format(
169
 
                                        count[SIGNATURE_NOT_SIGNED])
 
163
        return commit_not_signed_message(count)
170
164
 
 
165
    @deprecated_method(deprecated_in((2, 6, 0)))
171
166
    def expired_commit_message(self, count):
172
 
        return ngettext(u"{0} commit with key now expired",
173
 
                        u"{0} commits with key now expired",
174
 
                        count[SIGNATURE_EXPIRED]).format(
175
 
                                        count[SIGNATURE_EXPIRED])
 
167
        return expired_commit_message(count)
176
168
 
177
169
 
178
170
def _set_gpg_tty():
391
383
        return bulk_verify_signatures(repository, revisions, self,
392
384
            process_events_callback)
393
385
 
 
386
    @deprecated_method(deprecated_in((2, 6, 0)))
394
387
    def verbose_valid_message(self, result):
395
388
        """takes a verify result and returns list of signed commits strings"""
396
 
        signers = {}
397
 
        for rev_id, validity, uid in result:
398
 
            if validity == SIGNATURE_VALID:
399
 
                signers.setdefault(uid, 0)
400
 
                signers[uid] += 1
401
 
        result = []
402
 
        for uid, number in signers.items():
403
 
             result.append( ngettext(u"{0} signed {1} commit",
404
 
                             u"{0} signed {1} commits",
405
 
                             number).format(uid, number) )
406
 
        return result
407
 
 
408
 
 
 
389
        return verbose_valid_message(result)
 
390
 
 
391
    @deprecated_method(deprecated_in((2, 6, 0)))
409
392
    def verbose_not_valid_message(self, result, repo):
410
393
        """takes a verify result and returns list of not valid commit info"""
411
 
        signers = {}
412
 
        for rev_id, validity, empty in result:
413
 
            if validity == SIGNATURE_NOT_VALID:
414
 
                revision = repo.get_revision(rev_id)
415
 
                authors = ', '.join(revision.get_apparent_authors())
416
 
                signers.setdefault(authors, 0)
417
 
                signers[authors] += 1
418
 
        result = []
419
 
        for authors, number in signers.items():
420
 
            result.append( ngettext(u"{0} commit by author {1}",
421
 
                                 u"{0} commits by author {1}",
422
 
                                 number).format(number, authors) )
423
 
        return result
 
394
        return verbose_not_valid_message(result, repo)
424
395
 
 
396
    @deprecated_method(deprecated_in((2, 6, 0)))
425
397
    def verbose_not_signed_message(self, result, repo):
426
398
        """takes a verify result and returns list of not signed commit info"""
427
 
        signers = {}
428
 
        for rev_id, validity, empty in result:
429
 
            if validity == SIGNATURE_NOT_SIGNED:
430
 
                revision = repo.get_revision(rev_id)
431
 
                authors = ', '.join(revision.get_apparent_authors())
432
 
                signers.setdefault(authors, 0)
433
 
                signers[authors] += 1
434
 
        result = []
435
 
        for authors, number in signers.items():
436
 
            result.append( ngettext(u"{0} commit by author {1}",
437
 
                                 u"{0} commits by author {1}",
438
 
                                 number).format(number, authors) )
439
 
        return result
 
399
        return verbose_not_valid_message(result, repo)
440
400
 
 
401
    @deprecated_method(deprecated_in((2, 6, 0)))
441
402
    def verbose_missing_key_message(self, result):
442
403
        """takes a verify result and returns list of missing key info"""
443
 
        signers = {}
444
 
        for rev_id, validity, fingerprint in result:
445
 
            if validity == SIGNATURE_KEY_MISSING:
446
 
                signers.setdefault(fingerprint, 0)
447
 
                signers[fingerprint] += 1
448
 
        result = []
449
 
        for fingerprint, number in signers.items():
450
 
            result.append( ngettext(u"Unknown key {0} signed {1} commit",
451
 
                                 u"Unknown key {0} signed {1} commits",
452
 
                                 number).format(fingerprint, number) )
453
 
        return result
 
404
        return verbose_missing_key_message(result)
454
405
 
 
406
    @deprecated_method(deprecated_in((2, 6, 0)))
455
407
    def verbose_expired_key_message(self, result, repo):
456
408
        """takes a verify result and returns list of expired key info"""
457
 
        signers = {}
458
 
        fingerprint_to_authors = {}
459
 
        for rev_id, validity, fingerprint in result:
460
 
            if validity == SIGNATURE_EXPIRED:
461
 
                revision = repo.get_revision(rev_id)
462
 
                authors = ', '.join(revision.get_apparent_authors())
463
 
                signers.setdefault(fingerprint, 0)
464
 
                signers[fingerprint] += 1
465
 
                fingerprint_to_authors[fingerprint] = authors
466
 
        result = []
467
 
        for fingerprint, number in signers.items():
468
 
            result.append(
469
 
                ngettext(u"{0} commit by author {1} with key {2} now expired",
470
 
                         u"{0} commits by author {1} with key {2} now expired",
471
 
                         number).format(
472
 
                    number, fingerprint_to_authors[fingerprint], fingerprint) )
473
 
        return result
 
409
        return verbose_expired_key_message(result, repo)
474
410
 
 
411
    @deprecated_method(deprecated_in((2, 6, 0)))
475
412
    def valid_commits_message(self, count):
476
413
        """returns message for number of commits"""
477
 
        return gettext(u"{0} commits with valid signatures").format(
478
 
                                        count[SIGNATURE_VALID])
 
414
        return valid_commits_message(count)
479
415
 
 
416
    @deprecated_method(deprecated_in((2, 6, 0)))
480
417
    def unknown_key_message(self, count):
481
418
        """returns message for number of commits"""
482
 
        return ngettext(u"{0} commit with unknown key",
483
 
                        u"{0} commits with unknown keys",
484
 
                        count[SIGNATURE_KEY_MISSING]).format(
485
 
                                        count[SIGNATURE_KEY_MISSING])
 
419
        return unknown_key_message(count)
486
420
 
 
421
    @deprecated_method(deprecated_in((2, 6, 0)))
487
422
    def commit_not_valid_message(self, count):
488
423
        """returns message for number of commits"""
489
 
        return ngettext(u"{0} commit not valid",
490
 
                        u"{0} commits not valid",
491
 
                        count[SIGNATURE_NOT_VALID]).format(
492
 
                                            count[SIGNATURE_NOT_VALID])
 
424
        return commit_not_valid_message(count)
493
425
 
 
426
    @deprecated_method(deprecated_in((2, 6, 0)))
494
427
    def commit_not_signed_message(self, count):
495
428
        """returns message for number of commits"""
496
 
        return ngettext(u"{0} commit not signed",
497
 
                        u"{0} commits not signed",
498
 
                        count[SIGNATURE_NOT_SIGNED]).format(
499
 
                                        count[SIGNATURE_NOT_SIGNED])
 
429
        return commit_not_signed_message(count)
500
430
 
 
431
    @deprecated_method(deprecated_in((2, 6, 0)))
501
432
    def expired_commit_message(self, count):
502
433
        """returns message for number of commits"""
503
 
        return ngettext(u"{0} commit with key now expired",
504
 
                        u"{0} commits with key now expired",
505
 
                        count[SIGNATURE_EXPIRED]).format(
506
 
                                    count[SIGNATURE_EXPIRED])
 
434
        return expired_commit_message(count)
 
435
 
 
436
 
 
437
def valid_commits_message(count):
 
438
    """returns message for number of commits"""
 
439
    return gettext(u"{0} commits with valid signatures").format(
 
440
                                    count[SIGNATURE_VALID])
 
441
 
 
442
 
 
443
def unknown_key_message(count):
 
444
    """returns message for number of commits"""
 
445
    return ngettext(u"{0} commit with unknown key",
 
446
                    u"{0} commits with unknown keys",
 
447
                    count[SIGNATURE_KEY_MISSING]).format(
 
448
                                    count[SIGNATURE_KEY_MISSING])
 
449
 
 
450
 
 
451
def commit_not_valid_message(count):
 
452
    """returns message for number of commits"""
 
453
    return ngettext(u"{0} commit not valid",
 
454
                    u"{0} commits not valid",
 
455
                    count[SIGNATURE_NOT_VALID]).format(
 
456
                                        count[SIGNATURE_NOT_VALID])
 
457
 
 
458
 
 
459
def commit_not_signed_message(count):
 
460
    """returns message for number of commits"""
 
461
    return ngettext(u"{0} commit not signed",
 
462
                    u"{0} commits not signed",
 
463
                    count[SIGNATURE_NOT_SIGNED]).format(
 
464
                                    count[SIGNATURE_NOT_SIGNED])
 
465
 
 
466
 
 
467
def expired_commit_message(count):
 
468
    """returns message for number of commits"""
 
469
    return ngettext(u"{0} commit with key now expired",
 
470
                    u"{0} commits with key now expired",
 
471
                    count[SIGNATURE_EXPIRED]).format(
 
472
                                count[SIGNATURE_EXPIRED])
 
473
 
 
474
 
 
475
def verbose_expired_key_message(result, repo):
 
476
    """takes a verify result and returns list of expired key info"""
 
477
    signers = {}
 
478
    fingerprint_to_authors = {}
 
479
    for rev_id, validity, fingerprint in result:
 
480
        if validity == SIGNATURE_EXPIRED:
 
481
            revision = repo.get_revision(rev_id)
 
482
            authors = ', '.join(revision.get_apparent_authors())
 
483
            signers.setdefault(fingerprint, 0)
 
484
            signers[fingerprint] += 1
 
485
            fingerprint_to_authors[fingerprint] = authors
 
486
    result = []
 
487
    for fingerprint, number in signers.items():
 
488
        result.append(
 
489
            ngettext(u"{0} commit by author {1} with key {2} now expired",
 
490
                     u"{0} commits by author {1} with key {2} now expired",
 
491
                     number).format(
 
492
                number, fingerprint_to_authors[fingerprint], fingerprint))
 
493
    return result
 
494
 
 
495
 
 
496
def verbose_valid_message(result):
 
497
    """takes a verify result and returns list of signed commits strings"""
 
498
    signers = {}
 
499
    for rev_id, validity, uid in result:
 
500
        if validity == SIGNATURE_VALID:
 
501
            signers.setdefault(uid, 0)
 
502
            signers[uid] += 1
 
503
    result = []
 
504
    for uid, number in signers.items():
 
505
         result.append(ngettext(u"{0} signed {1} commit",
 
506
                                u"{0} signed {1} commits",
 
507
                                number).format(uid, number))
 
508
    return result
 
509
 
 
510
 
 
511
def verbose_not_valid_message(result, repo):
 
512
    """takes a verify result and returns list of not valid commit info"""
 
513
    signers = {}
 
514
    for rev_id, validity, empty in result:
 
515
        if validity == SIGNATURE_NOT_VALID:
 
516
            revision = repo.get_revision(rev_id)
 
517
            authors = ', '.join(revision.get_apparent_authors())
 
518
            signers.setdefault(authors, 0)
 
519
            signers[authors] += 1
 
520
    result = []
 
521
    for authors, number in signers.items():
 
522
        result.append(ngettext(u"{0} commit by author {1}",
 
523
                               u"{0} commits by author {1}",
 
524
                               number).format(number, authors))
 
525
    return result
 
526
 
 
527
 
 
528
def verbose_not_signed_message(result, repo):
 
529
    """takes a verify result and returns list of not signed commit info"""
 
530
    signers = {}
 
531
    for rev_id, validity, empty in result:
 
532
        if validity == SIGNATURE_NOT_SIGNED:
 
533
            revision = repo.get_revision(rev_id)
 
534
            authors = ', '.join(revision.get_apparent_authors())
 
535
            signers.setdefault(authors, 0)
 
536
            signers[authors] += 1
 
537
    result = []
 
538
    for authors, number in signers.items():
 
539
        result.append(ngettext(u"{0} commit by author {1}",
 
540
                               u"{0} commits by author {1}",
 
541
                               number).format(number, authors))
 
542
    return result
 
543
 
 
544
 
 
545
def verbose_missing_key_message(result):
 
546
    """takes a verify result and returns list of missing key info"""
 
547
    signers = {}
 
548
    for rev_id, validity, fingerprint in result:
 
549
        if validity == SIGNATURE_KEY_MISSING:
 
550
            signers.setdefault(fingerprint, 0)
 
551
            signers[fingerprint] += 1
 
552
    result = []
 
553
    for fingerprint, number in signers.items():
 
554
        result.append(ngettext(u"Unknown key {0} signed {1} commit",
 
555
                               u"Unknown key {0} signed {1} commits",
 
556
                               number).format(fingerprint, number))
 
557
    return result