test with methode for username

This commit is contained in:
Désiré Werner Menrath 2025-05-07 22:42:08 +02:00
parent f4a51f0050
commit ca26576eab
4 changed files with 36 additions and 8 deletions

View File

@ -591,6 +591,36 @@ class ConfigManager:
config = cls.load()
return config.get(key, default)
@property
def username(self) -> str:
"""
Returns the username of the logged-in user,
even if the script is running with root privileges.
Returns:
str: The username of the logged-in user
"""
import os
from pathlib import Path
# Versuche zuerst SUDO_USER zu bekommen
sudo_user = os.environ.get("SUDO_USER")
if sudo_user:
return sudo_user
# Extrahiere aus Path.home()
home_path = str(Path.home())
if "/home/" in home_path:
return home_path.split("/home/")[1].split("/")[0]
# Fallbacks
try:
return os.getlogin()
except:
import getpass
return getpass.getuser()
class ThemeManager:
@staticmethod

View File

@ -6,11 +6,9 @@ import shutil
from pathlib import Path
from subprocess import check_call
from wp_app_config import AppConfig
from common_tools import ConfigManager
uname: Path = Path("/tmp/.log_user")
log_name = Path(uname).read_text(encoding="utf-8")
log_name: str = ConfigManager.username()
keyfile: Path = Path(f"/home/{log_name}/.config/wire_py/pbwgk.pem")
# PKEYFILE: Path = "/usr/local/etc/ssl/pwgk.pem"

View File

@ -7,11 +7,11 @@ from pathlib import Path
from subprocess import check_call
from common_tools import LxTools
from wp_app_config import AppConfig
from common_tools import ConfigManager
log_name = ConfigManager.username()
keyfile: Path = Path(
f"/home/{AppConfig.USER_FILE.read_text(encoding="utf-8")}/.config/wire_py/pbwgk.pem"
)
keyfile: Path = Path(f"/home/{log_name}/.config/wire_py/pbwgk.pem")
if not keyfile.is_file():

View File

@ -23,7 +23,7 @@ from common_tools import (
)
from wp_app_config import AppConfig, Msg
LxTools.uos()
Create.dir_and_files()
Create.make_dir()
Create.decrypt()