test with methode for username
This commit is contained in:
parent
f4a51f0050
commit
ca26576eab
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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():
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user