~matthew-t-bentley/duplicity/duplicity

« back to all changes in this revision

Viewing changes to duplicity/gpg.py

  • Committer: Kenneth Loafman
  • Date: 2016-10-22 21:01:58 UTC
  • Revision ID: kenneth@loafman.com-20161022210158-ru289ad0911dhqc7
* Merged in lp:~mwilck/duplicity/duplicity
  - GPG: enable truly non-interactive operation with gpg2
  - This patch fixes the IMO unexpected behavior that, when using GnuPG2, a pass phrase dialog always pops up for
    saving backups. This is particularly annoying when trying to do unattended / fully automatic backups.

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
        else:
88
88
            self.hidden_recipients = []
89
89
 
 
90
        self.gpg_major = self.get_gpg_major(globals.gpg_binary)
 
91
 
 
92
    _version_re = re.compile(r'^gpg.*\(GnuPG\) (?P<maj>[0-9])\.[0-9]+\.[0-9]+$')
 
93
 
 
94
    def get_gpg_major(self, binary):
 
95
        gpg = gpginterface.GnuPG()
 
96
        if binary is not None:
 
97
            gpg.call = binary
 
98
        res = gpg.run(["--version"], create_fhs=["stdout"])
 
99
        line = res.handles["stdout"].readline().rstrip()
 
100
        mtc = self._version_re.search(line)
 
101
        if mtc is not None:
 
102
            return int(mtc.group("maj"), 10)
 
103
        raise GPGError("failed to determine gpg version of %s from %s" % (binary, line))
90
104
 
91
105
class GPGFile:
92
106
    """
121
135
        gnupg.options.extra_args.append('--no-secmem-warning')
122
136
        if globals.use_agent:
123
137
            gnupg.options.extra_args.append('--use-agent')
 
138
        elif profile.gpg_major == 2:
 
139
            # This forces gpg2 to ignore the agent.
 
140
            # Necessary to enforce truly non-interactive operation.
 
141
            gnupg.options.extra_args.append('--pinentry-mode=cancel')
124
142
        if globals.gpg_options:
125
143
            for opt in globals.gpg_options.split():
126
144
                gnupg.options.extra_args.append(opt)