-
-
Save heewa/ffac2020110ad9b111b2 to your computer and use it in GitHub Desktop.
Nicer error msg for missing a library.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import third party libs | |
try: | |
from M2Crypto import RSA | |
from Crypto.Cipher import AES | |
except ImportError: | |
# No need for crypt in local mode, but give a nicer message | |
class CryptoErrorClass(): | |
def __init__(self, necessary_lib): | |
self._lib = necessary_lib | |
def __getattr__(self, attr): | |
log.error('Missing %s library, needed for remote master communication.', self._lib) | |
raise Exception('Missing {0} library.'.format(self._lib)) | |
RSA = CryptoErrorClass('M2Crypto') | |
AES = CryptoErrorClass('Crypto') | |
... | |
gen = RSA.gen_key(...) | |
... -> Exception: You need to install m2crypto. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment