capacity to read a config file
This commit is contained in:
parent
6fb1e9a29e
commit
13824687bd
6
.gitignore
vendored
6
.gitignore
vendored
@ -156,6 +156,8 @@ dmypy.json
|
|||||||
# Cython debug symbols
|
# Cython debug symbols
|
||||||
cython_debug/
|
cython_debug/
|
||||||
|
|
||||||
|
# Data directory
|
||||||
|
data/
|
||||||
|
|
||||||
# Big database files
|
# Big database files
|
||||||
database/
|
database/
|
||||||
@ -163,3 +165,7 @@ database/
|
|||||||
# Outputted Markdown files
|
# Outputted Markdown files
|
||||||
markdown/
|
markdown/
|
||||||
output/
|
output/
|
||||||
|
|
||||||
|
# YAML Configuration
|
||||||
|
spip2md.yml
|
||||||
|
spip2md.yaml
|
||||||
|
@ -8,6 +8,12 @@ from yaml import Loader, load
|
|||||||
config_paths = ("spip2md.yml", "spip2md.yaml")
|
config_paths = ("spip2md.yml", "spip2md.yaml")
|
||||||
|
|
||||||
|
|
||||||
|
def config_file() -> Optional[str]:
|
||||||
|
for path in config_paths:
|
||||||
|
if isfile(path):
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
class Configuration:
|
class Configuration:
|
||||||
db = "spip"
|
db = "spip"
|
||||||
db_host = "localhost"
|
db_host = "localhost"
|
||||||
@ -15,6 +21,7 @@ class Configuration:
|
|||||||
db_pass = "password"
|
db_pass = "password"
|
||||||
output_dir = "output"
|
output_dir = "output"
|
||||||
default_export_max = 1000
|
default_export_max = 1000
|
||||||
|
data_dir = "data"
|
||||||
|
|
||||||
def __init__(self, config_file: Optional[str] = None) -> None:
|
def __init__(self, config_file: Optional[str] = None) -> None:
|
||||||
if config_file is not None:
|
if config_file is not None:
|
||||||
@ -30,11 +37,8 @@ class Configuration:
|
|||||||
self.output_dir = config["output_dir"]
|
self.output_dir = config["output_dir"]
|
||||||
if "default_export_nb" in config:
|
if "default_export_nb" in config:
|
||||||
self.default_export_max = config["default_export_max"]
|
self.default_export_max = config["default_export_max"]
|
||||||
|
if "data_dir" in config:
|
||||||
|
self.data_dir = config["data_dir"]
|
||||||
|
|
||||||
|
|
||||||
config = Configuration()
|
config = Configuration(config_file())
|
||||||
|
|
||||||
for path in config_paths:
|
|
||||||
if isfile(path):
|
|
||||||
config = Configuration(path)
|
|
||||||
break
|
|
||||||
|
Loading…
Reference in New Issue
Block a user