Prereq checks introduced. And diagnostic steps on create profile.

This commit is contained in:
SimplifiedPrivacy 2026-11-09 11:55:33 -05:00
parent b396695721
commit fad5f99fb6
5 changed files with 82 additions and 4 deletions

View file

@ -62,7 +62,6 @@ class ProfileController:
# Get next id from the Repo, which confirms with what's on disk:
profile_id = ProfileController._repo.get_next_id()
logger.info(f"New profile id is {profile_id}")
# Create the object:
created_object = create_new_profile_object(profile_id=profile_id, potential_data=potential_data)

View file

@ -34,6 +34,9 @@ class ProfileRepository:
# Use the current cache to find a starting point for the next ID
next_id = max(self._cache.keys(), default=0) + 1
if next_id is None or next_id == 1:
return 1
while True:
try:
profile = model_manipulator.create_profile(next_id)

View file

@ -11,7 +11,7 @@ from core.models.system.SystemProfile import SystemProfile
from core.models.BaseProfile import ProfileType
from core.models.Result import Result, ResultError
from core.errors.logger import logger
# from core.utils.type_checker import type_checker
from core.utils.type_checker import type_checker
from typing import Optional
@ -34,7 +34,7 @@ def create_app_object_by_id(potential_data: dict) -> Result:
return Result(valid=True, data=application_version)
# @type_checker
@type_checker
def create_session_object(
profile_id: int,
potential_data: dict,
@ -75,7 +75,7 @@ def create_session_object(
return Result(valid=True, data=profile)
# @type_checker
@type_checker
def create_system_object(
profile_id: int,
potential_data: dict,
@ -104,6 +104,7 @@ def create_system_object(
def create_new_profile_object(profile_id: int, potential_data: dict) -> Result:
"""Creates and returns a brand new, literal profile object. (but not save to disk.)"""
logger.info(f"Creating a brand new profile object out of this data: {potential_data}.")
#---------------------------
# EXTRACT DATA
#---------------------------
@ -111,6 +112,7 @@ def create_new_profile_object(profile_id: int, potential_data: dict) -> Result:
protocol = potential_data.get('protocol', None)
ticket = potential_data.get('ticket', None)
raw_location = potential_data.get('location', None)
logger.info(f"The location is {raw_location}")
# already a location id:
if isinstance(raw_location, int):

View file

@ -137,6 +137,7 @@ def make_subscription_from_config(config_contents: dict) -> Subscription:
def create_profile_object_from_disk(profile_id: int) -> Result:
config_contents = read_profile_from_disk(profile_id)
logger.info(f"config_contents are {config_contents}")
if not config_contents:
return Result(valid=False, error_type=ResultError.MISSING_DATA, message="Missing the config")

View file

@ -0,0 +1,73 @@
from core.errors.logger import logger
import ctypes
from ctypes.util import find_library
import shutil
from enum import Enum
import subprocess
from typing import Optional
class LinuxDistro(Enum):
DEBIAN = "debian"
FEDORA = "fedora"
ARCH = "arch"
def diagnose_linux_distro() -> Optional[LinuxDistro]:
if shutil.which("apt") or shutil.which("apt-get"):
return LinuxDistro.DEBIAN
if shutil.which("dnf") or shutil.which("yum"):
return LinuxDistro.FEDORA
if shutil.which("pacman"):
return LinuxDistro.ARCH
return None
PRE_REQS = {
"libxcb-cursor0": {
LinuxDistro.DEBIAN: "sudo apt install libxcb-cursor0",
LinuxDistro.FEDORA: "sudo yum install xcb-util-cursor",
LinuxDistro.ARCH: "sudo pacman -S xcb-util-cursor"
}
}
def prompt_user_on_missing_package(package_name: str, distro_choice: Optional[LinuxDistro] = None):
logger.error(f"{package_name} is missing")
if distro_choice is None:
distro_choice = diagnose_linux_distro()
# Handle cases where the package is unknown or the distro is unsupported
if package_name not in PRE_REQS:
text_content = f"A required package ({package_name}) is missing, but no install command is defined for it."
elif distro_choice is None or distro_choice not in PRE_REQS[package_name]:
text_content = f"Cannot start because {package_name} is missing, and your Linux distribution is not supported."
else:
command = PRE_REQS[package_name][distro_choice]
text_content = f"Cannot start because a linux pre-req named {package_name} is missing.\n\nPlease run: {command}"
subprocess.run(['zenity', '--error', '--text', text_content])
def is_libxcb_cursor_available():
# find_library searches for the library using the system's default
# search paths and respects LD_LIBRARY_PATH
lib_path = find_library('xcb-cursor')
if not lib_path:
return False
try:
# Attempt to actually load the library into memory
ctypes.CDLL(lib_path)
return True
except OSError:
return False
def direct_filename_works() -> bool:
try:
ctypes.CDLL("libxcb-cursor.so.0")
logger.info("libxcb-cursor.so.0 Library found")
return True
except OSError:
logger.error("libxcb-cursor.so.0 Library missing")
return False