Feat: rexrite produce_and_compile
This commit is contained in:
parent
d66e1a0887
commit
97468b9602
@ -169,81 +169,68 @@ def texcompile(filename):
|
|||||||
def produce_and_compile(options):
|
def produce_and_compile(options):
|
||||||
""" Produce and compile subjects
|
""" Produce and compile subjects
|
||||||
"""
|
"""
|
||||||
working_dir = get_working_dir(options)
|
logger.debug(f"CI parser gets {options}")
|
||||||
|
|
||||||
if options["only_corr"]:
|
|
||||||
options["corr"] = True
|
|
||||||
tex_files = working_dir.glop("[0-9]*_*.tex")
|
|
||||||
else:
|
|
||||||
template = Path(options["template"]).name
|
template = Path(options["template"]).name
|
||||||
logger.debug(f"Template will be {template}")
|
directory = Path(options["template"]).parent
|
||||||
|
metadatas = subject_metadatas(options)
|
||||||
|
logger.debug(f"Metadata {metadatas}")
|
||||||
|
|
||||||
list_infos = subject_metadatas(options)
|
for meta in metadatas:
|
||||||
|
logger.debug(f"Feeding template toward {meta['texfile']}")
|
||||||
logger.debug(f"Metadata {list_infos}")
|
|
||||||
|
|
||||||
tex_files = []
|
|
||||||
for infos in list_infos:
|
|
||||||
dest = working_dir / Path(template.replace("tpl", infos["num"]))
|
|
||||||
logger.debug(f"Feeding template toward {dest}")
|
|
||||||
tex_files.append(dest)
|
|
||||||
if options["crazy"]:
|
if options["crazy"]:
|
||||||
while True:
|
crazy_feed(
|
||||||
try:
|
template=Path(meta["directory"]) / meta["template"],
|
||||||
pytex.feed(
|
data=meta,
|
||||||
working_dir / template,
|
output=meta["texfile"],
|
||||||
{"infos": infos},
|
|
||||||
output=dest,
|
|
||||||
force=1,
|
force=1,
|
||||||
)
|
)
|
||||||
except:
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
break
|
feed(
|
||||||
else:
|
template=Path(meta["directory"]) / meta["template"],
|
||||||
pytex.feed(
|
data=meta,
|
||||||
working_dir / template, {"infos": infos}, output=dest, force=1
|
output=meta["texfile"],
|
||||||
)
|
force=1,
|
||||||
logger.debug(f"{dest} fed")
|
|
||||||
|
|
||||||
if not options["no_compile"]:
|
|
||||||
pdf_files = []
|
|
||||||
for texfile in tex_files:
|
|
||||||
logger.debug(f"Start compiling {texfile}")
|
|
||||||
pytex.pdflatex(texfile)
|
|
||||||
logger.debug(f"End compiling {texfile}")
|
|
||||||
pdf_files.append(str(texfile).split(".")[0] + ".pdf")
|
|
||||||
logger.debug(f"Compiled files : {pdf_files}")
|
|
||||||
|
|
||||||
if not options["no_join"] and not options["no_compile"]:
|
|
||||||
pdfjoin(
|
|
||||||
pdf_files,
|
|
||||||
template.replace("tpl", "all").replace(".tex", ".pdf"),
|
|
||||||
working_dir,
|
|
||||||
rm_pdfs=1,
|
|
||||||
)
|
)
|
||||||
|
assert(Path(meta["texfile"]).exists())
|
||||||
|
logger.debug(f"{meta['texfile']} fed")
|
||||||
|
|
||||||
if options["corr"]:
|
if options["corr"]:
|
||||||
pdf_files = []
|
logger.debug(f"Building correction for {meta['texfile']}")
|
||||||
for texfile in tex_files:
|
meta.update({
|
||||||
corr_fname = activate_printanswers(texfile)
|
"corr_texfile": activate_printanswers(meta["texfile"]),
|
||||||
if not options["no_compile"]:
|
})
|
||||||
logger.debug(f"Start compiling {texfile}")
|
|
||||||
pytex.pdflatex(corr_fname)
|
|
||||||
logger.debug(f"End compiling {texfile}")
|
|
||||||
pdf_files.append(str(corr_fname).split(".")[0] + ".pdf")
|
|
||||||
deactivate_printanswers(corr_fname)
|
|
||||||
|
|
||||||
if not options["no_join"] and not options["no_compile"]:
|
if not options["no_compile"]:
|
||||||
|
for prefix in ["", "corr_"]:
|
||||||
|
key = prefix + "texfile"
|
||||||
|
try:
|
||||||
|
meta[key]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
texcompile(meta[key])
|
||||||
|
meta.update({
|
||||||
|
prefix+'pdffile': meta[key].replace('tex', 'pdf')
|
||||||
|
})
|
||||||
|
|
||||||
|
if not options["no_join"]:
|
||||||
|
for prefix in ["", "corr_"]:
|
||||||
|
key = prefix + "pdffile"
|
||||||
|
try:
|
||||||
|
pdfs = [m[key] for m in metadatas]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
pdfjoin(
|
pdfjoin(
|
||||||
pdf_files,
|
pdfs,
|
||||||
template.replace("tpl", "corr").replace(".tex", ".pdf"),
|
template.replace("tpl", prefix+"all").replace(".tex", ".pdf"),
|
||||||
working_dir,
|
directory,
|
||||||
rm_pdfs=1,
|
rm_pdfs=1,
|
||||||
)
|
)
|
||||||
|
|
||||||
if not options["dirty"]:
|
if not options["dirty"]:
|
||||||
pytex.clean(working_dir)
|
clean(directory)
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
|
@ -3,18 +3,7 @@
|
|||||||
|
|
||||||
|
|
||||||
import click
|
import click
|
||||||
import logging
|
from .bopytex import produce_and_compile
|
||||||
from pathlib import Path
|
|
||||||
from .bopytex import subject_metadatas, crazy_feed, pdfjoin, feed, clean, texcompile
|
|
||||||
|
|
||||||
formatter = logging.Formatter("%(name)s :: %(levelname)s :: %(message)s")
|
|
||||||
steam_handler = logging.StreamHandler()
|
|
||||||
steam_handler.setLevel(logging.DEBUG)
|
|
||||||
steam_handler.setFormatter(formatter)
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
logger.setLevel(logging.DEBUG)
|
|
||||||
logger.addHandler(steam_handler)
|
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.argument(
|
@click.argument(
|
||||||
@ -87,70 +76,7 @@ def new(**options):
|
|||||||
Feed the template (tpl_...) and then compile it with latex.
|
Feed the template (tpl_...) and then compile it with latex.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
logger.debug(f"CI parser gets {options}")
|
produce_and_compile(options)
|
||||||
|
|
||||||
template = Path(options["template"]).name
|
|
||||||
directory = Path(options["template"]).parent
|
|
||||||
metadatas = subject_metadatas(options)
|
|
||||||
logger.debug(f"Metadata {metadatas}")
|
|
||||||
|
|
||||||
for meta in metadatas:
|
|
||||||
logger.debug(f"Feeding template toward {meta['texfile']}")
|
|
||||||
if options["crazy"]:
|
|
||||||
crazy_feed(
|
|
||||||
template=Path(meta["directory"]) / meta["template"],
|
|
||||||
data=meta,
|
|
||||||
output=meta["texfile"],
|
|
||||||
force=1,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
feed(
|
|
||||||
template=Path(meta["directory"]) / meta["template"],
|
|
||||||
data=meta,
|
|
||||||
output=meta["texfile"],
|
|
||||||
force=1,
|
|
||||||
)
|
|
||||||
assert(Path(meta["texfile"]).exists())
|
|
||||||
logger.debug(f"{meta['texfile']} fed")
|
|
||||||
|
|
||||||
if options["corr"]:
|
|
||||||
logger.debug(f"Building correction for {meta['texfile']}")
|
|
||||||
meta.update({
|
|
||||||
"corr_texfile": activate_printanswers(meta["texfile"]),
|
|
||||||
})
|
|
||||||
|
|
||||||
if not options["no_compile"]:
|
|
||||||
for prefix in ["", "corr_"]:
|
|
||||||
key = prefix + "texfile"
|
|
||||||
try:
|
|
||||||
meta[key]
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
texcompile(meta[key])
|
|
||||||
meta.update({
|
|
||||||
prefix+'pdffile': meta[key].replace('tex', 'pdf')
|
|
||||||
})
|
|
||||||
|
|
||||||
if not options["no_join"]:
|
|
||||||
for prefix in ["", "corr_"]:
|
|
||||||
key = prefix + "pdffile"
|
|
||||||
try:
|
|
||||||
pdfs = [m[key] for m in metadatas]
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
pdfjoin(
|
|
||||||
pdfs,
|
|
||||||
template.replace("tpl", prefix+"all").replace(".tex", ".pdf"),
|
|
||||||
directory,
|
|
||||||
rm_pdfs=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
if not options["dirty"]:
|
|
||||||
clean(directory)
|
|
||||||
|
|
||||||
# produce_and_compile(options)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -111,6 +111,7 @@ def test_metadatas(prepare_test_template):
|
|||||||
"classe": "1ST",
|
"classe": "1ST",
|
||||||
"elo": "1000",
|
"elo": "1000",
|
||||||
"texfile": "01_test.tex",
|
"texfile": "01_test.tex",
|
||||||
|
"template": "tpl_test.tex",
|
||||||
"directory": ".",
|
"directory": ".",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -119,6 +120,7 @@ def test_metadatas(prepare_test_template):
|
|||||||
"classe": "1ST",
|
"classe": "1ST",
|
||||||
"elo": "1300",
|
"elo": "1300",
|
||||||
"texfile": "02_test.tex",
|
"texfile": "02_test.tex",
|
||||||
|
"template": "tpl_test.tex",
|
||||||
"directory": ".",
|
"directory": ".",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -127,6 +129,7 @@ def test_metadatas(prepare_test_template):
|
|||||||
"classe": "1ST",
|
"classe": "1ST",
|
||||||
"elo": "100",
|
"elo": "100",
|
||||||
"texfile": "03_test.tex",
|
"texfile": "03_test.tex",
|
||||||
|
"template": "tpl_test.tex",
|
||||||
"directory": ".",
|
"directory": ".",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -135,6 +138,7 @@ def test_metadatas(prepare_test_template):
|
|||||||
"classe": "1ST",
|
"classe": "1ST",
|
||||||
"elo": "4000",
|
"elo": "4000",
|
||||||
"texfile": "04_test.tex",
|
"texfile": "04_test.tex",
|
||||||
|
"template": "tpl_test.tex",
|
||||||
"directory": ".",
|
"directory": ".",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -143,6 +147,7 @@ def test_metadatas(prepare_test_template):
|
|||||||
"classe": "1ST",
|
"classe": "1ST",
|
||||||
"elo": "1300",
|
"elo": "1300",
|
||||||
"texfile": "05_test.tex",
|
"texfile": "05_test.tex",
|
||||||
|
"template": "tpl_test.tex",
|
||||||
"directory": ".",
|
"directory": ".",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user