From e69bf65543ad6104a760d0b7f278a7bdfaf7b8e2 Mon Sep 17 00:00:00 2001 From: Michał Górny Date: Mon, 27 Nov 2017 16:16:03 +0100 Subject: openpgp: Cache the correct GnuPG executable --- gemato/openpgp.py | 13 ++++++------- 1 file 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'], -- cgit v1.2.3