mirror of
https://github.com/BOSWatch/BW3-Core.git
synced 2026-04-04 13:57:44 +00:00
add resource and name to route point
This commit is contained in:
parent
39aeb6c93a
commit
5dcd71eb8d
5 changed files with 19 additions and 14 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue