diff options
author | Michał Górny <mgorny@gentoo.org> | 2017-11-27 16:16:03 +0100 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2017-11-27 16:16:03 +0100 |
commit | e69bf65543ad6104a760d0b7f278a7bdfaf7b8e2 (patch) | |
tree | 9e33fd20feb38a879cb6d8fff3cbe72751ebb14a | |
parent | 7c369d2be972c4aee919252cd850cae3b772e9bc (diff) | |
download | gemato-e69bf65543ad6104a760d0b7f278a7bdfaf7b8e2.tar.gz |
openpgp: Cache the correct GnuPG executable
-rw-r--r-- | gemato/openpgp.py | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/gemato/openpgp.py b/gemato/openpgp.py index c3c2f4e..0623e58 100644 --- a/gemato/openpgp.py +++ b/gemato/openpgp.py @@ -16,6 +16,8 @@ def _spawn_gpg(options, env_instance, stdin): impls = ['gpg2', 'gpg'] if env_instance is not None: env={'GNUPGHOME': env_instance.home} + if env_instance._impl is not None: + impls = [env_instance._impl] for impl in impls: try: @@ -33,7 +35,7 @@ def _spawn_gpg(options, env_instance, stdin): raise gemato.exceptions.OpenPGPNoImplementation() if env_instance is not None: - env_instance._set_started() + env_instance._impl = impl out, err = p.communicate(stdin) return (p.wait(), out, err) @@ -48,11 +50,11 @@ class OpenPGPEnvironment(object): or use as a context manager (via 'with'). """ - __slots__ = ['_home', '_started'] + __slots__ = ['_home', '_impl'] def __init__(self): self._home = tempfile.mkdtemp() - self._started = False + self._impl = None def __enter__(self): return self @@ -61,9 +63,6 @@ class OpenPGPEnvironment(object): if self._home is not None: self.close() - def _set_started(self): - self._started = True - @staticmethod def _rmtree_error_handler(func, path, exc_info): # ignore ENOENT -- it probably means a race condition between @@ -74,7 +73,7 @@ class OpenPGPEnvironment(object): def close(self): if self._home is not None: - if self._started: + if self._impl is not None: try: # terminate the agent spawned by the process subprocess.Popen(['gpgconf', '--kill', 'all'], |