2021-07-28 17:05:26 -03:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
"""
|
|
|
|
Generate docs from .msg files
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import argparse
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
def get_msgs_list(msgdir):
|
|
|
|
"""
|
|
|
|
Makes list of msg files in the given directory
|
|
|
|
"""
|
|
|
|
return [fn for fn in os.listdir(msgdir) if fn.endswith(".msg")]
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser(description='Generate docs from .msg files')
|
|
|
|
parser.add_argument('-d', dest='dir', help='output directory', required=True)
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
output_dir = args.dir
|
|
|
|
if not os.path.isdir(output_dir):
|
|
|
|
os.mkdir(output_dir)
|
|
|
|
|
2023-02-22 02:38:12 -04:00
|
|
|
msg_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),"../../msg")
|
2021-07-28 17:05:26 -03:00
|
|
|
msg_files = get_msgs_list(msg_path)
|
2021-07-28 23:18:57 -03:00
|
|
|
msg_files.sort()
|
2021-10-01 14:06:15 -03:00
|
|
|
|
2021-07-28 23:18:57 -03:00
|
|
|
filelist_in_markdown=''
|
2021-10-01 14:06:15 -03:00
|
|
|
|
2021-07-28 17:05:26 -03:00
|
|
|
for msg_file in msg_files:
|
|
|
|
msg_name = os.path.splitext(msg_file)[0]
|
|
|
|
output_file = os.path.join(output_dir, msg_name+'.md')
|
|
|
|
msg_filename = os.path.join(msg_path, msg_file)
|
|
|
|
print("{:} -> {:}".format(msg_filename, output_file))
|
2021-10-01 14:06:15 -03:00
|
|
|
|
2021-07-28 23:18:57 -03:00
|
|
|
#Format msg url
|
2022-07-31 22:39:39 -03:00
|
|
|
msg_url="[source file](https://github.com/PX4/PX4-Autopilot/blob/main/msg/%s)" % msg_file
|
2021-10-01 14:06:15 -03:00
|
|
|
|
2021-07-28 23:18:57 -03:00
|
|
|
msg_description = ""
|
2021-08-15 20:41:51 -03:00
|
|
|
summary_description = ""
|
|
|
|
|
2021-07-28 23:18:57 -03:00
|
|
|
#Get msg description (first non-empty comment line from top of msg)
|
|
|
|
with open(msg_filename, 'r') as lineparser:
|
2021-10-01 14:06:15 -03:00
|
|
|
line = lineparser.readline()
|
2021-08-15 20:41:51 -03:00
|
|
|
while line.startswith('#') or (line.strip() == ''):
|
|
|
|
print('DEBUG: line: %s' % line)
|
|
|
|
line=line[1:].strip()+'\n'
|
|
|
|
stripped_line=line.strip()
|
|
|
|
if msg_description and not summary_description and stripped_line=='':
|
|
|
|
summary_description = msg_description.strip()
|
2021-07-28 23:18:57 -03:00
|
|
|
|
2021-08-15 20:41:51 -03:00
|
|
|
msg_description+=line
|
|
|
|
line = lineparser.readline()
|
|
|
|
msg_description=msg_description.strip()
|
|
|
|
if not summary_description and msg_description:
|
|
|
|
summary_description = msg_description
|
|
|
|
print('msg_description: Z%sZ' % msg_description)
|
|
|
|
print('summary_description: Z%sZ' % summary_description)
|
|
|
|
summary_description
|
2021-07-28 23:18:57 -03:00
|
|
|
msg_contents = ""
|
|
|
|
#Get msg contents (read the file)
|
|
|
|
with open(msg_filename, 'r') as source_file:
|
|
|
|
msg_contents = source_file.read()
|
2021-10-01 14:06:15 -03:00
|
|
|
|
2022-10-19 20:36:47 -03:00
|
|
|
#Format markdown using msg name, comment, url, contents.
|
2021-07-28 23:18:57 -03:00
|
|
|
markdown_output="""# %s (UORB message)
|
2021-10-01 14:06:15 -03:00
|
|
|
|
2021-07-28 23:18:57 -03:00
|
|
|
%s
|
|
|
|
|
|
|
|
%s
|
|
|
|
|
|
|
|
```c
|
|
|
|
%s
|
|
|
|
```
|
|
|
|
""" % (msg_name, msg_description, msg_url, msg_contents)
|
|
|
|
|
|
|
|
with open(output_file, 'w') as content_file:
|
|
|
|
content_file.write(markdown_output)
|
2021-10-01 14:06:15 -03:00
|
|
|
|
2021-07-28 23:18:57 -03:00
|
|
|
readme_markdown_file_link='- [%s](%s.md)' % (msg_name,msg_name)
|
2021-08-15 20:41:51 -03:00
|
|
|
if summary_description:
|
|
|
|
readme_markdown_file_link+=" — %s" % summary_description
|
2021-07-28 23:18:57 -03:00
|
|
|
filelist_in_markdown+=readme_markdown_file_link+"\n"
|
2021-10-01 14:06:15 -03:00
|
|
|
|
2021-07-28 23:18:57 -03:00
|
|
|
# Write out the README.md file
|
2021-08-15 19:28:59 -03:00
|
|
|
readme_text="""# uORB Message Reference
|
2021-07-28 23:18:57 -03:00
|
|
|
|
|
|
|
:::note
|
2022-10-19 20:36:47 -03:00
|
|
|
This list is [auto-generated](https://github.com/PX4/PX4-Autopilot/blob/main/Tools/msg/generate_msg_docs.py) from the source code.
|
2021-07-28 23:18:57 -03:00
|
|
|
:::
|
2021-10-01 14:06:15 -03:00
|
|
|
|
2021-07-28 23:18:57 -03:00
|
|
|
This topic lists the UORB messages available in PX4 (some of which may be may be shared by the [PX4-ROS 2 Bridge](../ros/ros2_comm.md)).
|
|
|
|
Graphs showing how these are used [can be found here](../middleware/uorb_graph.md).
|
2021-10-01 14:06:15 -03:00
|
|
|
|
2021-07-28 23:18:57 -03:00
|
|
|
%s
|
|
|
|
""" % (filelist_in_markdown)
|
|
|
|
readme_file = os.path.join(output_dir, 'README.md')
|
|
|
|
with open(readme_file, 'w') as content_file:
|
2021-10-01 14:06:15 -03:00
|
|
|
content_file.write(readme_text)
|