]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blobdiff - rpp/blocks/scripts/doc_parse.py
doc: Allow underscores (and markdown syntax) in parameter documentation
[pes-rpp/rpp-simulink.git] / rpp / blocks / scripts / doc_parse.py
index 98b7533e79e8373b66926f82c29c35b3babe2516..1ccb38c57deac00181ab364d3516788aaaa257b2 100755 (executable)
@@ -1,11 +1,25 @@
 #!/usr/bin/env python3
 
+# Copyright (C) 2013-2015 Czech Technical University in Prague
+#
+# Authors:
+#     - Michal Sojka <sojkam1@fel.cvut.cz>
+#
+# This document contains proprietary information belonging to Czech
+# Technical University in Prague. Passing on and copying of this
+# document, and communication of its contents is not permitted
+# without prior written authorization.
+#
+# File : doc_parse.py
+# Abstract:
+
 import yaml
 import argparse
 import Rx
 import sys
 import subprocess
 import os
+import os.path
 from string import Template
 
 parser = argparse.ArgumentParser()
@@ -24,90 +38,57 @@ parser.add_argument('--maskpromptstring', help="output prompt strings for Simuli
                     action = 'store_true')
 parser.add_argument('--masktype', help="output mask type for Simulink mask",
                     action = 'store_true')
+parser.add_argument('--name', help="print block name",
+                    action = 'store_true')
 args = parser.parse_args()
 
 mydir = os.path.dirname(os.path.realpath(__file__))
 
-def print_markdown(args, text):
+def markdown_as(format, text):
     sys.stdout.flush()
-    if args.html:
-        format = 'html'
-    else:
-        format = 'markdown'
-    proc = subprocess.Popen(['pandoc', '-f', 'markdown', '-t', format], stdin = subprocess.PIPE)
+    proc = subprocess.Popen(['pandoc', '-f', 'markdown', '-t', format], stdin = subprocess.PIPE, stdout = subprocess.PIPE)
     proc.stdin.write(bytes(text, 'UTF-8'))
-    proc.communicate()
+    (stdout, stderr) = proc.communicate()
     proc.stdin.close()
     if proc.returncode:
         raise Exception("pandoc failed: %d" % proc.returncode)
+    return stdout.decode('utf-8').rstrip()
 
-def print_latex_desc(doc):
+def print_markdown_as(format, text):
+    print(markdown_as(format, text))
+
+def print_latex_desc(doc, filename):
     def iodef_str(iodef):
         if iodef is None: return "None"
         str='%d\n\\begin{enumerate}\n' % len(iodef)
         for io in iodef:
             str += Template('\\item {\\bf $name} $type').substitute(io)
             if 'range' in io:
-                str += '  %s' % io['range']
+                str += '  %s' % markdown_as('latex', io['range'])
+            if 'note' in io:
+                str += '  %s' % markdown_as('latex', io['note'])
             str += '\n'
         return str +'\end{enumerate}'
 
     print("\\newpage\n")
-    print("\\subsubsection{%s}\n" % doc['Name'])
+    print("\\subsection{%s}" % doc['Name'])
+    print("\\label{sec:block:%s}\n" % os.path.basename(filename))
     print("\\begin{description}\n")
     print("\\item[Inputs:]     %s\n" % iodef_str(doc['Inputs']))
     print("\\item[Outputs:]    %s\n" % iodef_str(doc['Outputs']))
     print("\\item[Parameters:] %s\n" % iodef_str(doc['Parameters']))
     print("\\end{description}\n")
 
-    print_markdown_as('latex', doc['Description'])
-
-    print("\n\\textbf{Status:}")
-    print("\\begin{multicols}{3}")
-    if doc['Status']['Tested']:
-        print("\\begin{compactitem}")
-        print("\\item \\textbf{Tested}:")
-        print(" \\begin{compactitem}")
-        print("\n".join(["\\item %s" % i.replace('_', '\\_') for i in doc['Status']['Tested']]))
-        print(" \\end{compactitem}")
-        print("\\end{compactitem}")
-    else:
-        print("\\ ")
-
-    print("\\vfill\\columnbreak")
-
-    if doc['Status']['Untested']:
-        print("\\begin{compactitem}")
-        print("\\item \\textbf{Untested}:")
-        print(" \\begin{compactitem}")
-        print("\n".join(["\\item %s" % i.replace('_', '\\_') for i in doc['Status']['Untested']]))
-        print(" \\end{compactitem}")
-        print("\\end{compactitem}")
-    else:
-        print("\\ ")
-
-    print("\\vfill\\columnbreak")
-
-    if doc['Status']['Not working']:
-        print("\\begin{compactitem}")
-        print("\\item \\textbf{Not working}:")
-        print(" \\begin{compactitem}")
-        print("\n".join(["\\item %s" % i.replace('_', '\\_') for i in doc['Status']['Not working']]))
-        print(" \\end{compactitem}")
-        print("\\end{compactitem}")
-    else:
-        print("\\ ")
-
-    print("\\end{multicols}\n")
+    print_markdown_as('latex', doc['Help'])
 
     if doc.get('RPP API functions used', None) is not None:
-        print("\\textbf{RPP API functions used:}")
+        print("\\paragraph{RPP API functions used:}")
         print("\\begin{compactitem}")
         print("\n".join(["\\item \\texttt{%s}" % i.replace('_', '\\_') for i in doc['RPP API functions used']]))
         print("\\end{compactitem}")
 
     if doc.get('Relevant demos', None) is not None:
-        print("\\textbf{Relevant demos:}")
+        print("\\paragraph{Relevant demos:}")
         print("\\begin{compactitem}")
         print("\n".join(["\\item %s" % i.replace('_', '\\_') for i in doc['Relevant demos']]))
         print("\\end{compactitem}")
@@ -135,25 +116,25 @@ def process_file(f):
         raise Exception("Validation error in %s: %s" % (f, e))
         #raise
 
+    fmt = 'html' if args.html else 'markdown'
+
     if args.printdesc:
-        print_markdown(args, doc['Description'])
+        print_markdown_as(fmt, doc['Description'])
     if args.printhelp:
-        print_markdown(args, doc['Help'])
+        print_markdown_as(fmt, doc['Help'])
     if args.latex:
-        print_latex_desc(doc)
+        print_latex_desc(doc, f)
     if args.latex_table:
         global last_category
         if last_category == doc['Category']: doc['Category']=''
         doc['Header'] = doc['Header'].replace('_', '\\_')
-        if   doc['Status']['Not working']: doc['ShortStatus'] = '$\\alpha$'
-        elif doc['Status']['Untested']:    doc['ShortStatus'] = '$\\beta$'
-        elif not doc['Status']['Tested']:  doc['ShortStatus'] = '$\\beta$'
-        else:                              doc['ShortStatus'] = 'Stable'
-        print(Template("$Category & $Name & $ShortStatus & $Mnemonic & \\texttt{$Header} \\\\").substitute(doc))
+        print(Template("$Category & $Name & $Status & $Mnemonic & \\texttt{$Header} \\\\").substitute(doc))
         if doc['Category']:
             last_category = doc['Category']
     if args.masktype:
         print('RPP {name}'.format(name=doc['Name']))
+    if args.name:
+        print(doc['Name'])
     if args.maskpromptstring and doc['Parameters'] != None:
         print('|'.join(['{name}{range}{colon}'.format(name=par['name'],
                                                       range=(' '+par['range'] if ('range' in par and (par['type'] in ['double'] or