~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/gpg.py

  • Committer: Alexander Belchenko
  • Date: 2006-07-31 16:12:57 UTC
  • mto: (1711.2.111 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1906.
  • Revision ID: bialix@ukr.net-20060731161257-91a231523255332c
new official bzr.ico

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: