/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to brzlib/commit_signature_commands.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""Command that signs unsigned commits by the current user. """
18
 
 
19
 
from . import (
 
17
"""Command which looks for unsigned commits by the current user, and signs them.
 
18
"""
 
19
 
 
20
from __future__ import absolute_import
 
21
 
 
22
from brzlib import (
20
23
    controldir,
21
24
    errors,
22
25
    gpg,
23
 
    repository as _mod_repository,
24
26
    revision as _mod_revision,
25
27
    )
26
 
from .commands import Command
27
 
from .option import Option
28
 
from .i18n import gettext, ngettext
 
28
from brzlib.commands import Command
 
29
from brzlib.option import Option
 
30
from brzlib.i18n import gettext, ngettext
29
31
 
30
32
 
31
33
class cmd_sign_my_commits(Command):
41
43
    # repository
42
44
 
43
45
    takes_options = [
44
 
        Option('dry-run',
45
 
               help='Don\'t actually sign anything, just print'
46
 
               ' the revisions that would be signed.'),
47
 
        ]
 
46
            Option('dry-run',
 
47
                   help='Don\'t actually sign anything, just print'
 
48
                        ' the revisions that would be signed.'),
 
49
            ]
48
50
    takes_args = ['location?', 'committer?']
49
51
 
50
52
    def run(self, location=None, committer=None, dry_run=False):
62
64
        gpg_strategy = gpg.GPGStrategy(branch_config)
63
65
 
64
66
        count = 0
65
 
        with repo.lock_write():
 
67
        repo.lock_write()
 
68
        try:
66
69
            graph = repo.get_graph()
67
 
            with _mod_repository.WriteGroup(repo):
 
70
            repo.start_write_group()
 
71
            try:
68
72
                for rev_id, parents in graph.iter_ancestry(
69
73
                        [branch.last_revision()]):
70
74
                    if _mod_revision.is_null(rev_id):
83
87
                    count += 1
84
88
                    if not dry_run:
85
89
                        repo.sign_revision(rev_id, gpg_strategy)
 
90
            except:
 
91
                repo.abort_write_group()
 
92
                raise
 
93
            else:
 
94
                repo.commit_write_group()
 
95
        finally:
 
96
            repo.unlock()
86
97
        self.outf.write(
87
 
            ngettext('Signed %d revision.\n', 'Signed %d revisions.\n',
88
 
                     count) % count)
 
98
            ngettext('Signed %d revision.\n', 'Signed %d revisions.\n', count) %
 
99
            count)
89
100
 
90
101
 
91
102
class cmd_verify_signatures(Command):
95
106
    """
96
107
 
97
108
    takes_options = [
98
 
        Option('acceptable-keys',
99
 
               help='Comma separated list of GPG key patterns which are'
100
 
               ' acceptable for verification.',
101
 
               short_name='k',
102
 
               type=str,),
103
 
        'revision',
104
 
        'verbose',
105
 
        ]
 
109
            Option('acceptable-keys',
 
110
                   help='Comma separated list of GPG key patterns which are'
 
111
                        ' acceptable for verification.',
 
112
                   short_name='k',
 
113
                   type=str,),
 
114
            'revision',
 
115
            'verbose',
 
116
          ]
106
117
    takes_args = ['location?']
107
118
 
108
119
    def run(self, acceptable_keys=None, revision=None, verbose=None,
109
 
            location=u'.'):
 
120
                                                            location=u'.'):
110
121
        bzrdir = controldir.ControlDir.open_containing(location)[0]
111
122
        branch = bzrdir.open_branch()
112
123
        repo = branch.repository
117
128
 
118
129
        def write(string):
119
130
            self.outf.write(string + "\n")
120
 
 
121
131
        def write_verbose(string):
122
132
            self.outf.write("  " + string + "\n")
123
133
 
124
134
        self.add_cleanup(repo.lock_read().unlock)
125
 
        # get our list of revisions
 
135
        #get our list of revisions
126
136
        revisions = []
127
137
        if revision is not None:
128
138
            if len(revision) == 1:
134
144
                if to_revid is None:
135
145
                    to_revno = branch.revno()
136
146
                if from_revno is None or to_revno is None:
137
 
                    raise errors.BzrCommandError(
138
 
                        gettext('Cannot verify a range of non-revision-history'
139
 
                                ' revisions'))
 
147
                    raise errors.BzrCommandError(gettext(
 
148
                    'Cannot verify a range of non-revision-history revisions'))
140
149
                for revno in range(from_revno, to_revno + 1):
141
150
                    revisions.append(branch.get_rev_id(revno))
142
151
        else:
143
 
            # all revisions by default including merges
 
152
            #all revisions by default including merges
144
153
            graph = repo.get_graph()
145
154
            revisions = []
146
155
            for rev_id, parents in graph.iter_ancestry(
154
163
        count, result, all_verifiable = gpg.bulk_verify_signatures(
155
164
            repo, revisions, gpg_strategy)
156
165
        if all_verifiable:
157
 
            write(gettext("All commits signed with verifiable keys"))
158
 
            if verbose:
159
 
                for message in gpg.verbose_valid_message(result):
160
 
                    write_verbose(message)
161
 
            return 0
 
166
               write(gettext("All commits signed with verifiable keys"))
 
167
               if verbose:
 
168
                   for message in gpg.verbose_valid_message(result):
 
169
                       write_verbose(message)
 
170
               return 0
162
171
        else:
163
172
            write(gpg.valid_commits_message(count))
164
173
            if verbose:
165
 
                for message in gpg.verbose_valid_message(result):
166
 
                    write_verbose(message)
 
174
               for message in gpg.verbose_valid_message(result):
 
175
                   write_verbose(message)
167
176
            write(gpg.expired_commit_message(count))
168
177
            if verbose:
169
 
                for message in gpg.verbose_expired_key_message(result, repo):
170
 
                    write_verbose(message)
 
178
               for message in gpg.verbose_expired_key_message(result, repo):
 
179
                   write_verbose(message)
171
180
            write(gpg.unknown_key_message(count))
172
181
            if verbose:
173
182
                for message in gpg.verbose_missing_key_message(result):
175
184
            write(gpg.commit_not_valid_message(count))
176
185
            if verbose:
177
186
                for message in gpg.verbose_not_valid_message(result, repo):
178
 
                    write_verbose(message)
 
187
                   write_verbose(message)
179
188
            write(gpg.commit_not_signed_message(count))
180
189
            if verbose:
181
190
                for message in gpg.verbose_not_signed_message(result, repo):