10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-12-25 05:43:46 +01:00

Replace main cli options by LaTeX options

The tex options are placed in the dfbOptions LaTex environment
This commit is contained in:
Mickaël Véril 2020-06-18 15:02:12 +02:00
parent 1f60f96376
commit 8efa580659

View File

@ -6,18 +6,34 @@ import numpy as np
from pathlib import Path
from lib import LaTeX
from lib.Format import Format
from TexSoup import TexSoup
from TexSoup import TexSoup,TexCmd
from lib.data import dataFileBase,DataType
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--file', type=argparse.FileType('r'))
parser.add_argument('--defaultType', type=str, choices=[t.name for t in list(DataType)])
parser.add_argument('--format',type=str, choices=[t.name for t in list(Format)],default=Format.LINE.name)
parser.add_argument('--debug', action='store_true', help='Debug mode')
parser.add_argument('--suffix',type=str,default=None)
args = parser.parse_args()
lines=args.file.readlines()
soup=TexSoup(lines)
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
commands=[LaTeX.newCommand(cmd) for cmd in soup.find_all("newcommand")]
dat=LaTeX.tabularToData(soup.tabular,commands)
scriptpath=Path(sys.argv[0]).resolve()
@ -26,6 +42,6 @@ if args.debug:
datapath=datapath/"test"
if not datapath.exists():
datapath.mkdir()
datalst=dataFileBase.readFromTable(dat,format=Format[args.format],default=DataType[args.defaultType],commands=commands)
datalst=dataFileBase.readFromTable(dat,format=dfb_Opt["format"],default=dfb_Opt["defaultType"],commands=commands)
for data in datalst:
data.toFile(datapath,args.suffix)
data.toFile(datapath,dfb_Opt["suffix"])