~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/gpg.py

  • Committer: Robert Collins
  • Date: 2006-01-05 10:49:26 UTC
  • mto: (1534.1.2 integration)
  • mto: This revision was merged to the branch mainline in revision 1536.
  • Revision ID: robertc@robertcollins.net-20060105104926-6e5dc14eff2352ca
Implement deprecated_method

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""GPG signing and checking logic."""
19
19
 
20
20
import errno
21
 
import os
22
21
import subprocess
23
 
import sys
24
 
 
25
 
from bzrlib import (
26
 
    errors,
27
 
    trace,
28
 
    ui,
29
 
    )
30
 
 
 
22
 
 
23
import bzrlib.errors as errors
31
24
 
32
25
class DisabledGPGStrategy(object):
33
26
    """A GPG Strategy that makes everything fail."""
49
42
        return content
50
43
 
51
44
 
52
 
def _set_gpg_tty():
53
 
    tty = os.environ.get('TTY')
54
 
    if tty is not None:
55
 
        os.environ['GPG_TTY'] = tty
56
 
        trace.mutter('setting GPG_TTY=%s', tty)
57
 
    else:
58
 
        # This is not quite worthy of a warning, because some people
59
 
        # don't need GPG_TTY to be set. But it is worthy of a big mark
60
 
        # in ~/.bzr.log, so that people can debug it if it happens to them
61
 
        trace.mutter('** Env var TTY empty, cannot set GPG_TTY.'
62
 
                     '  Is TTY exported?')
63
 
 
64
 
 
65
45
class GPGStrategy(object):
66
46
    """GPG Signing and checking facilities."""
67
47
        
72
52
        self._config = config
73
53
 
74
54
    def sign(self, content):
75
 
        ui.ui_factory.clear_term()
76
 
 
77
 
        preexec_fn = _set_gpg_tty
78
 
        if sys.platform == 'win32':
79
 
            # Win32 doesn't support preexec_fn, but wouldn't support TTY anyway.
80
 
            preexec_fn = None
81
55
        try:
82
56
            process = subprocess.Popen(self._command_line(),
83
57
                                       stdin=subprocess.PIPE,
84
 
                                       stdout=subprocess.PIPE,
85
 
                                       preexec_fn=preexec_fn)
 
58
                                       stdout=subprocess.PIPE)
86
59
            try:
87
60
                result = process.communicate(content)[0]
88
61
                if process.returncode is None: