~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/gpg.py

  • Committer: Aaron Bentley
  • Date: 2006-09-20 14:03:05 UTC
  • mto: This revision was merged to the branch mainline in revision 2162.
  • Revision ID: abentley@panoramicfeedback.com-20060920140305-7726fe3eb92690b1
Get tree._iter_changed down to ~ 1 stat per file

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
 
import bzrlib.errors as errors
 
23
import sys
 
24
 
 
25
from bzrlib import (
 
26
    errors,
 
27
    trace,
 
28
    ui,
 
29
    )
 
30
 
24
31
 
25
32
class DisabledGPGStrategy(object):
26
33
    """A GPG Strategy that makes everything fail."""
42
49
        return content
43
50
 
44
51
 
 
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
 
45
65
class GPGStrategy(object):
46
66
    """GPG Signing and checking facilities."""
47
67
        
52
72
        self._config = config
53
73
 
54
74
    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
55
81
        try:
56
82
            process = subprocess.Popen(self._command_line(),
57
83
                                       stdin=subprocess.PIPE,
58
 
                                       stdout=subprocess.PIPE)
 
84
                                       stdout=subprocess.PIPE,
 
85
                                       preexec_fn=preexec_fn)
59
86
            try:
60
87
                result = process.communicate(content)[0]
61
88
                if process.returncode is None: