]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#777,!464] api2doc.py updated to handle new syntax, Makefile.am updated
authorTomek Mrugalski <tomasz@isc.org>
Tue, 6 Aug 2019 16:19:15 +0000 (18:19 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Wed, 7 Aug 2019 10:58:10 +0000 (12:58 +0200)
doc/sphinx/Makefile.am
doc/sphinx/api2doc.py

index 2d838f6c2e5c50ea3d5365f39a9ad761f391fd5c..3b3ff5153ae0900aae44ff5c94fcf6dcabb82d84 100644 (file)
@@ -52,7 +52,7 @@ rst_arm_sources+=arm/netconf.rst
 rst_arm_sources+=arm/quickstart.rst
 rst_arm_sources+=arm/shell.rst
 rst_arm_sources+=arm/stats.rst
-#rst_arm_sources+=$(srcdir)/api.rst TODO: disabled for now
+rst_arm_sources+=$(srcdir)/api.rst
 rst_arm_sources+=$(srcdir)/kea-messages.rst
 
 main_sources=$(rst_arm_sources) conf.py $(static_sources)
@@ -72,8 +72,7 @@ rst_man_sources+=man/perfdhcp.8.rst
 man_sources=$(rst_man_sources) conf.py
 man8s=$(foreach rst,$(rst_man_sources), $(sphinxbuilddir)/$(basename $(rst)))
 
-EXTRA_DIST += $(main_sources) $(man_sources) mes2doc.py  # api2doc.py
-
+EXTRA_DIST += $(main_sources) $(man_sources) mes2doc.py api2doc.py
 
 # list of messages files that are used to generate kea-messages.rst and then kea-messages.pdf
 mes_files=
@@ -228,8 +227,7 @@ api_files+=$(srcdir)/api/subnet6-list.json
 api_files+=$(srcdir)/api/subnet6-update.json
 api_files+=$(srcdir)/api/version-get.json
 
-#EXTRA_DIST += $(api_files)
-
+EXTRA_DIST += $(api_files)
 
 if HAVE_PDFLATEX
 all: html mans pdf
@@ -241,8 +239,8 @@ $(srcdir)/kea-messages.rst: $(mes_files) mes2doc.py
        $(PYTHON) $(srcdir)/mes2doc.py -o $@ $(mes_files)
 
 
-#$(srcdir)/api.rst: $(api_files) api2doc.py
-#      $(PYTHON) $(srcdir)/api2doc.py -o $@ $(api_files)
+$(srcdir)/api.rst: $(api_files) api2doc.py
+       $(PYTHON) $(srcdir)/api2doc.py -o $@ $(api_files)
 
 
 PDFLATEX_AND_OPTS=$(PDFLATEX) -interaction nonstopmode
@@ -265,6 +263,9 @@ pdf: $(main_sources)
 html: $(main_sources)
        $(SPHINXBUILD) -M html $(srcdir) $(sphinxbuilddir) $(sphinxopts)
 
+singlehtml: $(main_sources)
+       $(SPHINXBUILD) -M singlehtml $(srcdir) $(sphinxbuilddir) $(sphinxopts)
+
 $(man8s): mans
 
 mans: $(man_sources)
index 60ed6e951c7df297227688c6dabe314062472941..3c5f17040c1f20fbdd06b825a683c92aa913f8d8 100755 (executable)
@@ -6,7 +6,9 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http:#mozilla.org/MPL/2.0/.
 
-# Produce API Manual
+# Produce API Reference
+# - reads *.json files (each file describes a single command)
+# - produces .rst file suitable for Sphinx as output
 
 import os
 import json
@@ -27,7 +29,12 @@ def read_input_files(files):
     apis = {}
     for f in files:
         name = os.path.basename(f)[:-5]
+        # Skip special names starting with _ (such as _template.json)
+        if name[:1] == '_':
+            print("Skipping %s (starts with underscore)" % f)
+            continue
         with open(f) as fp:
+            print("Processing %s" % f)
             # use OrderedDict to preserve order of fields in cmd-syntax
             try:
                 descr = json.load(fp, object_pairs_hook=collections.OrderedDict)
@@ -87,7 +94,9 @@ API Reference
         rst += '-' * len(name) + '\n\n'
 
         # command overview
-        rst += '%s\n\n' % func['brief']
+        for brief_line in func['brief']:
+            rst += '%s\n' % brief_line
+        rst += '\n'
 
         # command can be issued to the following daemons
         rst += 'Supported by: '
@@ -104,7 +113,7 @@ API Reference
 
         # command syntax
         rst += 'Command syntax:\n\n'
-        rst += '.. code-block:: json\n\n'
+        rst += '.. code-block:: \n\n'
         if 'cmd-syntax' in func:
             cmd_syntaxes = [func['cmd-syntax']]
             if isinstance(cmd_syntaxes, dict):
@@ -114,9 +123,9 @@ API Reference
                     rst += cmd_syntax['comment']
                     rst += '\n\n'
                     del cmd_syntax['comment']
-                txt = json.dumps(cmd_syntax, indent=4, separators=(',', ': '))
-                lines = [ '    %s' % l for l in txt.splitlines()]
-                rst += '\n'.join(lines)
+
+                for line in cmd_syntax:
+                    rst += '    %s\n' % line
         else:
             rst += '   {\n'
             rst += '       "command": \"%s\"\n' % name
@@ -124,20 +133,25 @@ API Reference
         rst += '\n\n'
 
         if 'cmd-comment' in func:
-            rst += func['cmd-comment']
-            rst += '\n\n'
+            for l in func['cmd-comment']:
+                rst += "%s\n" % l
+            rst += '\n'
 
         # response syntax
         rst += 'Response syntax:\n\n'
-        rst += '.. code-block:: json\n\n'
+        rst += '.. code-block:: \n\n'
         if 'resp-syntax' in func:
             resp_syntaxes = [func['resp-syntax']]
             if isinstance(resp_syntaxes, dict):
                 resp_syntaxes = [resp_syntax]
             for resp_syntax in resp_syntaxes:
-                txt = json.dumps(resp_syntax, indent=4, separators=(',', ': '))
-                lines = [ '    %s' % l for l in txt.splitlines()]
-                rst += '\n'.join(lines)
+
+                for line in resp_syntax:
+                    rst += '    %s\n' % line
+
+                #txt = json.dumps(resp_syntax, indent=4, separators=(',', ': '))
+                #lines = [ '    %s' % l for l in txt.splitlines()]
+                #rst += '\n'.join(lines)
         else:
             rst += '   {\n'
             rst += '       "result": "<integer>",\n'
@@ -146,7 +160,8 @@ API Reference
         rst += '\n\n'
 
         if 'resp-comment' in func:
-            rst += func['resp-comment']
+            for resp_comment_line in func['resp-comment']:
+                rst += "%s\n" % resp_comment_line
             rst += '\n\n'
         else:
             rst += 'Result is an integer representation of the status. Currently supported statuses are:\n\n'