]> wagnertech.de Git - mDoc.git/blob - python/mDoc/mdoc_extract.py
pydev-s6git
[mDoc.git] / python / mDoc / mdoc_extract.py
1 #!/usr/bin/python3
2 '''
3 Created on 26.03.2021
4
5 @author: antix19
6 '''
7 import sys
8 from mdoc import extractor
9 import re
10
11 usage = 'mdoc-extract <source> <class> [target]'
12
13 def command_dispatch(args):
14     
15     # check runtime parameters
16     if len(args) < 2:
17         raise RuntimeError("mdoc-extract needs 2/3 arguments.")
18     
19     file = args[0]
20     classs = args[1]
21     if len(args) == 3:
22         target = args[2]
23     else:
24         target = re.sub(r'\..*', '.tex', file)
25     
26     return extractor.extract(file, classs, target)
27     
28
29 # evaulate runtime parameters
30 if __name__ == '__main__':
31     try:
32         ret = command_dispatch(sys.argv[1:])
33         if ret != 0:
34             print ("Operation returned: "+str(ret)) 
35         exit (ret)
36     except Exception as e:
37         print (e)
38         print (usage)
39         raise