diff --git a/fkie_master_discovery/src/fkie_master_discovery/master_monitor.py b/fkie_master_discovery/src/fkie_master_discovery/master_monitor.py index 2e458e92..737eb4ed 100644 --- a/fkie_master_discovery/src/fkie_master_discovery/master_monitor.py +++ b/fkie_master_discovery/src/fkie_master_discovery/master_monitor.py @@ -1074,6 +1074,8 @@ def unregister_node(self, name: str) -> bool: for code, msg, _ in r: if code != 1: Log.warn(f"unregistration failed: {msg}") + else: + success = True except KeyError: msg = f"Error while unregistering node: Node '{name}' not found" Log.warn(msg) diff --git a/fkie_multimaster_pylib/fkie_multimaster_pylib/crossbar/file_interface.py b/fkie_multimaster_pylib/fkie_multimaster_pylib/crossbar/file_interface.py index 34fe1e79..735faa54 100644 --- a/fkie_multimaster_pylib/fkie_multimaster_pylib/crossbar/file_interface.py +++ b/fkie_multimaster_pylib/fkie_multimaster_pylib/crossbar/file_interface.py @@ -88,6 +88,26 @@ def __str__(self): return json.dumps(dict(self), ensure_ascii=False) +class LogPathClearResult: + """ + :param str node: complete node name + :param bool result: Clear result. + :param str message: Message on error. + """ + + def __init__( + self, + node: str, + result: bool = False, + message: str = "", + ) -> None: + self.node = node + self.result = result + self.message = message + + def __str__(self): + return json.dumps(dict(self), ensure_ascii=False) + class FileItem: """ :param str path: absolute path of the file or directory diff --git a/fkie_node_manager_daemon/fkie_node_manager_daemon/file_servicer.py b/fkie_node_manager_daemon/fkie_node_manager_daemon/file_servicer.py index 892a72e0..02618f37 100644 --- a/fkie_node_manager_daemon/fkie_node_manager_daemon/file_servicer.py +++ b/fkie_node_manager_daemon/fkie_node_manager_daemon/file_servicer.py @@ -34,6 +34,7 @@ from fkie_multimaster_pylib.crossbar.file_interface import RosPackage from fkie_multimaster_pylib.crossbar.file_interface import PathItem from fkie_multimaster_pylib.crossbar.file_interface import LogPathItem +from fkie_multimaster_pylib.crossbar.file_interface import LogPathClearResult from fkie_multimaster_pylib.logging.logging import Log from fkie_multimaster_pylib.system.screen import get_logfile from fkie_multimaster_pylib.system.screen import get_ros_logfile @@ -105,6 +106,47 @@ def getLogPaths(self, nodes: List[str]) -> List[LogPathItem]: result.append(log_path_item) return json.dumps(result, cls=SelfEncoder) + @wamp.register("ros.path.clear_log_paths") + def clearLogPaths(self, nodes: List[str]) -> List[LogPathClearResult]: + Log.info( + f"{self.__class__.__name__}: Request to [ros.path.clear_log_paths] for {nodes}" + ) + result = [] + for node in nodes: + namespace = None + node_name = node + + namespace_search = re.search("/(.*)/", node_name) + if namespace_search is not None: + namespace = f"/{namespace_search.group(1)}" + node_name = node.replace(f"/{namespace}/", "") + + screen_log = get_logfile( + node=node_name, for_new_screen=True, namespace=namespace + ) + ros_log = get_ros_logfile(node) + resultDelete = True + message = '' + if (os.path.exists(screen_log)): + try: + os.remove(screen_log) + except OSError as error: + resultDelete = False + message += f"Can not remove {screen_log}: {error}. " + if (os.path.exists(ros_log)): + try: + os.remove(ros_log) + except OSError as error: + resultDelete = False + message += f"Can not remove {ros_log}: {error}. " + log_path_item = LogPathClearResult( + node, + result=resultDelete, + message=message + ) + result.append(log_path_item) + return json.dumps(result, cls=SelfEncoder) + @wamp.register("ros.path.get_list") def getPathList(self, inputPath: str) -> List[PathItem]: Log.info( diff --git a/fkie_node_manager_daemon/src/fkie_node_manager_daemon/file_servicer.py b/fkie_node_manager_daemon/src/fkie_node_manager_daemon/file_servicer.py index b93efe12..4e5b320c 100644 --- a/fkie_node_manager_daemon/src/fkie_node_manager_daemon/file_servicer.py +++ b/fkie_node_manager_daemon/src/fkie_node_manager_daemon/file_servicer.py @@ -53,6 +53,7 @@ from fkie_multimaster_pylib.crossbar.file_interface import RosPackage from fkie_multimaster_pylib.crossbar.file_interface import PathItem from fkie_multimaster_pylib.crossbar.file_interface import LogPathItem +from fkie_multimaster_pylib.crossbar.file_interface import LogPathClearResult from fkie_multimaster_pylib.defines import PACKAGE_FILE from fkie_multimaster_pylib.launch import xml from fkie_multimaster_pylib.logging.logging import Log @@ -610,6 +611,47 @@ def getLogPaths(self, nodes: List[str]) -> List[LogPathItem]: result.append(log_path_item) return json.dumps(result, cls=SelfEncoder) + @wamp.register("ros.path.clear_log_paths") + def clearLogPaths(self, nodes: List[str]) -> List[LogPathClearResult]: + Log.info( + f"{self.__class__.__name__}: Request to [ros.path.clear_log_paths] for {nodes}" + ) + result = [] + for node in nodes: + namespace = None + node_name = node + + namespace_search = re.search("/(.*)/", node_name) + if namespace_search is not None: + namespace = f"/{namespace_search.group(1)}" + node_name = node.replace(f"/{namespace}/", "") + + screen_log = get_logfile( + node=node_name, for_new_screen=True, namespace=namespace + ) + ros_log = get_ros_logfile(node) + resultDelete = True + message = '' + if (os.path.exists(screen_log)): + try: + os.remove(screen_log) + except OSError as error: + resultDelete = False + message += f"Can not remove {screen_log}: {error}. " + if (os.path.exists(ros_log)): + try: + os.remove(ros_log) + except OSError as error: + resultDelete = False + message += f"Can not remove {ros_log}: {error}. " + log_path_item = LogPathClearResult( + node, + result=resultDelete, + message=message + ) + result.append(log_path_item) + return json.dumps(result, cls=SelfEncoder) + def ChangedFiles(self, request, context): result = fms.PathList() chnged_files = []