~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/gpg.py

Fix BzrDir.create_workingtree for NULL_REVISION

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