[elbe-devel] [PATCH 2/8] Catch exception in mako template for xsdtoasciidoc
Torben Hohn
torben.hohn at linutronix.de
Fri Aug 9 11:24:51 CEST 2019
On Fri, Aug 09, 2019 at 10:47:48AM +0200, Torben Hohn wrote:
> From: Olivier Dion <dion at linutronix.de>
>
> If a node doesn't have documentation, an exception is thrown. This
> fix catch the exception and return a "FIX - I have no documentation"
> documentation text.
>
> Signed-off-by: Olivier Dion <dion at linutronix.de>
Reviewed-by: Torben Hohn <torben.hohn at linutronix.de>
> ---
> elbepack/xsdtoasciidoc.mako | 29 ++++++++++++++++-------------
> 1 file changed, 16 insertions(+), 13 deletions(-)
>
> diff --git a/elbepack/xsdtoasciidoc.mako b/elbepack/xsdtoasciidoc.mako
> index 1d9054f9d..351f85382 100644
> --- a/elbepack/xsdtoasciidoc.mako
> +++ b/elbepack/xsdtoasciidoc.mako
> @@ -15,11 +15,16 @@ RSTR = "{http://www.w3.org/2001/XMLSchema}restriction"
> MAXI = "{http://www.w3.org/2001/XMLSchema}maxInclusive"
> MINI = "{http://www.w3.org/2001/XMLSchema}minInclusive"
>
> -def docindent( s, indent=0 ):
> - lines = s.splitlines()
> - lines = [l.strip() for l in lines]
> - lines = map(lambda x: indent*" "+x, lines)
> - return str('').join(lines).strip()
> +def docindent(node, indent=0):
> + try:
> + s = node.text(e.text(".//%s" % DOC))
> + except:
> + return "FIXME - I have no documentation"
> + else:
> + lines = s.splitlines()
> + lines = [l.strip() for l in lines]
> + lines = map(lambda x: indent*" "+x, lines)
> + return str('').join(lines).strip()
>
> def genlink(typ):
> if typ.startswith("rfs:"):
> @@ -36,7 +41,7 @@ def stripscheme(s):
>
> def cardinality(e):
> min = None
> - max = None
> + max = None
>
> retval = ""
>
> @@ -60,9 +65,7 @@ def element_example(n):
> return "<%s> %s </%s>" % (name, _type, name)
>
> def doc(e):
> - if e.has(".//%s" % DOC):
> - return docindent(e.text(".//%s" % DOC), 2)
> - return ""
> + return docindent(e, 2)
>
> def element_doc(e):
> name = e.et.attrib["name"]
> @@ -80,14 +83,14 @@ def attr_doc(a):
> <%def name="do_element(n)">
> == ${n.et.attrib["name"]} type: '${n.et.attrib["type"]}' ==
>
> -${docindent(n.text(DOC))}
> +${docindent(n)}
> </%def>\
> ##
> <%def name="do_simple(n)">
> [[${n.et.attrib["name"]}]]
> == SIMPLE TYPE: ${n.et.attrib["name"]} ==
>
> -${docindent(n.text(DOC))}
> +${docindent(n)}
>
> %if n.has(RSTR):
> === Base Type ===
> @@ -109,7 +112,7 @@ ${docindent(n.text(DOC))}
> [[${n.et.attrib["name"]}]]
> == GROUP : ${n.et.attrib["name"]} ==
>
> -${docindent(n.text(DOC))}
> +${docindent(n)}
>
>
> % for e in n.all(".//%s" % ELEM):
> @@ -134,7 +137,7 @@ ${do_group(n)}
> [[${n.et.attrib["name"]}]]
> == TYPE: ${n.et.attrib["name"]} ==
>
> -${docindent(n.text(DOC))}
> +${docindent(n)}
>
> === Example ===
> [xml]
> --
> 2.11.0
>
>
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel
--
Torben Hohn
Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen
Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99
Hinweise zum Datenschutz finden Sie hier (Informations on data privacy
can be found here): https://linutronix.de/kontakt/Datenschutz.php
Linutronix GmbH | Firmensitz (Registered Office): Uhldingen-Mühlhofen |
Registergericht (Registration Court): Amtsgericht Freiburg i.Br., HRB700
806 | Geschäftsführer (Managing Directors): Heinz Egger, Thomas Gleixner
More information about the elbe-devel
mailing list