87 lines
2.1 KiB
Python
Executable File
87 lines
2.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import argparse
|
|
from pathlib import Path
|
|
from blog.page import new_page
|
|
from blog.config import Config
|
|
from blog.blog import Blog
|
|
|
|
# from blog.blog import Blog
|
|
|
|
actions_list = ["new", "make"]
|
|
blog_dir = "./inbox/"
|
|
|
|
|
|
def load_args():
|
|
"""Charge l'action et les paramêtres communs a toutes les actions."""
|
|
parser = argparse.ArgumentParser(description="Gestion du blog")
|
|
parser.add_argument("action", choices=actions_list, help="L'action a réaliser.")
|
|
parser.add_argument(
|
|
"-c",
|
|
"--config",
|
|
default=".blog",
|
|
help="Chemin vers le fichier de configuration",
|
|
)
|
|
parser.add_argument(
|
|
"-i",
|
|
"--inbox",
|
|
default="./inbox",
|
|
help="Chemin vers les fichiers markdown du blog",
|
|
)
|
|
parser.add_argument("all", nargs=argparse.REMAINDER)
|
|
return vars(parser.parse_args())
|
|
|
|
|
|
def load_make_args(args: str) -> dict:
|
|
"""Charge les paramêtres spécifiques à l'action make"""
|
|
parser = argparse.ArgumentParser(description="Compile le blog")
|
|
parser.add_argument(
|
|
"-t",
|
|
"--theme",
|
|
default="./themes/default",
|
|
help="Chemin vers le theme utilisé pour exporter le blog",
|
|
)
|
|
parser.add_argument(
|
|
"-o",
|
|
"--output",
|
|
default="./output",
|
|
help="Nom du dossier ou sera exporté le blog en html",
|
|
)
|
|
return vars(parser.parse_args(args))
|
|
|
|
|
|
def main():
|
|
"""Fonction principale"""
|
|
args = load_args()
|
|
|
|
if not Path(args["config"]).is_file():
|
|
print("Le fichier de configuration n'existe pas.")
|
|
os._exit(1)
|
|
|
|
conf = Config(args["config"])
|
|
conf.overload(args)
|
|
|
|
match args["action"]:
|
|
case "new":
|
|
page_title = " ".join(args["all"])
|
|
new_page(page_title)
|
|
os._exit(0)
|
|
|
|
case "make":
|
|
args = load_make_args(args["all"])
|
|
conf.overload(args)
|
|
|
|
blog = Blog(conf)
|
|
blog.make()
|
|
|
|
os._exit(0)
|
|
|
|
case _:
|
|
print("error")
|
|
os._exit(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|