Feat: possiblité de rejouter inv sequence
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Bertrand Benjamin 2020-09-22 20:42:19 +02:00
parent 5133d15ffd
commit 4287911c23

View File

@ -49,30 +49,45 @@ 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(
author=AUTHOR,
tribe="",
title="",
tags="",
summary="",
*args,
**kwrds,
):
sequence = {} sequence = {}
print("Nouvelle séquence") print("Nouvelle séquence")
sequence["author"] = prompt("Auteur: ", default=AUTHOR) sequence["author"] = prompt("Auteur: ", default=author)
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),
default=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"] = max([int(seq.name[0:2]) for seq in sequences]) + 1 sequence["num"] = max([int(seq.name[0:2]) for seq in 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']}): ", default=title
)
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),
default=tags,
) )
sequence["summary"] = prompt("Résumé: ") sequence["summary"] = prompt("Résumé: ", default=summary)
return sequence return sequence
@ -104,30 +119,31 @@ def import_skel(dest, datas, skel="sequence", skel_path="./tools/skeleton"):
@task @task
def sequence(c): def sequence(c):
sequence = sequence_prompt() sequence = {}
validate = False
while not validate:
sequence = sequence_prompt(**sequence)
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 = """\
Séquence: {num:0>2} {title} Séquence: {num:0>2} {title}
Niveau: {tribe} Niveau: {tribe}
Auteur: {author} Auteur: {author}
Date: {date} Date: {date}
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? ").lower() in ["o", "k", "oui", "ok"]
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:
print("Tant pis. Ya plus qu'à recommencer.")