core: Replace legacy INI config system with Pydantic-based TOML configuration.
This is a huge configuration refactoring. The configuration system now uses Pydantic settings, with better validation, better support for environment variables and other goodies. The main config files now use TOML instead of INI, this allow for better handling of complex types, notably dict. Plugins, components and frontends can declare their config settings in a class which will be imported dynamically.
This commit is contained in:
parent
f3f40848b3
commit
6a7b7bc36a
1 changed files with 1392 additions and 1011 deletions
|
|
@ -17,8 +17,15 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""tools to help manipulating files"""
|
||||
import os.path
|
||||
from pathlib import Path
|
||||
|
||||
from libervia.backend.core.constants import xdg_config_home
|
||||
from libervia.backend.core.log import getLogger
|
||||
|
||||
|
||||
log = getLogger(__name__)
|
||||
|
||||
|
||||
def get_unique_name(path):
|
||||
"""Generate a path with a name not conflicting with existing file
|
||||
|
|
@ -32,3 +39,22 @@ def get_unique_name(path):
|
|||
path = ori_path.with_name(f"{ori_path.stem}_{idx}{ori_path.suffix}")
|
||||
idx += 1
|
||||
return path
|
||||
|
||||
|
||||
def get_downloads_dir() -> Path:
|
||||
"""Find XDG download dir."""
|
||||
dirs_file = xdg_config_home / "user-dirs.dirs"
|
||||
|
||||
try:
|
||||
with dirs_file.open("r") as f:
|
||||
for line in f:
|
||||
if line.startswith("XDG_DOWNLOAD_DIR"):
|
||||
path_str = line.split("=", 1)[1].strip().strip('"')
|
||||
# We use "expandvars" to expand $HOME.
|
||||
return Path(os.path.expandvars(path_str))
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
except Exception as e:
|
||||
log.warning(f"Can't read XDG user directories: {e}")
|
||||
|
||||
return Path.home() / "Downloads"
|
||||
|
|
|
|||
Loading…
Reference in a new issue