10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-11-03 20:53:59 +01:00
QUESTDB_website/tools/datafileBuilder.py

42 lines
1.4 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
2020-07-03 14:51:12 +02:00
from lib import LaTeX,formats,dfbOptions
from lib.formats import getFormatHandlers
2020-06-26 14:36:35 +02:00
from TexSoup import TexSoup,TexNode,TexCmd,TexEnv
2020-06-20 18:30:18 +02:00
from lib.data import dataFileBase,DataType,state
from collections import defaultdict
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--file', type=argparse.FileType('r'))
2020-07-03 14:51:12 +02:00
parser.add_argument("--list","-l",action="store_true", help='List all available format')
2020-03-28 13:21:47 +01:00
parser.add_argument('--debug', action='store_true', help='Debug mode')
args = parser.parse_args()
2020-07-03 14:51:12 +02:00
if args.list:
print("The list of avalable formats are:")
for formatName,_ in getFormatHandlers():
print(formatName)
elif args.file!=None:
2020-07-03 14:51:12 +02:00
lines=args.file.readlines()
soup=TexSoup(lines)
opt=soup.dfbOptions
if type(opt) is TexNode and type(opt.expr) is TexEnv:
texOps=dfbOptions.readFromEnv(opt)
else:
texOps=dfbOptions()
commands=[LaTeX.newCommand(cmd) for cmd in soup.find_all("newcommand")]
dat=LaTeX.tabularToData(soup.tabular,commands,texOps.excludeColumns)
2020-07-03 14:51:12 +02:00
scriptpath=Path(sys.argv[0]).resolve()
datapath=scriptpath.parents[1]/"static"/"data"
if args.debug:
datapath=datapath/"test"
if not datapath.exists():
datapath.mkdir()
datalst=dataFileBase.readFromTable(dat,texOps,commands=commands)
for data in datalst:
data.toFile(datapath,texOps.suffix)
else:
parser.print_help()