Skip to content

Commit

Permalink
Better injection for the plugin logger.
Browse files Browse the repository at this point in the history
  • Loading branch information
Neoklosch committed Jun 14, 2017
1 parent 25ade76 commit 2e52965
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
10 changes: 5 additions & 5 deletions motey/val/plugins/abstractVAL.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from yapsy.IPlugin import IPlugin

from motey.di.app_module import DICore


class AbstractVAL(IPlugin):
"""
Expand All @@ -17,7 +15,7 @@ def __init__(self):
Constructor of the AbstractVAL.
"""
super().__init__()
self.logger = DICore.logger()
self.logger = None

def get_plugin_type(self):
"""
Expand Down Expand Up @@ -117,10 +115,12 @@ def activate(self):
"""
Called at plugin activation.
"""
self.logger.info("%s plugin activated" % self.get_plugin_type())
if self.logger:
self.logger.info("%s plugin activated" % self.get_plugin_type())

def deactivate(self):
"""
Called when the plugin is disabled.
"""
self.logger.info("%s plugin deactivated" % self.get_plugin_type())
if self.logger:
self.logger.info("%s plugin deactivated" % self.get_plugin_type())
18 changes: 12 additions & 6 deletions motey/val/plugins/dockerVAL.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,14 @@ def create_instance(self, image_name, parameters={}):
parameters.pop('detach')
container = client.containers.create(image_name, detach=True, **parameters)
except ContainerError as ce:
self.logger.error("create docker instance > container could not be created")
if self.logger:
self.logger.error("create docker instance > container could not be created")
except ImageNotFound as inf:
self.logger.error("create docker instance > image not found")
if self.logger:
self.logger.error("create docker instance > image not found")
except APIError as apie:
self.logger.error("create docker instance > api error")
if self.logger:
self.logger.error("create docker instance > api error")
return container_id

def start_instance(self, instance_name, parameters={}):
Expand All @@ -123,11 +126,14 @@ def start_instance(self, instance_name, parameters={}):
container = client.containers.run(instance_name, detach=True, **parameters)
container_id = container.id
except ContainerError as ce:
self.logger.error("start docker instance > container could not be created")
if self.logger:
self.logger.error("start docker instance > container could not be created")
except ImageNotFound as inf:
self.logger.error("start docker instance > image not found")
if self.logger:
self.logger.error("start docker instance > image not found")
except APIError as apie:
self.logger.error("start docker instance > api error")
if self.logger:
self.logger.error("start docker instance > api error")
return container_id

def stop_instance(self, container_name):
Expand Down
2 changes: 1 addition & 1 deletion motey/val/valmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def register_plugins(self):
"""

self.labeling_repository.remove_all_from_type('plugin')
print(absolute_file_path("motey/val/plugins"))
self.plugin_manager.setPluginPlaces([absolute_file_path("motey/val/plugins")])
self.plugin_manager.collectPlugins()
for plugin in self.plugin_manager.getAllPlugins():
plugin.plugin_object.logger = self.logger
plugin.plugin_object.activate()
self.labeling_repository.add(plugin.plugin_object.get_plugin_type(), 'plugin')

Expand Down

0 comments on commit 2e52965

Please sign in to comment.