Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
3473f committed Mar 24, 2024
1 parent 350f09f commit 3b4272a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
27 changes: 20 additions & 7 deletions ros2autodoc/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from ros2pkg.api import get_executable_paths, get_package_names

from ros2autodoc.api.doc_parser import DocParser
from ros2autodoc.api.doc_writer import DocWriter
from ros2autodoc.api.doc_writer import DocWriter, TODO


def check_for_package(package_name):
Expand Down Expand Up @@ -92,11 +92,14 @@ def document_node(node, package_name, node_name, path, file_name="/README.md"):
def update_documentation(node, node_name, file_path):
"""Update the documentation for the given node."""
parser = DocParser(file_path)
writer = DocWriter(None, node_name)
if node_name not in parser.get_node_names():
print(f"Node {node_name} not found in document {file_path}")
return

# The writer is responsible for creating the Node object
# This is bad design and requires major re-write
writer = DocWriter(None, node_name)

param_names, params, description = _get_parameters(node, node_name)
if len(params) > 0:
writer.get_parameters(param_names, params, description)
Expand All @@ -121,11 +124,21 @@ def update_documentation(node, node_name, file_path):
if len(actions_servers) > 0:
writer.get_action_servers(actions_servers)

curr_node = writer.get_node()
for i, parsed_node in enumerate(parser.get_nodes()):
if parsed_node.name == curr_node.name:
# compare both of their content
continue
# Get both nodes we are working with
running_node = writer.get_node()
parsed_node = parser.get_node(running_node.name)

if running_node.parameters or parsed_node.parameters:
# Update the parsed node with parameters from the running nodes
for old_param in parsed_node.parameters:
for new_param in running_node.parameters:
if old_param['name'] == new_param['name']:
if old_param['type'] is not new_param['type']:
old_param['type'] = new_param['type']
if old_param['description'] is not new_param['description'] and new_param['description'] is not TODO:
old_param['description'] = new_param['description']




def _get_parameters(node, node_name):
Expand Down
6 changes: 6 additions & 0 deletions ros2autodoc/api/doc_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ def get_node_names(self):
for node in self.nodes:
node_names.append(node.name)
return node_names

def get_node(self, name):
for node in self.nodes:
if node.name == name:
return node
return False

def _dict_to_list(self, dictionary):
output_list = []
Expand Down

0 comments on commit 3b4272a

Please sign in to comment.