Skip to content

Commit

Permalink
added crossbar interface to clear node log paths
Browse files Browse the repository at this point in the history
  • Loading branch information
atiderko committed Jan 8, 2024
1 parent db5c936 commit 2be6828
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions fkie_node_manager_daemon/fkie_node_manager_daemon/file_servicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down

0 comments on commit 2be6828

Please sign in to comment.