~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/gpg.py

  • Committer: Jelmer Vernooij
  • Date: 2011-02-26 15:39:49 UTC
  • mto: (5691.1.1 bzr.dev)
  • mto: This revision was merged to the branch mainline in revision 5692.
  • Revision ID: jelmer@samba.org-20110226153949-o0fk909b30g7z570
Fix the use of "bzr tags" in branches with ghosts in their mainline /and/ tags on revisions not in the branch ancestry.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 by Canonical Ltd
 
1
# Copyright (C) 2005 Canonical Ltd
2
2
#   Authors: Robert Collins <robert.collins@canonical.com>
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
13
13
#
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
 
18
18
"""GPG signing and checking logic."""
19
19
 
 
20
import os
 
21
import sys
 
22
 
 
23
from bzrlib.lazy_import import lazy_import
 
24
lazy_import(globals(), """
20
25
import errno
21
 
import os
22
26
import subprocess
23
27
 
24
28
from bzrlib import (
26
30
    trace,
27
31
    ui,
28
32
    )
 
33
""")
29
34
 
30
35
 
31
36
class DisabledGPGStrategy(object):
45
50
        """Real strategies take a configuration."""
46
51
 
47
52
    def sign(self, content):
48
 
        return content
 
53
        return ("-----BEGIN PSEUDO-SIGNED CONTENT-----\n" + content +
 
54
                "-----END PSEUDO-SIGNED CONTENT-----\n")
49
55
 
50
56
 
51
57
def _set_gpg_tty():
63
69
 
64
70
class GPGStrategy(object):
65
71
    """GPG Signing and checking facilities."""
66
 
        
 
72
 
67
73
    def _command_line(self):
68
74
        return [self._config.gpg_signing_command(), '--clearsign']
69
75
 
71
77
        self._config = config
72
78
 
73
79
    def sign(self, content):
 
80
        if isinstance(content, unicode):
 
81
            raise errors.BzrBadParameterUnicode('content')
74
82
        ui.ui_factory.clear_term()
 
83
 
 
84
        preexec_fn = _set_gpg_tty
 
85
        if sys.platform == 'win32':
 
86
            # Win32 doesn't support preexec_fn, but wouldn't support TTY anyway.
 
87
            preexec_fn = None
75
88
        try:
76
89
            process = subprocess.Popen(self._command_line(),
77
90
                                       stdin=subprocess.PIPE,
78
91
                                       stdout=subprocess.PIPE,
79
 
                                       preexec_fn=_set_gpg_tty)
 
92
                                       preexec_fn=preexec_fn)
80
93
            try:
81
94
                result = process.communicate(content)[0]
82
95
                if process.returncode is None: