Added parser.py docstrings

pull/15/head
Jef Roosens 2021-04-25 18:27:57 +02:00
parent 3277af2ac5
commit d513a03c4a
Signed by: Jef Roosens
GPG Key ID: B580B976584B5F30
2 changed files with 15 additions and 0 deletions

View File

@ -1,3 +1,4 @@
"""Handles parsing a config file from disk."""
import yaml
from pathlib import Path
from typing import List, Union
@ -6,9 +7,19 @@ import skeleton
def read_specs_file(path: Union[str, Path]) -> List[Spec]:
"""
Read a config file and merge it with the skeleton.
Args:
path: path to the yaml config file
Returns:
A list of specs, parsed from the config.
"""
with open(path, "r") as yaml_file:
data = yaml.safe_load(yaml_file)
# NOTE shouldn't this be defined as a top-level variable?
categories = [
("directories", DirectorySpec),
("volumes", VolumeSpec),
@ -23,6 +34,7 @@ def read_specs_file(path: Union[str, Path]) -> List[Spec]:
# Check what defaults are present
defaults = {}
if data.get("defaults"):
if data["defaults"].get("all"):
defaults = skeleton.merge(defaults, data["defaults"]["all"])

View File

@ -89,6 +89,9 @@ def merge_with_skeleton(data: Dict, skel: Dict) -> Dict:
data: dictionary containing the selected config values
skel: dictionary containing the skeleton (aka the def)
Returns:
a new dictionary representing the two merged dictionaries
Todo:
* Check if an infinite loop is possible
* Split info less complex functions