capacity to read a config file

This commit is contained in:
Guilhem Fauré 2023-05-22 13:31:35 +02:00
parent 6fb1e9a29e
commit 13824687bd
2 changed files with 16 additions and 6 deletions

6
.gitignore vendored
View File

@ -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

View File

@ -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())