This commit is contained in:
parent
7782330ed2
commit
5f0fc8bc42
@ -60,10 +60,19 @@ def get_working_dir(options):
|
||||
|
||||
|
||||
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 """
|
||||
output_fname = "corr_" + texfile
|
||||
""" Activate printanswers mod in 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(output_fname, "w") as output_f:
|
||||
for line in input_f.readlines():
|
||||
@ -120,7 +129,8 @@ def subject_metadatas(options):
|
||||
d.update(s)
|
||||
metadatas.append(d)
|
||||
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:
|
||||
raise ValueError("Need metacsv or quantity to build subject metadata")
|
||||
|
||||
@ -222,7 +232,8 @@ def produce_and_compile(options):
|
||||
else:
|
||||
pdfjoin(
|
||||
pdfs,
|
||||
template.replace("tpl", prefix+"all").replace(".tex", ".pdf"),
|
||||
template.replace(
|
||||
"tpl", prefix+"all").replace(".tex", ".pdf"),
|
||||
directory,
|
||||
rm_pdfs=1,
|
||||
)
|
||||
|
@ -15,6 +15,7 @@ logger = logging.getLogger(__name__)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger.addHandler(steam_handler)
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.argument(
|
||||
"template",
|
||||
@ -26,7 +27,6 @@ logger.addHandler(steam_handler)
|
||||
"-w",
|
||||
"--working-dir",
|
||||
type=click.Path(exists=True),
|
||||
help="Where fed templates and compiled files will be placed",
|
||||
)
|
||||
@click.option(
|
||||
"-s",
|
||||
@ -64,7 +64,7 @@ logger.addHandler(steam_handler)
|
||||
"--only-corr",
|
||||
is_flag=True,
|
||||
default=False,
|
||||
help="Create and compile only correction from existing subjects",
|
||||
help="Activate correction and compile only from existing subjects",
|
||||
)
|
||||
@click.option(
|
||||
"-c",
|
||||
@ -96,6 +96,7 @@ def new(**options):
|
||||
logger.debug(f"Metadata {metadatas}")
|
||||
|
||||
for meta in metadatas:
|
||||
if not options["only_corr"]:
|
||||
logger.debug(f"Feeding template toward {meta['texfile']}")
|
||||
if options["crazy"]:
|
||||
crazy_feed(
|
||||
@ -114,14 +115,19 @@ def new(**options):
|
||||
assert(Path(meta["texfile"]).exists())
|
||||
logger.debug(f"{meta['texfile']} fed")
|
||||
|
||||
if options["corr"]:
|
||||
if options["corr"] or options["only_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_"]:
|
||||
if options["only_corr"]:
|
||||
to_compile = ["corr_"]
|
||||
else:
|
||||
to_compile = ["", "corr_"]
|
||||
|
||||
for prefix in to_compile:
|
||||
key = prefix + "texfile"
|
||||
try:
|
||||
meta[key]
|
||||
@ -143,7 +149,8 @@ def new(**options):
|
||||
else:
|
||||
pdfjoin(
|
||||
pdfs,
|
||||
template.replace("tpl", prefix+"all").replace(".tex", ".pdf"),
|
||||
template.replace(
|
||||
"tpl", prefix+"all").replace(".tex", ".pdf"),
|
||||
directory,
|
||||
rm_pdfs=1,
|
||||
)
|
||||
@ -151,8 +158,6 @@ def new(**options):
|
||||
if not options["dirty"]:
|
||||
clean(directory)
|
||||
|
||||
# produce_and_compile(options)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
new()
|
||||
|
Loading…
Reference in New Issue
Block a user