mirror of
https://github.com/aljazceru/cowrie.git
synced 2025-12-17 05:54:21 +01:00
Improve handling of ImportErrors to notify users that they need to install new dependencies (#389)
* Improve handling of ImportErrors to notify users that they need to install new dependencies Also added missing dependency to requirements.txt * Mention installing dependencies in virtualenv if used * Move requirements used only by output modules to a separate file * Using a virtualenv is now the only officially supported method * Handle ImportErrors when loading output plugins so different install instructions can be given * Cleanup requirements-output.txt
This commit is contained in:
committed by
Michel Oosterhof
parent
ccbd05746e
commit
24c251b405
@@ -32,7 +32,7 @@ FIXME: This module contains ...
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from zope.interface import implementer
|
||||
from zope.interface import implementer, provider
|
||||
|
||||
import os
|
||||
import sys
|
||||
@@ -42,6 +42,7 @@ from twisted.plugin import IPlugin
|
||||
from twisted.application.service import IServiceMaker
|
||||
from twisted.application import internet, service
|
||||
from twisted.cred import portal
|
||||
from twisted.logger import ILogObserver, globalLogPublisher
|
||||
|
||||
from cowrie.core.config import readConfigFile
|
||||
from cowrie import core
|
||||
@@ -61,6 +62,16 @@ class Options(usage.Options):
|
||||
]
|
||||
|
||||
|
||||
@provider(ILogObserver)
|
||||
def importFailureObserver(event):
|
||||
if 'failure' in event and event['failure'].type is ImportError:
|
||||
log.err("ERROR: %s. Please run `pip install -U -r requirements.txt` "
|
||||
"from Cowrie's install directory and virtualenv to install "
|
||||
"the new dependency" % event['failure'].value.message)
|
||||
|
||||
|
||||
globalLogPublisher.addObserver(importFailureObserver)
|
||||
|
||||
|
||||
@implementer(IServiceMaker, IPlugin)
|
||||
class CowrieServiceMaker(object):
|
||||
@@ -132,7 +143,10 @@ class CowrieServiceMaker(object):
|
||||
log.addObserver(output.emit)
|
||||
self.output_plugins.append(output)
|
||||
log.msg("Loaded output engine: {}".format(engine))
|
||||
except:
|
||||
except ImportError as e:
|
||||
log.err("Failed to load output engine: {} due to ImportError: {}".format(engine, e))
|
||||
log.msg("Please install the dependencies for {} listed in requirements-output.txt".format(engine))
|
||||
except Exception:
|
||||
log.err()
|
||||
log.msg("Failed to load output engine: {}".format(engine))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user