add resource and name to route point

This commit is contained in:
Bastian Schroll 2019-10-25 11:12:41 +02:00
parent 39aeb6c93a
commit 5dcd71eb8d
No known key found for this signature in database
GPG key ID: 0AE96912A20E9F5F
5 changed files with 19 additions and 14 deletions

View file

@ -28,7 +28,7 @@ class Router:
@param name: name of the router"""
self._name = name
self._routeList = []
logging.debug("[%s] new router", self._name)
logging.debug("[%s] add new router", self._name)
def addRoute(self, route):
"""!Adds a route point to the router
@ -46,8 +46,8 @@ class Router:
"""
logging.debug("[%s] started", self._name)
for routeObject in self._routeList:
logging.debug("[%s] -> run route: %s", self._name, routeObject)
bwPacket_tmp = routeObject.callback(copy.deepcopy(bwPacket)) # copy bwPacket to prevent edit the original
logging.debug("[%s] -> run route: %s", self._name, routeObject.name)
bwPacket_tmp = routeObject.callback._run(copy.deepcopy(bwPacket)) # copy bwPacket to prevent edit the original
if bwPacket_tmp is None: # returning None doesnt change the bwPacket
continue

View file

@ -64,23 +64,25 @@ class RouterManager:
for route in router.get("route"):
routeType = route.get("type")
routeName = route.get("name")
routeRes = route.get("res")
routeName = route.get("name", default=routeRes)
routeConfig = route.get("config", default=ConfigYAML()) # if no config - build a empty
if routeType is None or routeName is None:
if routeType is None or routeRes is None:
logging.error("type or name not found in route: %s", route)
return False
try:
if routeType == "plugin":
importedFile = importlib.import_module(routeType + "." + routeName)
importedFile = importlib.import_module(routeType + "." + routeRes)
loadedClass = importedFile.BoswatchPlugin(routeConfig)
routerDict_tmp[routerName].addRoute(Route(routeName, loadedClass._run))
routerDict_tmp[routerName].addRoute(Route(routeName, loadedClass))
elif routeType == "module":
importedFile = importlib.import_module(routeType + "." + routeName)
importedFile = importlib.import_module(routeType + "." + routeRes)
loadedClass = importedFile.BoswatchModule(routeConfig)
routerDict_tmp[routerName].addRoute(Route(routeName, loadedClass._run))
routerDict_tmp[routerName].addRoute(Route(routeName, loadedClass))
elif routeType == "router":
routerDict_tmp[routerName].addRoute(Route(routeName, routerDict_tmp[routeName].runRouter))
@ -91,7 +93,7 @@ class RouterManager:
# except ModuleNotFoundError: # only since Py3.6
except ImportError:
logging.error("%s not found: %s", route.get("type"), route.get("name"))
logging.error("%s not found: %s", route.get("type"), route.get("res"))
return False
logging.debug("finished building routers")

View file

@ -19,7 +19,8 @@ router:
- name: Router 1
route:
- type: module
name: filter.modeFilter
res: filter.modeFilter
name: Filter Fms/Zvei
config:
allowed:
- fms

View file

@ -110,7 +110,8 @@ Jeder Router kann eine beliebige Anzahl einzelner Routenpunkte enthalten. Diese
|Feld|Beschreibung|Default|
|----|------------|-------|
|type|Art des Routenpunktes (module, plugin, router)||
|name|Zu ladende Resource (Siehe entsprechende Kapitel)||
|res|Zu ladende Resource (Siehe entsprechende Kapitel)||
|name|Optionaler Name des Routenpunktes|gleich wie Resource|
|config|Konfigurationseinstellungen des Routenpunktes (Siehe entsprechende Kapitel)||
**Beispiel:**
@ -119,7 +120,8 @@ router:
- name: Router 1
route:
- type: module
name: filter.modeFilter
res: filter.modeFilter
name: Filter Fms/Zvei
config:
allowed:
- fms

View file

@ -16,7 +16,7 @@ Mit diesem Modul ist es Möglich, die Pakete auf bestimmte Modes (FMS, POCSAG, Z
**Beispiel:**
```yaml
- type: module
name: filter.modeFilter
res: filter.modeFilter
config:
allowed:
- fms