-# Copyright (C) 2013-2014 Czech Technical University in Prague
+#!/usr/bin/env python3
+
+# Copyright (C) 2013-2015 Czech Technical University in Prague
#
# Authors:
# - Michal Sojka <sojkam1@fel.cvut.cz>
# File : doc_parse.py
# Abstract:
-#!/usr/bin/env python3
-
import yaml
import argparse
import Rx
import sys
import subprocess
import os
+import os.path
from string import Template
parser = argparse.ArgumentParser()
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_as(format, text):
- proc = subprocess.Popen(['pandoc', '-f', 'markdown', '-t', format], stdin = subprocess.PIPE)
+def markdown_as(format, text):
+ sys.stdout.flush()
+ 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_markdown_as(format, text):
+ print(markdown_as(format, text))
-def print_latex_desc(doc):
+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_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}")
if args.printhelp:
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']=''
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