Feat: only_corr works
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Bertrand Benjamin 2020-11-03 10:23:18 +01:00
parent 7782330ed2
commit 5f0fc8bc42
2 changed files with 45 additions and 29 deletions

View File

@ -60,10 +60,19 @@ def get_working_dir(options):
def activate_printanswers( def activate_printanswers(
texfile, noans=r"solution/print = false", ans=r"solution/print = true" texfile,
noans=r"%\printsolutionstype{exercise}",
ans=r"\printsolutionstype{exercise}",
corr_prefix="corr_"
): ):
""" Activate printanswers mod in texfile """ """ Activate printanswers mod in texfile
output_fname = "corr_" + texfile
:param texfile: path to the latex file
:param noans: string that prevent printing solution
:param ans: string that activate printing solution
:param corr_prefix: correction file prefix
"""
output_fname = corr_prefix + texfile
with open(texfile, "r") as input_f: with open(texfile, "r") as input_f:
with open(output_fname, "w") as output_f: with open(output_fname, "w") as output_f:
for line in input_f.readlines(): for line in input_f.readlines():
@ -120,7 +129,8 @@ def subject_metadatas(options):
d.update(s) d.update(s)
metadatas.append(d) metadatas.append(d)
elif options["number_subjects"] > 0: elif options["number_subjects"] > 0:
metadatas = [{"num": f"{i+1:02d}"} for i in range(options["number_subjects"])] metadatas = [{"num": f"{i+1:02d}"}
for i in range(options["number_subjects"])]
else: else:
raise ValueError("Need metacsv or quantity to build subject metadata") raise ValueError("Need metacsv or quantity to build subject metadata")
@ -222,7 +232,8 @@ def produce_and_compile(options):
else: else:
pdfjoin( pdfjoin(
pdfs, pdfs,
template.replace("tpl", prefix+"all").replace(".tex", ".pdf"), template.replace(
"tpl", prefix+"all").replace(".tex", ".pdf"),
directory, directory,
rm_pdfs=1, rm_pdfs=1,
) )

View File

@ -15,6 +15,7 @@ logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
logger.addHandler(steam_handler) logger.addHandler(steam_handler)
@click.command() @click.command()
@click.argument( @click.argument(
"template", "template",
@ -26,7 +27,6 @@ logger.addHandler(steam_handler)
"-w", "-w",
"--working-dir", "--working-dir",
type=click.Path(exists=True), type=click.Path(exists=True),
help="Where fed templates and compiled files will be placed",
) )
@click.option( @click.option(
"-s", "-s",
@ -64,7 +64,7 @@ logger.addHandler(steam_handler)
"--only-corr", "--only-corr",
is_flag=True, is_flag=True,
default=False, default=False,
help="Create and compile only correction from existing subjects", help="Activate correction and compile only from existing subjects",
) )
@click.option( @click.option(
"-c", "-c",
@ -96,6 +96,7 @@ def new(**options):
logger.debug(f"Metadata {metadatas}") logger.debug(f"Metadata {metadatas}")
for meta in metadatas: for meta in metadatas:
if not options["only_corr"]:
logger.debug(f"Feeding template toward {meta['texfile']}") logger.debug(f"Feeding template toward {meta['texfile']}")
if options["crazy"]: if options["crazy"]:
crazy_feed( crazy_feed(
@ -114,14 +115,19 @@ def new(**options):
assert(Path(meta["texfile"]).exists()) assert(Path(meta["texfile"]).exists())
logger.debug(f"{meta['texfile']} fed") logger.debug(f"{meta['texfile']} fed")
if options["corr"]: if options["corr"] or options["only_corr"]:
logger.debug(f"Building correction for {meta['texfile']}") logger.debug(f"Building correction for {meta['texfile']}")
meta.update({ meta.update({
"corr_texfile": activate_printanswers(meta["texfile"]), "corr_texfile": activate_printanswers(meta["texfile"]),
}) })
if not options["no_compile"]: if not options["no_compile"]:
for prefix in ["", "corr_"]: if options["only_corr"]:
to_compile = ["corr_"]
else:
to_compile = ["", "corr_"]
for prefix in to_compile:
key = prefix + "texfile" key = prefix + "texfile"
try: try:
meta[key] meta[key]
@ -143,7 +149,8 @@ def new(**options):
else: else:
pdfjoin( pdfjoin(
pdfs, pdfs,
template.replace("tpl", prefix+"all").replace(".tex", ".pdf"), template.replace(
"tpl", prefix+"all").replace(".tex", ".pdf"),
directory, directory,
rm_pdfs=1, rm_pdfs=1,
) )
@ -151,8 +158,6 @@ def new(**options):
if not options["dirty"]: if not options["dirty"]:
clean(directory) clean(directory)
# produce_and_compile(options)
if __name__ == "__main__": if __name__ == "__main__":
new() new()