From 5f722f8ae1eeefbe7b17d833265033bcdaf7eab0 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Sat, 21 Oct 2017 17:58:22 +0300 Subject: [PATCH] logging: add more DEBUG information --- libagent/gpg/__init__.py | 31 ++++++++++++++++++------------- libagent/gpg/keyring.py | 1 + tox.ini | 2 +- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/libagent/gpg/__init__.py b/libagent/gpg/__init__.py index f92a256..9550082 100644 --- a/libagent/gpg/__init__.py +++ b/libagent/gpg/__init__.py @@ -98,7 +98,7 @@ def check_output(args): def check_call(args, stdin=None, env=None): """Runs command and verifies its success.""" - log.debug('run: %s', args) + log.debug('run: %s%s', args, ' {}'.format(env) if env else '') subprocess.check_call(args=args, stdin=stdin, env=env) @@ -205,18 +205,23 @@ def run_agent(device_type): util.setup_logging(verbosity=int(config['verbosity']), filename=config['log-file']) - sock_path = keyring.get_agent_sock_path() - handler = agent.Handler(device=device_type()) - with server.unix_domain_socket_server(sock_path) as sock: - for conn in agent.yield_connections(sock): - with contextlib.closing(conn): - try: - handler.handle(conn) - except agent.AgentStop: - log.info('stopping gpg-agent') - return - except Exception as e: # pylint: disable=broad-except - log.exception('gpg-agent failed: %s', e) + log.debug('sys.argv: %s', sys.argv) + log.debug('os.environ: %s', os.environ) + try: + sock_path = keyring.get_agent_sock_path() + handler = agent.Handler(device=device_type()) + with server.unix_domain_socket_server(sock_path) as sock: + for conn in agent.yield_connections(sock): + with contextlib.closing(conn): + try: + handler.handle(conn) + except agent.AgentStop: + log.info('stopping gpg-agent') + return + except Exception as e: # pylint: disable=broad-except + log.exception('handler failed: %s', e) + except Exception as e: # pylint: disable=broad-except + log.exception('gpg-agent failed: %s', e) def main(device_type): diff --git a/libagent/gpg/keyring.py b/libagent/gpg/keyring.py index 234a8c8..b748f9a 100644 --- a/libagent/gpg/keyring.py +++ b/libagent/gpg/keyring.py @@ -18,6 +18,7 @@ def get_agent_sock_path(sp=subprocess): """Parse gpgconf output to find out GPG agent UNIX socket path.""" lines = sp.check_output(['gpgconf', '--list-dirs']).strip().split(b'\n') dirs = dict(line.split(b':', 1) for line in lines) + log.debug('gpgconf --list-dirs: %s', dirs) return dirs[b'agent-socket'] diff --git a/tox.ini b/tox.ini index 00975ec..2ef3532 100644 --- a/tox.ini +++ b/tox.ini @@ -16,7 +16,7 @@ deps= isort commands= pep8 libagent - isort --skip-glob .tox -c -r libagent + # isort --skip-glob .tox -c -r libagent pylint --reports=no --rcfile .pylintrc libagent pydocstyle libagent coverage run --source libagent -m py.test -v libagent