forked from Support/sp-hydra-veil-gui
65 lines
No EOL
2 KiB
Python
Executable file
65 lines
No EOL
2 KiB
Python
Executable file
from core.models.session.SessionProfile import SessionProfile
|
|
from core.models.system.SystemProfile import SystemProfile
|
|
from core.controllers.ProfileController import ProfileController
|
|
from core.models.BaseProfile import BaseProfile
|
|
|
|
# not currently used, but can be added:
|
|
# application_version_observer,
|
|
# client_observer,
|
|
# invoice_observer,
|
|
|
|
from gui.v2.infrastructure.setup_observers import (
|
|
connection_observer,
|
|
profile_observer,
|
|
ticket_observer,
|
|
)
|
|
|
|
import inspect
|
|
|
|
def filter_profiles_by_type(profile_data: list) -> tuple:
|
|
"""
|
|
Purpose:
|
|
Isolate system and session profiles into separate lists
|
|
Why:
|
|
Session profiles must be disabled first before System profiles.
|
|
Called by:
|
|
worker_thread's disable_all_profiles
|
|
"""
|
|
system_profiles = []
|
|
session_profiles = []
|
|
for profile_id in profile_data:
|
|
profile = ProfileController.get(int(profile_id))
|
|
|
|
if isinstance(profile, SessionProfile):
|
|
session_profiles.append(profile)
|
|
|
|
elif isinstance(profile, SystemProfile):
|
|
system_profiles.append(profile)
|
|
|
|
else:
|
|
print(f"Skipping/discarding unknown profile {profile_id} type {type(profile)} full info: {profile}")
|
|
|
|
return session_profiles, system_profiles
|
|
|
|
|
|
def disable_profile_via_controller(profile: BaseProfile):
|
|
"""
|
|
Purpose:
|
|
Disable a profile via the controller
|
|
Why:
|
|
Inspect signature deals with changing observers
|
|
Called by:
|
|
worker_thread's disable_all_profiles
|
|
"""
|
|
kwargs = {
|
|
'profile_observer': profile_observer,
|
|
'ticket_observer': ticket_observer,
|
|
'connection_observer': connection_observer,
|
|
}
|
|
supported = inspect.signature(ProfileController.disable).parameters
|
|
ProfileController.disable(
|
|
profile,
|
|
**{key: value for key, value in kwargs.items() if key in supported}
|
|
)
|
|
|
|
# We return nothing, because core signals via observers for success. And raises errors for failure. |