| 1 |
From: Andrej Shadura <[email protected]> |
| 2 |
Date: Tue, 12 Jan 2021 14:55:49 +0100 |
| 3 |
Subject: Add an xdg 5 compatibility layer |
| 4 |
|
| 5 |
--- |
| 6 |
xdg/__init__.py | 36 ++++++++++++++++++++++++++++++++++++ |
| 7 |
1 file changed, 36 insertions(+) |
| 8 |
|
| 9 |
diff --git a/xdg/__init__.py b/xdg/__init__.py |
| 10 |
index a417f61..f41c87b 100644 |
| 11 |
--- a/xdg/__init__.py |
| 12 |
+++ b/xdg/__init__.py |
| 13 |
@@ -1,3 +1,39 @@ |
| 14 |
__all__ = [ "BaseDirectory", "DesktopEntry", "Menu", "Exceptions", "IniFile", "IconTheme", "Locale", "Config", "Mime", "RecentFiles", "MenuEditor" ] |
| 15 |
|
| 16 |
__version__ = "0.28" |
| 17 |
+ |
| 18 |
+# Compatibility with xdg 5 |
| 19 |
+ |
| 20 |
+from pathlib import Path |
| 21 |
+from typing import Optional, List |
| 22 |
+import os |
| 23 |
+ |
| 24 |
+from . import BaseDirectory |
| 25 |
+ |
| 26 |
+def xdg_cache_home() -> Path: |
| 27 |
+ return Path(BaseDirectory.xdg_cache_home) |
| 28 |
+ |
| 29 |
+def xdg_config_dirs() -> List[Path]: |
| 30 |
+ return [Path(path) for path in BaseDirectory.xdg_config_dirs] |
| 31 |
+ |
| 32 |
+def xdg_config_home() -> Path: |
| 33 |
+ return Path(BaseDirectory.xdg_config_home) |
| 34 |
+ |
| 35 |
+def xdg_data_dirs() -> List[Path]: |
| 36 |
+ return [Path(path) for path in BaseDirectory.xdg_data_dirs] |
| 37 |
+ |
| 38 |
+def xdg_data_home() -> Path: |
| 39 |
+ return Path(BaseDirectory.xdg_data_home) |
| 40 |
+ |
| 41 |
+def xdg_runtime_dir() -> Optional[Path]: |
| 42 |
+ try: |
| 43 |
+ return Path(os.environ['XDG_RUNTIME_DIR']) |
| 44 |
+ except KeyError: |
| 45 |
+ return None |
| 46 |
+ |
| 47 |
+XDG_CACHE_HOME = xdg_cache_home() |
| 48 |
+XDG_CONFIG_DIRS = xdg_config_dirs() |
| 49 |
+XDG_CONFIG_HOME = xdg_config_home() |
| 50 |
+XDG_DATA_DIRS = xdg_data_dirs() |
| 51 |
+XDG_DATA_HOME = xdg_data_home() |
| 52 |
+XDG_RUNTIME_DIR = xdg_runtime_dir() |