Commit 40f3e4ba authored by Pavel Spirek's avatar Pavel Spirek

Backend can now write data to backend at startup

parent 2beda877
...@@ -204,6 +204,19 @@ def main(): ...@@ -204,6 +204,19 @@ def main():
op_internal.register_op_handlers(datastore) op_internal.register_op_handlers(datastore)
usr_op_handlers.register_op_handlers(datastore) usr_op_handlers.register_op_handlers(datastore)
# Write datastore content to the backend application (if required)
try:
confh_ros = usr_conf_data_handlers.run_on_startup
except AttributeError:
pass
else:
try:
confh_ros()
except Exception as e:
error("Writing configuration to backend failed")
error(ErrorHelpers.epretty(e))
sig_exit_handler(0, None)
# Create HTTP server # Create HTTP server
rest_srv = RestServer() rest_srv = RestServer()
rest_srv.register_api_handlers(datastore) rest_srv.register_api_handlers(datastore)
......
...@@ -344,7 +344,7 @@ class BaseDatastore: ...@@ -344,7 +344,7 @@ class BaseDatastore:
if sn is None: if sn is None:
return return
h = CONF_DATA_HANDLES.get_handler(str(id(sn))) h = CONF_DATA_HANDLES.get_handler(id(sn))
if h is not None: if h is not None:
info("handler for actual data node triggered") info("handler for actual data node triggered")
if isinstance(h, ConfDataObjectHandler): if isinstance(h, ConfDataObjectHandler):
...@@ -364,7 +364,7 @@ class BaseDatastore: ...@@ -364,7 +364,7 @@ class BaseDatastore:
else: else:
sn = sn.parent sn = sn.parent
while sn is not None: while sn is not None:
h = CONF_DATA_HANDLES.get_handler(str(id(sn))) h = CONF_DATA_HANDLES.get_handler(id(sn))
if h is not None and isinstance(h, ConfDataObjectHandler): if h is not None and isinstance(h, ConfDataObjectHandler):
info("handler for superior data node triggered, replace") info("handler for superior data node triggered, replace")
# print(h.schema_path) # print(h.schema_path)
......
...@@ -116,8 +116,7 @@ class ConfDataHandlerList: ...@@ -116,8 +116,7 @@ class ConfDataHandlerList:
self.handlers = [] # type: List[Tuple[HandlerSelectorT, BaseDataListener]] self.handlers = [] # type: List[Tuple[HandlerSelectorT, BaseDataListener]]
def register(self, handler: "BaseDataListener"): def register(self, handler: "BaseDataListener"):
schema_node = handler.schema_node # type: SchemaNode sch_node_id = id(handler.schema_node)
sch_node_id = str(id(schema_node))
self.handlers.append((sch_node_id, handler)) self.handlers.append((sch_node_id, handler))
def get_handler(self, sch_node_id: str) -> "BaseDataListener": def get_handler(self, sch_node_id: str) -> "BaseDataListener":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment