This commit is contained in:
Marc Beninca 2025-03-19 12:09:01 +01:00
parent e43409d40c
commit a23e0eb12c
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F
2 changed files with 16 additions and 2 deletions

View file

@ -3,6 +3,7 @@
import os import os
import shutil import shutil
import tomllib import tomllib
import yaml
from pathlib import Path from pathlib import Path
from rwx import ps from rwx import ps
@ -132,6 +133,19 @@ def read_file_text(file_path: Path, charset: str = CHARSET) -> str:
return read_file_bytes(file_path).decode(charset) return read_file_bytes(file_path).decode(charset)
def read_file_yaml(file_path: Path, charset: str = CHARSET) -> dict | list:
"""Read whole file as yaml object.
:param file_path: source input file
:type file_path: Path
:param charset: charset to use for decoding input
:type charset: str
:rtype: dict
"""
text = read_file_text(file_path, charset)
return yaml.safe_load(text)
def wipe(path: Path) -> None: def wipe(path: Path) -> None:
"""Wipe provided path, whether directory or file. """Wipe provided path, whether directory or file.

View file

@ -7,7 +7,7 @@ from typing import Any
from yt_dlp import YoutubeDL from yt_dlp import YoutubeDL
from rwx import Object from rwx import Object
from rwx.fs import read_file_dict from rwx.fs import read_file_yaml
from rwx.log import stream as log from rwx.log import stream as log
TIMESTAMP = "%Y%m%d%H%M%S" TIMESTAMP = "%Y%m%d%H%M%S"
@ -28,7 +28,7 @@ class Cache(Object):
self.load() self.load()
def load(self) -> None: def load(self) -> None:
d = read_file_dict(self.root_file) d = read_file_yaml(self.root_file)
log.info(d) log.info(d)