Feat: planner generate tasks all by themselves

This commit is contained in:
Bertrand Benjamin 2022-04-09 23:00:43 +02:00
parent c89959673b
commit abd517b339
2 changed files with 50 additions and 2 deletions

View File

@ -1,9 +1,43 @@
from bopytex.tasks import Task, activate_corr_on, compile_pdf, generate, join_pdfs from bopytex.tasks import Task, activate_corr_on, compile_pdf, generate, join_pdfs
import bopytex.planner.naming as naming import bopytex.planner.naming as naming
from bopytex.planner.exceptions import PlannerMissingOption
import csv
def build_subject_list_from_infos(infos: list[dict]) -> list[dict]:
subjects = []
digit = len(str(len(infos)))
for i, infos in enumerate(infos):
subjects.append({"number": str(i + 1).zfill(digit), **infos})
return subjects
def build_subject_list_from_qty(qty: int) -> list[dict]:
subjects = []
digit = len(str(qty))
for i in range(qty):
subjects.append({"number": str(i + 1).zfill(digit)})
return subjects
def default_planner(options: dict) -> list[Task]: def default_planner(options: dict) -> list[Task]:
pass try:
students_csv = options["students_csv"]
except KeyError:
try:
quantity_subjects = options["quantity_subjects"]
except KeyError:
raise PlannerMissingOption("students_csv or quantity_subjects is required")
else:
options["subjects"] = build_subject_list_from_qty(qty=quantity_subjects)
else:
with open(students_csv, "r") as csv_file:
infos = csv.DictReader(csv_file)
options["subjects"] = build_subject_list_from_infos(infos)
return default_tasks_builder(options)
def default_tasks_builder( def default_tasks_builder(

View File

@ -1,9 +1,23 @@
from bopytex.tasks import Task, activate_corr_on, compile_pdf, generate, join_pdfs from bopytex.tasks import Task, activate_corr_on, compile_pdf, generate, join_pdfs
import bopytex.planner.naming as naming import bopytex.planner.naming as naming
import os
def list_files(dir=".", accept=lambda _: True, reject=lambda _: False):
files = []
for file in os.listdir(dir):
if accept(file) and not reject(file):
files.append(file)
return files
def only_corr_planner(options: dict) -> list[Task]: def only_corr_planner(options: dict) -> list[Task]:
pass sources = list_files(
accept=lambda x: x.endswith(".tex"),
reject=lambda x: x.startswith("tpl_"),
)
options["sources"] = sources
return only_corr_tasks_builder(options)
def only_corr_tasks_builder( def only_corr_tasks_builder(