2013-09-27 18:09:38 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# encoding: utf-8
|
|
|
|
|
2017-04-16 08:36:27 +00:00
|
|
|
"""
|
|
|
|
Producing then compiling templates
|
|
|
|
"""
|
|
|
|
|
2022-04-09 05:30:13 +00:00
|
|
|
import csv
|
2022-04-09 14:08:10 +00:00
|
|
|
import os
|
2022-04-09 14:18:56 +00:00
|
|
|
from bopytex.actions import ACTIONS
|
|
|
|
|
2022-04-09 20:06:42 +00:00
|
|
|
from bopytex.planner import only_corr_planner, default_planner
|
2022-04-09 14:18:56 +00:00
|
|
|
from bopytex.scheduler import Scheduler
|
2017-04-16 15:46:14 +00:00
|
|
|
|
2017-04-17 14:10:38 +00:00
|
|
|
|
2022-04-09 05:30:13 +00:00
|
|
|
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
|
|
|
|
|
2022-04-09 14:08:10 +00:00
|
|
|
|
2022-04-09 05:30:13 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2022-04-09 20:06:42 +00:00
|
|
|
def list_files(dir=".", accept=lambda _: True, reject=lambda _: False):
|
2022-04-09 14:08:10 +00:00
|
|
|
tex_files = []
|
|
|
|
for file in os.listdir(dir):
|
2022-04-09 20:06:42 +00:00
|
|
|
if accept(file) and not reject(file):
|
2022-04-09 14:08:10 +00:00
|
|
|
tex_files.append(file)
|
|
|
|
return tex_files
|
|
|
|
|
|
|
|
|
2022-04-09 05:30:13 +00:00
|
|
|
def bopytex(
|
|
|
|
template: str,
|
|
|
|
students_csv: str,
|
|
|
|
quantity_subjects: int,
|
|
|
|
corr: bool,
|
|
|
|
only_corr: bool,
|
|
|
|
no_join: bool,
|
2022-04-09 14:18:56 +00:00
|
|
|
no_pdf: bool,
|
|
|
|
actions: dict = ACTIONS,
|
2019-10-15 17:50:54 +00:00
|
|
|
):
|
2022-04-09 14:18:56 +00:00
|
|
|
|
|
|
|
if only_corr:
|
2022-04-09 20:06:42 +00:00
|
|
|
tex_files = list_files(
|
|
|
|
accept=lambda x: x.endswith(".tex"),
|
|
|
|
reject=lambda x: x.startswith("tpl_"),
|
|
|
|
)
|
2022-04-09 14:18:56 +00:00
|
|
|
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
|
|
|
|
)
|
2022-04-09 20:06:42 +00:00
|
|
|
tasks = default_planner(template, subjects, corr, no_join, no_pdf)
|
2022-04-09 19:53:00 +00:00
|
|
|
|
|
|
|
scheduler = Scheduler([template])
|
2022-04-09 14:18:56 +00:00
|
|
|
scheduler.append(tasks)
|
|
|
|
|
2022-04-09 20:06:42 +00:00
|
|
|
for task in scheduler.backlog:
|
2022-04-09 19:53:00 +00:00
|
|
|
pass
|
2014-01-19 20:37:46 +00:00
|
|
|
|
2017-04-16 08:36:27 +00:00
|
|
|
|
2013-09-27 18:09:38 +00:00
|
|
|
# -----------------------------
|
|
|
|
# Reglages pour 'vim'
|
|
|
|
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
2017-04-16 08:36:27 +00:00
|
|
|
# cursor: 16 del
|