diff --git a/bopytex/planner.py b/bopytex/planner.py index 21d00ca..28fea3b 100644 --- a/bopytex/planner.py +++ b/bopytex/planner.py @@ -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, diff --git a/bopytex/service.py b/bopytex/service.py index 77ec753..5bb2b3a 100755 --- a/bopytex/service.py +++ b/bopytex/service.py @@ -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 diff --git a/test/test_planner.py b/test/test_planner.py index 9582726..41c542f 100644 --- a/test/test_planner.py +++ b/test/test_planner.py @@ -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,9 +225,10 @@ def test_planner_generate_compile_corr_joined(): ), ] + def test_only_corr_planner(): tasks = only_corr_planner( - sources = ["01_source.tex", "02_source.tex"], + sources=["01_source.tex", "02_source.tex"], ) assert tasks == [ Task(