~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit_signature_commands.py

  • Committer: Jelmer Vernooij
  • Date: 2016-04-03 16:32:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6617.
  • Revision ID: jelmer@jelmer.uk-20160403163231-h72bo0uyek2gikw0
Don't put French text in doc/en/user-reference when LANGUAGE=fr_CH.UTF_8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Command which looks for unsigned commits by the current user, and signs them.
18
18
"""
19
19
 
20
 
from bzrlib.lazy_import import lazy_import
21
 
lazy_import(globals(), """
 
20
from __future__ import absolute_import
 
21
 
22
22
from bzrlib import (
23
 
    bzrdir as _mod_bzrdir,
 
23
    controldir,
24
24
    errors,
25
25
    gpg,
26
26
    revision as _mod_revision,
27
27
    )
28
 
""")
29
28
from bzrlib.commands import Command
30
29
from bzrlib.option import Option
31
30
from bzrlib.i18n import gettext, ngettext
32
31
 
 
32
 
33
33
class cmd_sign_my_commits(Command):
34
34
    __doc__ = """Sign all commits by a given committer.
35
35
 
51
51
 
52
52
    def run(self, location=None, committer=None, dry_run=False):
53
53
        if location is None:
54
 
            bzrdir = _mod_bzrdir.BzrDir.open_containing('.')[0]
 
54
            bzrdir = controldir.ControlDir.open_containing('.')[0]
55
55
        else:
56
56
            # Passed in locations should be exact
57
 
            bzrdir = _mod_bzrdir.BzrDir.open(location)
 
57
            bzrdir = controldir.ControlDir.open(location)
58
58
        branch = bzrdir.open_branch()
59
59
        repo = branch.repository
60
 
        branch_config = branch.get_config()
 
60
        branch_config = branch.get_config_stack()
61
61
 
62
62
        if committer is None:
63
 
            committer = branch_config.username()
 
63
            committer = branch_config.get('email')
64
64
        gpg_strategy = gpg.GPGStrategy(branch_config)
65
65
 
66
66
        count = 0
83
83
                        continue
84
84
                    # We have a revision without a signature who has a
85
85
                    # matching committer, start signing
86
 
                    print rev_id
 
86
                    self.outf.write("%s\n" % rev_id)
87
87
                    count += 1
88
88
                    if not dry_run:
89
89
                        repo.sign_revision(rev_id, gpg_strategy)
94
94
                repo.commit_write_group()
95
95
        finally:
96
96
            repo.unlock()
97
 
        print 'Signed %d revisions' % (count,)
 
97
        self.outf.write(
 
98
            ngettext('Signed %d revision.\n', 'Signed %d revisions.\n', count) %
 
99
            count)
98
100
 
99
101
 
100
102
class cmd_verify_signatures(Command):
109
111
                        ' acceptable for verification.',
110
112
                   short_name='k',
111
113
                   type=str,),
112
 
            'revision', 
 
114
            'revision',
113
115
            'verbose',
114
116
          ]
115
117
    takes_args = ['location?']
116
118
 
117
119
    def run(self, acceptable_keys=None, revision=None, verbose=None,
118
120
                                                            location=u'.'):
119
 
        bzrdir = _mod_bzrdir.BzrDir.open_containing(location)[0]
 
121
        bzrdir = controldir.ControlDir.open_containing(location)[0]
120
122
        branch = bzrdir.open_branch()
121
123
        repo = branch.repository
122
 
        branch_config = branch.get_config()
 
124
        branch_config = branch.get_config_stack()
123
125
        gpg_strategy = gpg.GPGStrategy(branch_config)
124
126
 
125
127
        gpg_strategy.set_acceptable_keys(acceptable_keys)
129
131
        def write_verbose(string):
130
132
            self.outf.write("  " + string + "\n")
131
133
 
 
134
        self.add_cleanup(repo.lock_read().unlock)
132
135
        #get our list of revisions
133
136
        revisions = []
134
137
        if revision is not None:
141
144
                if to_revid is None:
142
145
                    to_revno = branch.revno()
143
146
                if from_revno is None or to_revno is None:
144
 
                    raise errors.BzrCommandError('Cannot verify a range of '\
145
 
                                               'non-revision-history revisions')
 
147
                    raise errors.BzrCommandError(gettext(
 
148
                    'Cannot verify a range of non-revision-history revisions'))
146
149
                for revno in range(from_revno, to_revno + 1):
147
150
                    revisions.append(branch.get_rev_id(revno))
148
151
        else:
149
152
            #all revisions by default including merges
150
153
            graph = repo.get_graph()
151
154
            revisions = []
152
 
            repo.lock_read()
153
155
            for rev_id, parents in graph.iter_ancestry(
154
156
                    [branch.last_revision()]):
155
157
                if _mod_revision.is_null(rev_id):
158
160
                    # Ignore ghosts
159
161
                    continue
160
162
                revisions.append(rev_id)
161
 
            repo.unlock()
162
 
        count, result, all_verifiable =\
163
 
                                gpg_strategy.do_verifications(revisions, repo)
 
163
        count, result, all_verifiable = gpg.bulk_verify_signatures(
 
164
            repo, revisions, gpg_strategy)
164
165
        if all_verifiable:
165
 
               write(gettext(
166
 
                            "All commits signed with verifiable keys"))
 
166
               write(gettext("All commits signed with verifiable keys"))
167
167
               if verbose:
168
 
                   write(gpg_strategy.verbose_valid_message(result))
 
168
                   for message in gpg.verbose_valid_message(result):
 
169
                       write_verbose(message)
169
170
               return 0
170
171
        else:
171
 
            write(gpg_strategy.valid_commits_message(count))
172
 
            if verbose:
173
 
               for message in gpg_strategy.verbose_valid_message(result):
174
 
                   write_verbose(message)
175
 
            write(gpg_strategy.unknown_key_message(count))
176
 
            if verbose:
177
 
                for message in gpg_strategy.verbose_missing_key_message(result):
 
172
            write(gpg.valid_commits_message(count))
 
173
            if verbose:
 
174
               for message in gpg.verbose_valid_message(result):
 
175
                   write_verbose(message)
 
176
            write(gpg.expired_commit_message(count))
 
177
            if verbose:
 
178
               for message in gpg.verbose_expired_key_message(result, repo):
 
179
                   write_verbose(message)
 
180
            write(gpg.unknown_key_message(count))
 
181
            if verbose:
 
182
                for message in gpg.verbose_missing_key_message(result):
178
183
                    write_verbose(message)
179
 
            write(gpg_strategy.commit_not_valid_message(count))
 
184
            write(gpg.commit_not_valid_message(count))
180
185
            if verbose:
181
 
                for message in gpg_strategy.verbose_not_valid_message(result,
182
 
                                                                        repo):
 
186
                for message in gpg.verbose_not_valid_message(result, repo):
183
187
                   write_verbose(message)
184
 
            write(gpg_strategy.commit_not_signed_message(count))
 
188
            write(gpg.commit_not_signed_message(count))
185
189
            if verbose:
186
 
                for message in gpg_strategy.verbose_not_signed_message(result,
187
 
                                                                          repo):
 
190
                for message in gpg.verbose_not_signed_message(result, repo):
188
191
                    write_verbose(message)
189
192
            return 1