From: Andrej Shadura Date: Tue, 12 Jan 2021 14:55:49 +0100 Subject: Add an xdg 5 compatibility layer --- xdg/__init__.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/xdg/__init__.py b/xdg/__init__.py index a417f61..f41c87b 100644 --- a/xdg/__init__.py +++ b/xdg/__init__.py @@ -1,3 +1,39 @@ __all__ = [ "BaseDirectory", "DesktopEntry", "Menu", "Exceptions", "IniFile", "IconTheme", "Locale", "Config", "Mime", "RecentFiles", "MenuEditor" ] __version__ = "0.28" + +# Compatibility with xdg 5 + +from pathlib import Path +from typing import Optional, List +import os + +from . import BaseDirectory + +def xdg_cache_home() -> Path: + return Path(BaseDirectory.xdg_cache_home) + +def xdg_config_dirs() -> List[Path]: + return [Path(path) for path in BaseDirectory.xdg_config_dirs] + +def xdg_config_home() -> Path: + return Path(BaseDirectory.xdg_config_home) + +def xdg_data_dirs() -> List[Path]: + return [Path(path) for path in BaseDirectory.xdg_data_dirs] + +def xdg_data_home() -> Path: + return Path(BaseDirectory.xdg_data_home) + +def xdg_runtime_dir() -> Optional[Path]: + try: + return Path(os.environ['XDG_RUNTIME_DIR']) + except KeyError: + return None + +XDG_CACHE_HOME = xdg_cache_home() +XDG_CONFIG_DIRS = xdg_config_dirs() +XDG_CONFIG_HOME = xdg_config_home() +XDG_DATA_DIRS = xdg_data_dirs() +XDG_DATA_HOME = xdg_data_home() +XDG_RUNTIME_DIR = xdg_runtime_dir()