Extract the notification part of controller to a dedicated class

This commit is contained in:
Julien Duponchelle committed 2016-05-18 14:56:23 +02:00
1 parent d86cefaaeb
commit 694e1a2e68
10 files changed
+162 -106

No files matched your search

+9 -14
View File
@@ -24,6 +24,7 @@ import aiohttp
from ..config import Config
from .project import Project
from .compute import Compute
from .notification import Notification
from ..version import __version__
import logging
@@ -36,6 +37,7 @@ class Controller:
def __init__(self):
self._computes = {}
self._projects = {}
self._notification = Notification(self)
if sys.platform.startswith("win"):
config_path = os.path.join(os.path.expandvars("%APPDATA%"), "GNS3")
@@ -116,6 +118,13 @@ class Controller:
password=server_config.get("password", ""))
return self._computes["local"]
@property
def notification(self):
"""
The notification system
"""
return self._notification
@property
def computes(self):
"""
@@ -180,17 +189,3 @@ class Controller:
Controller._instance = Controller()
return Controller._instance
def emit(self, action, event, **kwargs):
"""
Send a notification to clients scoped by projects
"""
if "project_id" in kwargs:
try:
project_id = kwargs.pop("project_id")
self._projects[project_id].emit(action, event, **kwargs)
except KeyError:
pass
else:
for project_instance in self._projects.values():
project_instance.emit(action, event, **kwargs)