forked from AG_QGIS/Plugin_SN_Basis
78 lines
1.7 KiB
Python
78 lines
1.7 KiB
Python
|
|
"""
|
|||
|
|
sn_basis/functions/os_wrapper.py – Betriebssystem-Abstraktion
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
from pathlib import Path
|
|||
|
|
import platform
|
|||
|
|
from typing import Union
|
|||
|
|
|
|||
|
|
|
|||
|
|
# ---------------------------------------------------------
|
|||
|
|
# OS-Erkennung
|
|||
|
|
# ---------------------------------------------------------
|
|||
|
|
|
|||
|
|
_SYSTEM = platform.system().lower()
|
|||
|
|
|
|||
|
|
if _SYSTEM.startswith("win"):
|
|||
|
|
OS_NAME = "windows"
|
|||
|
|
elif _SYSTEM.startswith("darwin"):
|
|||
|
|
OS_NAME = "macos"
|
|||
|
|
else:
|
|||
|
|
OS_NAME = "linux"
|
|||
|
|
|
|||
|
|
IS_WINDOWS = OS_NAME == "windows"
|
|||
|
|
IS_LINUX = OS_NAME == "linux"
|
|||
|
|
IS_MACOS = OS_NAME == "macos"
|
|||
|
|
|
|||
|
|
|
|||
|
|
# ---------------------------------------------------------
|
|||
|
|
# OS-Eigenschaften
|
|||
|
|
# ---------------------------------------------------------
|
|||
|
|
|
|||
|
|
PATH_SEPARATOR = "\\" if IS_WINDOWS else "/"
|
|||
|
|
LINE_SEPARATOR = "\r\n" if IS_WINDOWS else "\n"
|
|||
|
|
|
|||
|
|
|
|||
|
|
# ---------------------------------------------------------
|
|||
|
|
# Pfad-Utilities
|
|||
|
|
# ---------------------------------------------------------
|
|||
|
|
|
|||
|
|
_PathLike = Union[str, Path]
|
|||
|
|
|
|||
|
|
|
|||
|
|
def normalize_path(path: _PathLike) -> Path:
|
|||
|
|
"""
|
|||
|
|
Normalisiert einen Pfad OS-unabhängig.
|
|||
|
|
"""
|
|||
|
|
try:
|
|||
|
|
return Path(path).expanduser().resolve()
|
|||
|
|
except Exception:
|
|||
|
|
return Path(path)
|
|||
|
|
|
|||
|
|
|
|||
|
|
def get_home_dir() -> Path:
|
|||
|
|
"""
|
|||
|
|
Liefert das Home-Verzeichnis des aktuellen Users.
|
|||
|
|
"""
|
|||
|
|
return Path.home()
|
|||
|
|
|
|||
|
|
|
|||
|
|
# ---------------------------------------------------------
|
|||
|
|
# Dateisystem-Eigenschaften
|
|||
|
|
# ---------------------------------------------------------
|
|||
|
|
|
|||
|
|
def is_case_sensitive_fs() -> bool:
|
|||
|
|
"""
|
|||
|
|
Gibt zurück, ob das Dateisystem case-sensitiv ist.
|
|||
|
|
"""
|
|||
|
|
# Windows ist immer case-insensitive
|
|||
|
|
if IS_WINDOWS:
|
|||
|
|
return False
|
|||
|
|
|
|||
|
|
# macOS meist case-insensitive, aber nicht garantiert
|
|||
|
|
if IS_MACOS:
|
|||
|
|
return False
|
|||
|
|
|
|||
|
|
# Linux praktisch immer case-sensitiv
|
|||
|
|
return True
|