pydev
authorMichael Wagner <michael@wagnertech.de>
Tue, 17 Sep 2019 23:00:20 +0000 (01:00 +0200)
committerMichael Wagner <michael@wagnertech.de>
Tue, 17 Sep 2019 23:00:20 +0000 (01:00 +0200)
python/mDoc/mdoc.py [new file with mode: 0755]
python/mDoc/mdoc/__init__.py [new file with mode: 0644]
python/mDoc/mdoc/worker.py [new file with mode: 0644]
python/mDoc/mutil [new symlink]
python/mDoc/tpl/latex.tpl [new file with mode: 0644]

diff --git a/python/mDoc/mdoc.py b/python/mDoc/mdoc.py
new file mode 100755 (executable)
index 0000000..2386fec
--- /dev/null
@@ -0,0 +1,37 @@
+#!/usr/bin/python3
+'''
+Created on 02.08.2019
+
+@author: mdoc
+'''
+
+import sys
+from mdoc import worker
+from test import xxx
+from test.xxx import MyClass
+
+usage = 'mdoc <source> <target-format>'
+
+def command_dispatch(args):
+    
+    # check runtime parameters
+    if len(args) < 2:
+        raise RuntimeError("xets needs 2 arguments.")
+    
+    file = args[0]
+    format = args[1]
+    
+    return worker.convert(file, format)
+    
+
+# evaulate runtime parameters
+if __name__ == '__main__':
+    try:
+        ret = command_dispatch(sys.argv[1:])
+        if ret != 0:
+            print (usage) 
+        exit (ret)
+    except Exception as e:
+        print (e)
+        print (usage)
+        raise
\ No newline at end of file
diff --git a/python/mDoc/mdoc/__init__.py b/python/mDoc/mdoc/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/python/mDoc/mdoc/worker.py b/python/mDoc/mdoc/worker.py
new file mode 100644 (file)
index 0000000..b98ad57
--- /dev/null
@@ -0,0 +1,61 @@
+'''
+Created on 02.08.2019
+
+@author: mdoc
+'''
+
+from mutil.XmlExtractor import XmlExtractor
+from mutil import XmlExtractor as XMLE
+import re
+
+def outfirst(outfile, tpllayer, attrs, value):
+    if tpllayer["value"]:
+        ostr = tpllayer["value"]
+        if "$value" in ostr:
+            ostr = re.sub(r"\$value", value, ostr)
+        print (ostr, end="", file=outfile)
+
+def outlast(outfile, tpllayer, attrs, value):
+    if tpllayer["value"]:
+        print (file=outfile)
+
+def process_file_layer(source, outfile, globals, hierarc):
+
+
+    (ctl,elem, value, attrs) = source.extractElement(XMLE.EC_BEG)
+    while ctl != XMLE.EC_END:
+        item = None
+        nexthiera = {}
+        if elem in hierarc:
+            item = hierarc[elem]
+            nexthiera = hierarc[elem]["items"]
+        elif elem in globals:
+            item = globals[elem]
+        else:
+            print ("Warning: No mapping for item:" +elem)
+        if item:
+            outfirst(outfile, item, attrs, value)
+        process_file_layer(source, outfile, globals, nexthiera)
+        if item:
+            outlast(outfile, item, attrs, value)
+        (ctl,elem, value, attrs) = source.extractElement(ctl)
+        
+def convert (file, format):
+    
+    source = XmlExtractor()
+    source.openInput(file)
+
+    # read whole template
+    tple = XmlExtractor()
+    tpl = tple.readFile("tpl/"+format+".tpl")
+    globals = tpl["mdoc"]["items"]["global"]["items"]
+    hierarc = tpl["mdoc"]["items"]["hierarchical"]["items"]
+    
+    # open output file
+    ext = tpl["mdoc"]["attrs"]["extension"]
+    outname = re.sub(r"\.xml", "."+ext, file)
+    outfile = open(outname, "w")
+    #print ("hallo", file=outfile)
+    
+    process_file_layer(source, outfile, globals, hierarc)
+    
diff --git a/python/mDoc/mutil b/python/mDoc/mutil
new file mode 120000 (symlink)
index 0000000..774bbec
--- /dev/null
@@ -0,0 +1 @@
+../../../xets/python/xets/util/
\ No newline at end of file
diff --git a/python/mDoc/tpl/latex.tpl b/python/mDoc/tpl/latex.tpl
new file mode 100644 (file)
index 0000000..fbcbbbb
--- /dev/null
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mdoc format="latex" extension="tex">
+<global/>
+<hierarchical>
+<article>
+<test>testdata</test>
+<articleinfo>
+<![CDATA[
+\documentclass[12pt, a4paper, parskip=half]{scrartcl}
+\usepackage[utf8]{inputenc}% muss zum Editor passen -> http://texwelt.de/wissen/fragen/2656/
+\usepackage[T1]{fontenc}
+\usepackage[ngerman]{babel}
+\usepackage{wallpaper}
+\usepackage{wrapfig} % Für Textumlauf
+\usepackage{geometry}
+\geometry{a4paper,left=25mm,right=20mm, top=33mm, bottom=30mm}
+
+\renewcommand{\familydefault}{\sfdefault}
+
+\author{Michael J.M. Wagner}
+\date{\vspace{-6ex}}
+
+\CenterWallPaper{1}{wagner_tech_briefbogen_blau_fs1.pdf}
+
+\setcounter{secnumdepth}{0} % keine Kapitelnummerierung
+]]>
+<title>
+<![CDATA[\title{$value}]]>
+</title>
+</articleinfo>
+</article>
+</hierarchical>
+</mdoc>
+