refact: rename planner to default_planner

This commit is contained in:
Bertrand Benjamin 2022-04-09 22:06:42 +02:00
parent e52b6eb064
commit 8c9d7bf9a2
3 changed files with 18 additions and 24 deletions

View File

@ -17,7 +17,7 @@ def naming_join(template):
return naming_source2pdf("joined" + template[3:])
def planner(
def default_planner(
template: str,
subjects: list[dict],
corr: bool = False,

View File

@ -5,22 +5,13 @@
Producing then compiling templates
"""
import logging
import csv
import os
from bopytex.actions import ACTIONS
from bopytex.planner import only_corr_planner, planner
from bopytex.planner import only_corr_planner, default_planner
from bopytex.scheduler import Scheduler
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)
def build_subject_list_from_infos(infos: list[dict]) -> list[dict]:
subjects = []
@ -47,10 +38,10 @@ def build_subjects(students_csv, quantity_subjects):
return build_subject_list_from_qty(quantity_subjects)
def list_tex_files_no_tpl(dir="."):
def list_files(dir=".", accept=lambda _: True, reject=lambda _: False):
tex_files = []
for file in os.listdir(dir):
if file.endswith(".tex") and not file.startswith("tpl_"):
if accept(file) and not reject(file):
tex_files.append(file)
return tex_files
@ -67,19 +58,21 @@ def bopytex(
):
if only_corr:
tex_files = list_tex_files_no_tpl()
tex_files = list_files(
accept=lambda x: x.endswith(".tex"),
reject=lambda x: x.startswith("tpl_"),
)
tasks = only_corr_planner(sources=tex_files, no_pdf=no_pdf, no_join=no_join)
else:
subjects = build_subjects(
students_csv=students_csv, quantity_subjects=quantity_subjects
)
tasks = planner(template, subjects, corr, no_join, no_pdf)
tasks = default_planner(template, subjects, corr, no_join, no_pdf)
scheduler = Scheduler([template])
scheduler.append(tasks)
for _ in scheduler.backlog:
for task in scheduler.backlog:
pass

View File

@ -1,9 +1,9 @@
from bopytex.planner import only_corr_planner, planner
from bopytex.planner import only_corr_planner, default_planner
from bopytex.tasks import Task
def test_planner_generate():
tasks = planner(
tasks = default_planner(
template="tpl_source.tex",
subjects=[{"number": "01"}, {"number": "02"}],
no_pdf=1,
@ -25,7 +25,7 @@ def test_planner_generate():
def test_planner_generate_compile():
tasks = planner(
tasks = default_planner(
template="tpl_source.tex",
subjects=[{"number": "01"}, {"number": "02"}],
no_join=1,
@ -59,7 +59,7 @@ def test_planner_generate_compile():
def test_planner_generate_compile_join():
tasks = planner(
tasks = default_planner(
template="tpl_source.tex",
subjects=[{"number": "01"}, {"number": "02"}],
)
@ -98,7 +98,7 @@ def test_planner_generate_compile_join():
def test_planner_generate_compile_corr():
tasks = planner(
tasks = default_planner(
template="tpl_source.tex",
subjects=[{"number": "01"}, {"number": "02"}],
corr=1,
@ -157,7 +157,7 @@ def test_planner_generate_compile_corr():
def test_planner_generate_compile_corr_joined():
tasks = planner(
tasks = default_planner(
template="tpl_source.tex",
subjects=[{"number": "01"}, {"number": "02"}],
corr=1,
@ -225,6 +225,7 @@ def test_planner_generate_compile_corr_joined():
),
]
def test_only_corr_planner():
tasks = only_corr_planner(
sources=["01_source.tex", "02_source.tex"],