#!/usr/bin/env python # encoding: utf-8 """ 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.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 = [] 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 build_subjects(students_csv, quantity_subjects): if students_csv: with open(students_csv, "r") as csv_file: infos = csv.DictReader(csv_file) return build_subject_list_from_infos(infos) return build_subject_list_from_qty(quantity_subjects) def list_tex_files_no_tpl(dir="."): tex_files = [] for file in os.listdir(dir): if file.endswith(".tex") and not file.startswith("tpl_"): tex_files.append(file) return tex_files def bopytex( template: str, students_csv: str, quantity_subjects: int, corr: bool, only_corr: bool, no_join: bool, no_pdf: bool, actions: dict = ACTIONS, ): if only_corr: tex_files = list_tex_files_no_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) scheduler = Scheduler(actions, [template]) scheduler.append(tasks) scheduler.run() # ----------------------------- # Reglages pour 'vim' # vim:set autoindent expandtab tabstop=4 shiftwidth=4: # cursor: 16 del