Bopytex/bopytex/planner.py

68 lines
1.5 KiB
Python

from bopytex.tasks import Task, activate_corr_on, compile_pdf, generate, join_pdfs
def naming_template2source(template: str, metadatas: dict):
return metadatas["number"] + template[3:]
def naming_corr(source):
return "corr_" + source
def naming_source2pdf(source):
return source[:-4] + ".pdf"
def naming_join(template):
return naming_source2pdf("joined" + template[3:])
def planner(
template: str,
subjects: list[dict],
corr: bool = False,
no_join: bool = False,
no_pdf: bool = False,
# dirty: bool = False,
) -> list[Task]:
tasks = []
pdfs = []
corr_pdfs = []
for subject in subjects:
source = naming_template2source(template, subject)
tasks.append(generate(template, subject, source))
if not no_pdf:
pdf = naming_source2pdf(source)
tasks.append(compile_pdf(source, pdf))
pdfs.append(pdf)
if corr:
corr_source = naming_corr(source)
tasks.append(activate_corr_on(source, corr_source))
if not no_pdf:
corr_pdf = naming_source2pdf(corr_source)
tasks.append(compile_pdf(corr_source, corr_pdf))
corr_pdfs.append(corr_pdf)
if not no_join:
joined = naming_join(template)
if pdfs:
tasks.append(join_pdfs(pdfs, joined))
if corr_pdfs:
corr_joined = naming_corr(joined)
tasks.append(join_pdfs(corr_pdfs, corr_joined))
return tasks
def only_corr_planner(
no_join: bool = False,
):
pass