From a23e0eb12cb620b32be19c569d6ee0660f4b9d05 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Wed, 19 Mar 2025 12:09:01 +0100 Subject: [PATCH] yaml --- rwx/fs/__init__.py | 14 ++++++++++++++ rwx/sw/ytdlp/__init__.py | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/rwx/fs/__init__.py b/rwx/fs/__init__.py index 1873da2..b55713a 100644 --- a/rwx/fs/__init__.py +++ b/rwx/fs/__init__.py @@ -3,6 +3,7 @@ import os import shutil import tomllib +import yaml from pathlib import Path 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) +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: """Wipe provided path, whether directory or file. diff --git a/rwx/sw/ytdlp/__init__.py b/rwx/sw/ytdlp/__init__.py index 69a5ede..29a4305 100644 --- a/rwx/sw/ytdlp/__init__.py +++ b/rwx/sw/ytdlp/__init__.py @@ -7,7 +7,7 @@ from typing import Any from yt_dlp import YoutubeDL 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 TIMESTAMP = "%Y%m%d%H%M%S" @@ -28,7 +28,7 @@ class Cache(Object): self.load() def load(self) -> None: - d = read_file_dict(self.root_file) + d = read_file_yaml(self.root_file) log.info(d)