yaml
This commit is contained in:
parent
e43409d40c
commit
a23e0eb12c
2 changed files with 16 additions and 2 deletions
|
@ -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.
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue