2019-11-12 20:09:18 +01:00
|
|
|
#!/usr/bin/env python3
|
2019-11-12 14:36:23 +01:00
|
|
|
import sys
|
|
|
|
import re
|
2019-11-19 13:52:53 +01:00
|
|
|
from enum import IntEnum,auto,unique
|
2019-11-12 14:36:23 +01:00
|
|
|
import numpy as np
|
|
|
|
from pathlib import Path
|
|
|
|
from lib import LaTeX
|
2019-12-03 15:24:29 +01:00
|
|
|
from lib.Format import Format
|
2020-06-18 15:02:12 +02:00
|
|
|
from TexSoup import TexSoup,TexCmd
|
2020-06-18 12:27:24 +02:00
|
|
|
from lib.data import dataFileBase,DataType
|
2019-11-12 14:36:23 +01:00
|
|
|
import argparse
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('--file', type=argparse.FileType('r'))
|
2020-03-28 13:21:47 +01:00
|
|
|
parser.add_argument('--debug', action='store_true', help='Debug mode')
|
2019-11-12 14:36:23 +01:00
|
|
|
args = parser.parse_args()
|
|
|
|
lines=args.file.readlines()
|
|
|
|
soup=TexSoup(lines)
|
2020-06-18 15:02:12 +02:00
|
|
|
opt=soup.dfbOptions
|
|
|
|
dfb_Opt= {"defaultType":DataType.ABS,"format":Format.LINE,"suffix":None}
|
|
|
|
dfbDefaultTypeNode=opt.defaultType
|
|
|
|
if dfbDefaultTypeNode!=None:
|
|
|
|
dfbDefaultType=dfbDefaultTypeNode.expr
|
|
|
|
if type(dfbDefaultType) is TexCmd:
|
|
|
|
dfb_Opt["defaultType"]=DataType[dfbDefaultType.args[0].value.upper()]
|
|
|
|
|
|
|
|
dfbFormatNode=opt.format
|
|
|
|
if dfbFormatNode!=None:
|
|
|
|
dfbFormat=dfbFormatNode.expr
|
|
|
|
if type(dfbFormat) is TexCmd:
|
|
|
|
dfb_Opt["format"]=Format[dfbFormat.args[0].value.upper()]
|
|
|
|
|
|
|
|
dfbSuffixNode=opt.suffix
|
|
|
|
if dfbSuffixNode!=None:
|
|
|
|
dfbSuffix=dfbSuffixNode.expr
|
|
|
|
if type(dfbSuffix) is TexCmd:
|
|
|
|
dfb_Opt["suffix"]=dfbSuffix.args[0].value
|
2019-11-12 14:36:23 +01:00
|
|
|
commands=[LaTeX.newCommand(cmd) for cmd in soup.find_all("newcommand")]
|
|
|
|
dat=LaTeX.tabularToData(soup.tabular,commands)
|
|
|
|
scriptpath=Path(sys.argv[0]).resolve()
|
|
|
|
datapath=scriptpath.parents[1]/"static"/"data"
|
2020-02-19 11:47:58 +01:00
|
|
|
if args.debug:
|
2019-11-12 14:36:23 +01:00
|
|
|
datapath=datapath/"test"
|
|
|
|
if not datapath.exists():
|
|
|
|
datapath.mkdir()
|
2020-06-18 15:02:12 +02:00
|
|
|
datalst=dataFileBase.readFromTable(dat,format=dfb_Opt["format"],default=dfb_Opt["defaultType"],commands=commands)
|
2019-11-19 13:52:53 +01:00
|
|
|
for data in datalst:
|
2020-06-18 15:02:12 +02:00
|
|
|
data.toFile(datapath,dfb_Opt["suffix"])
|