Compare commits
No commits in common. "a4f83d140ff45323be7f455790cd13bfbc18e409" and "8e0121e8a8cc3be80fa1d7b527326e3966beffb2" have entirely different histories.
a4f83d140f
...
8e0121e8a8
2
.gitignore
vendored
2
.gitignore
vendored
@ -26,4 +26,4 @@ test/
|
|||||||
.venv/
|
.venv/
|
||||||
venv/
|
venv/
|
||||||
video/
|
video/
|
||||||
.vim
|
|
||||||
|
@ -2,16 +2,7 @@ docutils==0.16
|
|||||||
gitdb==4.0.5
|
gitdb==4.0.5
|
||||||
GitPython==3.1.7
|
GitPython==3.1.7
|
||||||
greenlet==0.4.16
|
greenlet==0.4.16
|
||||||
invoke==1.4.1
|
|
||||||
jedi==0.17.2
|
|
||||||
Jinja2==2.11.2
|
|
||||||
MarkupSafe==1.1.1
|
|
||||||
msgpack==1.0.0
|
msgpack==1.0.0
|
||||||
mypytex==0.4
|
|
||||||
parso==0.7.1
|
|
||||||
prompt-toolkit==3.0.6
|
|
||||||
pynvim==0.4.1
|
pynvim==0.4.1
|
||||||
restructuredtext-lint==1.3.1
|
restructuredtext-lint==1.3.1
|
||||||
smmap==3.0.4
|
smmap==3.0.4
|
||||||
Unidecode==1.1.1
|
|
||||||
wcwidth==0.2.5
|
|
||||||
|
46
tasks.py
46
tasks.py
@ -4,7 +4,7 @@ from prompt_toolkit import prompt
|
|||||||
from prompt_toolkit.completion import WordCompleter
|
from prompt_toolkit.completion import WordCompleter
|
||||||
from prompt_toolkit.validation import Validator
|
from prompt_toolkit.validation import Validator
|
||||||
from unidecode import unidecode
|
from unidecode import unidecode
|
||||||
import jinja2
|
import jinja2
|
||||||
from pytex import texenv
|
from pytex import texenv
|
||||||
import datetime
|
import datetime
|
||||||
import locale
|
import locale
|
||||||
@ -12,23 +12,21 @@ import locale
|
|||||||
locale.setlocale(locale.LC_ALL, "fr_FR.UTF-8")
|
locale.setlocale(locale.LC_ALL, "fr_FR.UTF-8")
|
||||||
|
|
||||||
TRIBES = [
|
TRIBES = [
|
||||||
{"name": "Terminale Technologique", "directory": "TST"},
|
{"name": "Première Technologique", "directory": "1ST"},
|
||||||
{"name": "Terminale Terminale spé sti2d", "directory": "TST_sti2d"},
|
{"name": "Science numérique et technologique", "directory": "SNT"},
|
||||||
{"name": "Science numérique et technologique", "directory": "SNT"},
|
{"name": "Terminale L-ES", "directory": "TESL"},
|
||||||
]
|
{"name": "Terminale sti2d", "directory": "Tsti2d"},
|
||||||
|
]
|
||||||
|
|
||||||
AUTHOR = "Benjamin Bertrand"
|
AUTHOR = "Benjamin Bertrand"
|
||||||
|
|
||||||
|
|
||||||
def is_tribe(tribe):
|
def is_tribe(tribe):
|
||||||
return tribe in [t["directory"] for t in TRIBES]
|
return tribe in [t["directory"] for t in TRIBES]
|
||||||
|
|
||||||
|
|
||||||
def get_sequences(tribe):
|
def get_sequences(tribe):
|
||||||
p = Path(tribe)
|
p = Path(tribe)
|
||||||
return [x for x in p.iterdir() if (x.is_dir() and x.name[0:2].isdigit())]
|
return [x for x in p.iterdir() if (x.is_dir() and x.name[0:2].isdigit())]
|
||||||
|
|
||||||
|
|
||||||
def get_tags(tribe=""):
|
def get_tags(tribe=""):
|
||||||
p = Path(tribe)
|
p = Path(tribe)
|
||||||
tags = set()
|
tags = set()
|
||||||
@ -38,15 +36,13 @@ def get_tags(tribe=""):
|
|||||||
line = index.readline()
|
line = index.readline()
|
||||||
while line:
|
while line:
|
||||||
if line.startswith(":tags"):
|
if line.startswith(":tags"):
|
||||||
tags.update(line[7:].replace("\n", "").split(", "))
|
tags.update(line[7:].replace("\n", "").split(', '))
|
||||||
break
|
break
|
||||||
line = index.readline()
|
line = index.readline()
|
||||||
return {t.lower() for t in tags}
|
return {t.lower() for t in tags}
|
||||||
|
|
||||||
|
|
||||||
def next_weekday(date, day=0):
|
def next_weekday(date, day=0):
|
||||||
return date + datetime.timedelta(days=(day - date.weekday() + 7) % 7)
|
return date + datetime.timedelta(days=(day-date.weekday()+7)%7)
|
||||||
|
|
||||||
|
|
||||||
def sequence_prompt():
|
def sequence_prompt():
|
||||||
sequence = {}
|
sequence = {}
|
||||||
@ -57,24 +53,19 @@ def sequence_prompt():
|
|||||||
sequence["date"] = datetime.date.today()
|
sequence["date"] = datetime.date.today()
|
||||||
|
|
||||||
tribes = WordCompleter([t["directory"] for t in TRIBES])
|
tribes = WordCompleter([t["directory"] for t in TRIBES])
|
||||||
sequence["tribe"] = prompt(
|
sequence["tribe"] = prompt("Classe: ", completer=tribes, validator=Validator.from_callable(is_tribe))
|
||||||
"Classe: ", completer=tribes, validator=Validator.from_callable(is_tribe)
|
|
||||||
)
|
|
||||||
|
|
||||||
sequences = get_sequences(sequence["tribe"])
|
sequences = get_sequences(sequence["tribe"])
|
||||||
print("Séquences trouvées:\n\t" + "\n\t".join(sorted([s.name for s in sequences])))
|
print("Séquences trouvées:\n\t" + '\n\t'.join(sorted([s.name for s in sequences])))
|
||||||
sequence["num"] = len(sequences) + 1
|
sequence["num"] = len(sequences) + 1
|
||||||
sequence["title"] = prompt(f"Nom de la séquence (n°{sequence['num']}): ")
|
sequence["title"] = prompt(f"Nom de la séquence (n°{sequence['num']}): ")
|
||||||
|
|
||||||
known_tags = get_tags()
|
known_tags = get_tags()
|
||||||
sequence["tags"] = prompt(
|
sequence["tags"] = prompt("Tags (séparés par une virgule): ", completer=WordCompleter(known_tags))
|
||||||
"Tags (séparés par une virgule): ", completer=WordCompleter(known_tags)
|
|
||||||
)
|
|
||||||
|
|
||||||
sequence["summary"] = prompt("Résumé: ")
|
sequence["summary"] = prompt("Résumé: ")
|
||||||
return sequence
|
return sequence
|
||||||
|
|
||||||
|
|
||||||
def import_skel(dest, datas, skel="sequence", skel_path="./tools/skeleton"):
|
def import_skel(dest, datas, skel="sequence", skel_path="./tools/skeleton"):
|
||||||
d = Path(dest)
|
d = Path(dest)
|
||||||
d.mkdir()
|
d.mkdir()
|
||||||
@ -84,7 +75,7 @@ def import_skel(dest, datas, skel="sequence", skel_path="./tools/skeleton"):
|
|||||||
|
|
||||||
template_loader = jinja2.FileSystemLoader(searchpath=p)
|
template_loader = jinja2.FileSystemLoader(searchpath=p)
|
||||||
template_env = jinja2.Environment(loader=template_loader)
|
template_env = jinja2.Environment(loader=template_loader)
|
||||||
|
|
||||||
texenv.loader.loaders.append(template_loader)
|
texenv.loader.loaders.append(template_loader)
|
||||||
|
|
||||||
print("")
|
print("")
|
||||||
@ -96,18 +87,15 @@ def import_skel(dest, datas, skel="sequence", skel_path="./tools/skeleton"):
|
|||||||
|
|
||||||
output_text = template.render(**datas)
|
output_text = template.render(**datas)
|
||||||
|
|
||||||
with open(d / filename, "w") as f:
|
with open(d/filename, "w") as f:
|
||||||
f.write(output_text)
|
f.write(output_text)
|
||||||
print(f"Importation de {filename} - OK")
|
print(f"Importation de {filename} - OK")
|
||||||
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def sequence(c):
|
def sequence(c):
|
||||||
sequence = sequence_prompt()
|
sequence = sequence_prompt()
|
||||||
|
|
||||||
dest = unidecode(
|
dest = unidecode(("{tribe}/{num:0>2}_{title}/".format(**sequence)).replace(" ", "_"))
|
||||||
("{tribe}/{num:0>2}_{title}/".format(**sequence)).replace(" ", "_")
|
|
||||||
)
|
|
||||||
dest = Path(dest)
|
dest = Path(dest)
|
||||||
|
|
||||||
seq_summary = """\
|
seq_summary = """\
|
||||||
@ -118,14 +106,12 @@ def sequence(c):
|
|||||||
Tags: {tags}
|
Tags: {tags}
|
||||||
Sommaire: {summary}
|
Sommaire: {summary}
|
||||||
Dossier: {dest}
|
Dossier: {dest}
|
||||||
""".format(
|
""".format(dest=dest, **sequence)
|
||||||
dest=dest, **sequence
|
|
||||||
)
|
|
||||||
print(seq_summary)
|
print(seq_summary)
|
||||||
|
|
||||||
validate = prompt("C'est ok? ")
|
validate = prompt("C'est ok? ")
|
||||||
if validate.lower() in ["o", "y", ""]:
|
if validate.lower() in ["o", "y", ""]:
|
||||||
sequence["title_under"] = "#" * len(sequence["title"])
|
sequence["title_under"] = '#'*len(sequence["title"])
|
||||||
import_skel(dest, sequence, "sequence")
|
import_skel(dest, sequence, "sequence")
|
||||||
else:
|
else:
|
||||||
print("Tant pis. Ya plus qu'à recommencer.")
|
print("Tant pis. Ya plus qu'à recommencer.")
|
||||||
|
Loading…
Reference in New Issue
Block a user