10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-11-04 21:24:00 +01:00
QUESTDB_website/tools/datafileBuilder.py

32 lines
1.2 KiB
Python
Raw Normal View History

2019-11-12 20:09:18 +01:00
#!/usr/bin/env python3
import sys
import re
from enum import IntEnum,auto,unique
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
from TexSoup import TexSoup
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)])
2019-12-03 15:24:29 +01:00
parser.add_argument('--format',type=str, choices=[t.name for t in list(Format)],default=Format.LINE.name)
2020-03-28 13:21:47 +01:00
parser.add_argument('--debug', action='store_true', help='Debug mode')
parser.add_argument('--prefix',type=str,default=None)
args = parser.parse_args()
print(args)
lines=args.file.readlines()
soup=TexSoup(lines)
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"
if args.debug:
datapath=datapath/"test"
if not datapath.exists():
datapath.mkdir()
2019-12-12 15:20:56 +01:00
datalst=dataFileBase.readFromTable(dat,format=Format[args.format],default=dataType[args.defaultType],commands=commands)
for data in datalst:
2020-03-28 13:21:47 +01:00
data.toFile(datapath,args.prefix)