~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/gpg.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-08-15 01:33:03 UTC
  • mfrom: (1912.3.4 gpg-agent)
  • Revision ID: pqm@pqm.ubuntu.com-20060815013303-e6a7352909ba2829
(jam) use GPG_TTY to fix bug #54468

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