From 13824687bdfb068343cd03f51df79d91c291141e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilhem=20Faur=C3=A9?= Date: Mon, 22 May 2023 13:31:35 +0200 Subject: [PATCH] capacity to read a config file --- .gitignore | 6 ++++++ spip2md/config.py | 16 ++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 4bab660..e5305f3 100644 --- a/.gitignore +++ b/.gitignore @@ -156,6 +156,8 @@ dmypy.json # Cython debug symbols cython_debug/ +# Data directory +data/ # Big database files database/ @@ -163,3 +165,7 @@ database/ # Outputted Markdown files markdown/ output/ + +# YAML Configuration +spip2md.yml +spip2md.yaml diff --git a/spip2md/config.py b/spip2md/config.py index 555fe54..a60248b 100644 --- a/spip2md/config.py +++ b/spip2md/config.py @@ -8,6 +8,12 @@ from yaml import Loader, load config_paths = ("spip2md.yml", "spip2md.yaml") +def config_file() -> Optional[str]: + for path in config_paths: + if isfile(path): + return path + + class Configuration: db = "spip" db_host = "localhost" @@ -15,6 +21,7 @@ class Configuration: db_pass = "password" output_dir = "output" default_export_max = 1000 + data_dir = "data" def __init__(self, config_file: Optional[str] = None) -> None: if config_file is not None: @@ -30,11 +37,8 @@ class Configuration: self.output_dir = config["output_dir"] if "default_export_nb" in config: self.default_export_max = config["default_export_max"] + if "data_dir" in config: + self.data_dir = config["data_dir"] -config = Configuration() - -for path in config_paths: - if isfile(path): - config = Configuration(path) - break +config = Configuration(config_file())