From 9530c4d7db8f0af404c7a08986c208a788fe36a8 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Fri, 3 Nov 2017 10:52:27 +0200 Subject: [PATCH] gpg: use gpgconf for getting gpg binary path --- libagent/gpg/keyring.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/libagent/gpg/keyring.py b/libagent/gpg/keyring.py index 27f603d..76c8090 100644 --- a/libagent/gpg/keyring.py +++ b/libagent/gpg/keyring.py @@ -177,15 +177,17 @@ def sign_digest(sock, keygrip, digest, sp=subprocess, environ=None): return parse_sig(sig) +def get_gnupg_components(sp=subprocess): + """Parse GnuPG components' paths.""" + output = sp.check_output(['gpgconf', '--list-components']) + components = dict(re.findall('(.*):.*:(.*)', output.decode('ascii'))) + log.debug('gpgconf --list-components: %s', components) + return components + + def get_gnupg_binary(sp=subprocess): """Starting GnuPG 2.2.x, the default installation uses `gpg`.""" - for cmd in ['gpg2', 'gpg']: - try: - return sp.check_output(args=['which', cmd]).strip().decode('ascii') - except subprocess.CalledProcessError: - log.debug('%r not found', cmd) - continue - raise OSError('GnuPG seems to be not installed') + return get_gnupg_components(sp=sp)['gpg'] def gpg_command(args, env=None, sp=subprocess):