px_process_module_doc: separate page into one page per category

This commit is contained in:
Beat Küng 2017-05-05 11:50:57 +02:00
parent 05c3b711f3
commit 7a4f557a7a
2 changed files with 22 additions and 9 deletions

View File

@ -5,26 +5,34 @@ import os
class MarkdownTablesOutput(): class MarkdownTablesOutput():
def __init__(self, module_groups): def __init__(self, module_groups):
self._outputs = {}
result = """ result = """
# Modules & Commands Reference # Modules & Commands Reference
Documentation of PX4 modules, drivers and commands. It describes the provided The following pages document the PX4 modules, drivers and commands. They
functionality, high-level implementation overview and how to use the describe the provided functionality, high-level implementation overview and how
command-line interface. to use the command-line interface.
> **Note** **This list is auto-generated from the source code** and contains the > **Note** **This is auto-generated from the source code** and contains the
> most recent modules documentation. > most recent modules documentation.
This is not a complete list and NuttX provides some additional commands It is not a complete list and NuttX provides some additional commands
as well (such as `free`). Use `help` on the console to get a list of all as well (such as `free`). Use `help` on the console to get a list of all
available commands, and in most cases `command help` will print the usage. available commands, and in most cases `command help` will print the usage.
Since this is generated from source, errors must be reported/fixed Since this is generated from source, errors must be reported/fixed
in the [Firmware](https://github.com/PX4/Firmware) repository. in the [Firmware](https://github.com/PX4/Firmware) repository.
## Categories
""" """
for category in sorted(module_groups):
result += "- [%s](modules_%s.md)\n" % (category.capitalize(), category)
self._outputs['main'] = result
for category in sorted(module_groups): for category in sorted(module_groups):
result += "# Category: %s\n" % category.capitalize() result = "# Modules Reference: %s\n" % category.capitalize()
module_list = module_groups[category] module_list = module_groups[category]
for module in module_list: for module in module_list:
result += "## %s\n" % module.name() result += "## %s\n" % module.name()
@ -36,8 +44,10 @@ in the [Firmware](https://github.com/PX4/Firmware) repository.
if len(usage_string) > 0: if len(usage_string) > 0:
result += "### Usage\n```\n%s\n```\n" % usage_string result += "### Usage\n```\n%s\n```\n" % usage_string
self.output = result self._outputs[category] = result
def Save(self, dirname): def Save(self, dirname):
with codecs.open(os.path.join(dirname, 'modules.md'), 'w', 'utf-8') as f: for output_name in self._outputs:
f.write(self.output) output = self._outputs[output_name]
with codecs.open(os.path.join(dirname, 'modules_'+output_name+'.md'), 'w', 'utf-8') as f:
f.write(output)

View File

@ -93,6 +93,9 @@ def main():
# Output to Markdown/HTML tables # Output to Markdown/HTML tables
if args.markdown: if args.markdown:
if (args.verbose): print("Creating markdown output to directory " + str(args.markdown))
if not os.path.exists(args.markdown):
os.makedirs(args.markdown)
out = markdownout.MarkdownTablesOutput(module_groups) out = markdownout.MarkdownTablesOutput(module_groups)
out.Save(args.markdown) out.Save(args.markdown)