~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/gpg.py

  • Committer: John Arbash Meinel
  • Date: 2006-02-15 15:18:44 UTC
  • mto: (1185.79.1 bzr-jam-pending)
  • mto: This revision was merged to the branch mainline in revision 1554.
  • Revision ID: john@arbash-meinel.com-20060215151844-ce3e3efccd19da3f
Reverting gpg changes, should not be mainline, see gpg_uses_tempfile plugin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
import errno
21
21
import subprocess
22
 
import tempfile
23
22
 
24
23
import bzrlib.errors as errors
25
24
 
26
 
 
27
25
class DisabledGPGStrategy(object):
28
26
    """A GPG Strategy that makes everything fail."""
29
27
 
48
46
    """GPG Signing and checking facilities."""
49
47
        
50
48
    def _command_line(self):
51
 
        return [self._config.gpg_signing_command(),
52
 
                '--output', '-', '--clearsign']
 
49
        return [self._config.gpg_signing_command(), '--clearsign']
53
50
 
54
51
    def __init__(self, config):
55
52
        self._config = config
56
53
 
57
54
    def sign(self, content):
58
 
        f = tempfile.NamedTemporaryFile()
59
 
        cmd = self._command_line() + [f.name]
60
 
        f.write(content)
61
 
        f.flush()
62
55
        try:
63
 
            process = subprocess.Popen(cmd,
 
56
            process = subprocess.Popen(self._command_line(),
 
57
                                       stdin=subprocess.PIPE,
64
58
                                       stdout=subprocess.PIPE)
65
59
            try:
66
 
                result = process.communicate()[0]
 
60
                result = process.communicate(content)[0]
67
61
                if process.returncode is None:
68
62
                    process.wait()
69
63
                if process.returncode != 0:
70
 
                    raise errors.SigningFailed(cmd)
 
64
                    raise errors.SigningFailed(self._command_line())
71
65
                return result
72
66
            except OSError, e:
73
67
                if e.errno == errno.EPIPE:
74
 
                    raise errors.SigningFailed(cmd)
 
68
                    raise errors.SigningFailed(self._command_line())
75
69
                else:
76
70
                    raise
77
71
        except ValueError:
80
74
        except OSError, e:
81
75
            if e.errno == errno.ENOENT:
82
76
                # gpg is not installed
83
 
                raise errors.SigningFailed(cmd)
 
77
                raise errors.SigningFailed(self._command_line())
84
78
            else:
85
79
                raise
86
 
        f.close()