From 73539fefaba455c976c38489226ff4eeac688bab Mon Sep 17 00:00:00 2001 From: Michael Wagner Date: Fri, 26 Mar 2021 19:31:44 +0100 Subject: [PATCH] antix19 --- doc/README | 6 +++- python/mDoc/mdoc/extractor.py | 65 +++++++++++++++++++++++++++++++++++ python/mDoc/mdoc_extract.py | 36 +++++++++++++++++++ 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 python/mDoc/mdoc/extractor.py create mode 100755 python/mDoc/mdoc_extract.py diff --git a/doc/README b/doc/README index fb03237..a1a42dc 100644 --- a/doc/README +++ b/doc/README @@ -27,4 +27,8 @@ Dabei gelten folgende Regeln: x Input: Sie können direkt auf die Variablen value (der Wert des tags) und source (das XML- Dokument) zugreifen. x Output: Der Wert der Variablen out wird in die Zieldatei kopiert - +- mDoc-spezifische Tags (Docbook-Erweiterung) + x : Einzelne Zeilen innerhalb eines Paragraphen + x : Definition von Testbausteinen, wenn im Paragraphen auch Hervorhebungs-Tags (wie + ) vorkommen. + diff --git a/python/mDoc/mdoc/extractor.py b/python/mDoc/mdoc/extractor.py new file mode 100644 index 0000000..1b9b7be --- /dev/null +++ b/python/mDoc/mdoc/extractor.py @@ -0,0 +1,65 @@ +''' +Created on 26.03.2021 + +@author: antix19 +''' +from mutil.XmlExtractor import XmlExtractor +from mutil import XmlExtractor as XMLE +from pickle import NONE, FALSE, TRUE + +def eval_class(classs, item): + item_hira = item.split(".") + ilen = len(item_hira) + class_hira = classs.split(".") + if len(class_hira) < len(item_hira): + return False,ilen + for i in range(len(item_hira)): + if item_hira[i] != class_hira[i]: + return False,ilen + return True,ilen + +def is_for_print(classs, attrs): + include = False + exclude = False + ilen = 0 + elen = 0 + if "include" in attrs: + include,ilen = eval_class(classs, attrs["include"]) + if "exclude" in attrs: + exclude,elen = eval_class(classs, attrs["exclude"]) + if ilen > 0 and elen == 0: + return include + elif elen > 0 and ilen == 0: + return not exclude + elif ilen > 0 and elen > 0: + if ilen > elen: + if include: + return True + else: + return not exclude + elif elen > ilen: + if exclude: + return False + else: + return include + return True + + +def extract(file, classs, target): + source = XmlExtractor() + source.openInput(file) + + # open output file + out_file = open(target, "w") + + source.requireChild("document") + (ctl,elem, value, attrs) = source.extractElement(XMLE.EC_BEG) + while ctl != XMLE.EC_END: + if elem != "text": + raise EnvironmentError(" node expected") + if is_for_print(classs, attrs): + out_file.write(value+"\n") + (ctl,elem, value, attrs) = source.extractElement(ctl) + return 0 + + \ No newline at end of file diff --git a/python/mDoc/mdoc_extract.py b/python/mDoc/mdoc_extract.py new file mode 100755 index 0000000..6226d79 --- /dev/null +++ b/python/mDoc/mdoc_extract.py @@ -0,0 +1,36 @@ +#!/usr/bin/python3 +''' +Created on 26.03.2021 + +@author: antix19 +''' +import sys +from mdoc import extractor +import re + +usage = 'mdoc-extract ' + +def command_dispatch(args): + + # check runtime parameters + if len(args) < 2: + raise RuntimeError("mdoc-extract needs 2 arguments.") + + file = args[0] + classs = args[1] + target = re.sub(r'\..*', '.tex', file) + + return extractor.extract(file, classs, target) + + +# evaulate runtime parameters +if __name__ == '__main__': + try: + ret = command_dispatch(sys.argv[1:]) + if ret != 0: + print ("Operation returned: "+str(ret)) + exit (ret) + except Exception as e: + print (e) + print (usage) + raise \ No newline at end of file -- 2.20.1