From 0d820477c2e9493af5ae7ece70ce457b3ac4a8f0 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Fri, 29 Jul 2016 01:28:12 +0200 Subject: [PATCH] GPG: Improve error messages. --- plugins/GPG/plugin.py | 20 ++++++++++++++++++++ src/gpg.py | 7 +++++++ 2 files changed, 27 insertions(+) diff --git a/plugins/GPG/plugin.py b/plugins/GPG/plugin.py index b34aa925e..5d05e9924 100644 --- a/plugins/GPG/plugin.py +++ b/plugins/GPG/plugin.py @@ -32,6 +32,7 @@ import re import sys import time import uuid +import functools import supybot.gpg as gpg import supybot.conf as conf @@ -50,6 +51,25 @@ except ImportError: # without the i18n module _ = lambda x: x +def check_gpg_available(f): + if gpg.available: + return f + else: + if not gpg.found_gnupg_lib: + def newf(self, irc, *args): + irc.error(_('gnupg features are not available because ' + 'the python-gnupg library is not installed.')) + elif not gpg.found_gnupg_bin: + def newf(self, irc, *args): + irc.error(_('gnupg features are not available because ' + 'the gnupg executable is not installed.')) + else: + # This case should never happen. + def newf(self, irc, *args): + irc.error(_('gnupg features are not available.')) + newf.__doc__ = f.__doc__ + newf.__name__ = f.__name__ + return newf class GPG(callbacks.Plugin): """Provides authentication based on GPG keys.""" diff --git a/src/gpg.py b/src/gpg.py index 45e17e60c..40b6ffc3f 100644 --- a/src/gpg.py +++ b/src/gpg.py @@ -32,6 +32,8 @@ import os import supybot.log as log import supybot.conf as conf +found_gnupg_lib = False +found_gnupg_bin = False try: import gnupg except ImportError: @@ -42,11 +44,16 @@ except ImportError: try: if gnupg: gnupg.GPG(gnupghome=None) + found_gnupg_lib = found_gnupg_bin = True except TypeError: # This is the 'gnupg' library, not 'python-gnupg'. gnupg = None + log.error('Cannot use GPG. gnupg (a Python package) is installed, ' + 'but python-gnupg (an other Python package) should be ' + 'installed instead.') except OSError: gnupg = None + found_gnupg_lib = True log.error('Cannot use GPG. python-gnupg is installed but cannot ' 'find the gnupg executable.')