diff options
Diffstat (limited to 'py_modules/lsfg_vk/configuration.py')
| -rw-r--r-- | py_modules/lsfg_vk/configuration.py | 45 |
1 files changed, 1 insertions, 44 deletions
diff --git a/py_modules/lsfg_vk/configuration.py b/py_modules/lsfg_vk/configuration.py index b61a06d..13fa925 100644 --- a/py_modules/lsfg_vk/configuration.py +++ b/py_modules/lsfg_vk/configuration.py @@ -22,9 +22,7 @@ class ConfigurationService(BaseService): ConfigurationResponse with current configuration or error """ try: - # Get TOML configuration (with defaults if file doesn't exist) if not self.config_file_path.exists(): - # Return default configuration with DLL detection if file doesn't exist from .dll_detection import DllDetectionService dll_service = DllDetectionService(self.log) toml_config = ConfigurationManager.get_defaults_with_dll_detection(dll_service) @@ -32,7 +30,6 @@ class ConfigurationService(BaseService): content = self.config_file_path.read_text(encoding='utf-8') toml_config = ConfigurationManager.parse_toml_content(content) - # Get script environment variables (if script exists) script_values = {} if self.lsfg_script_path.exists(): try: @@ -42,7 +39,6 @@ class ConfigurationService(BaseService): except Exception as e: self.log.warning(f"Failed to parse launch script: {str(e)}") - # Merge TOML config with script values config = ConfigurationManager.merge_config_with_script(toml_config, script_values) return self._success_response(ConfigurationResponse, config=config) @@ -54,7 +50,6 @@ class ConfigurationService(BaseService): except Exception as e: error_msg = f"Error parsing config file: {str(e)}" self.log.error(error_msg) - # Return defaults with DLL detection if parsing fails from .dll_detection import DllDetectionService dll_service = DllDetectionService(self.log) config = ConfigurationManager.get_defaults_with_dll_detection(dll_service) @@ -75,7 +70,6 @@ class ConfigurationService(BaseService): profile_data = self._get_profile_data() current_profile = profile_data["current_profile"] - # Update the current profile's config return self.update_profile_config(current_profile, config) except (OSError, IOError) as e: @@ -97,10 +91,8 @@ class ConfigurationService(BaseService): ConfigurationResponse with success status """ try: - # Create configuration from keyword arguments using generated function config = ConfigurationManager.create_config_from_args(**kwargs) - # Update using the new profile-aware method return self.update_config_from_dict(config) except (OSError, IOError) as e: @@ -124,18 +116,14 @@ class ConfigurationService(BaseService): try: profile_data = self._get_profile_data() - # Update global config (DLL path is global) profile_data["global_config"]["dll"] = dll_path - # Also update current profile's config for backward compatibility current_profile = profile_data["current_profile"] from .config_schema_generated import DLL profile_data["profiles"][current_profile][DLL] = dll_path - # Save to file self._save_profile_data(profile_data) - # Update launch script script_result = self.update_lsfg_script_from_profile_data(profile_data) if not script_result["success"]: self.log.warning(f"Failed to update launch script: {script_result['error']}") @@ -163,7 +151,6 @@ class ConfigurationService(BaseService): try: script_content = self._generate_script_content(config) - # Write the script file self._write_file(self.lsfg_script_path, script_content, 0o755) self.log.info(f"Updated lsfg launch script at {self.lsfg_script_path}") @@ -188,15 +175,11 @@ class ConfigurationService(BaseService): """ lines = [ "#!/bin/bash", - "# lsfg-vk launch script generated by decky-lossless-scaling-vk plugin", - "# This script sets up the environment for lsfg-vk to work with the plugin configuration" ] - # Use auto-generated script generation logic generate_script_lines = get_script_generation_logic() lines.extend(generate_script_lines(config)) - # Always add the LSFG_PROCESS export and execution line lines.extend([ "export LSFG_PROCESS=decky-lsfg-vk", 'exec "$@"' @@ -216,23 +199,18 @@ class ConfigurationService(BaseService): current_profile = profile_data["current_profile"] config = profile_data["profiles"].get(current_profile, ConfigurationManager.get_defaults()) - # Merge global config with profile config merged_config = dict(config) for field_name, value in profile_data["global_config"].items(): merged_config[field_name] = value lines = [ "#!/bin/bash", - "# lsfg-vk launch script generated by decky-lossless-scaling-vk plugin", f"# Current profile: {current_profile}", - "# This script sets up the environment for lsfg-vk to work with the plugin configuration" ] - # Use auto-generated script generation logic generate_script_lines = get_script_generation_logic() lines.extend(generate_script_lines(merged_config)) - # Export LSFG_PROCESS with current profile name lines.extend([ f"export LSFG_PROCESS={current_profile}", 'exec "$@"' @@ -243,7 +221,6 @@ class ConfigurationService(BaseService): def _get_profile_data(self) -> ProfileData: """Get current profile data from config file""" if not self.config_file_path.exists(): - # Return default profile structure if file doesn't exist from .dll_detection import DllDetectionService dll_service = DllDetectionService(self.log) default_config = ConfigurationManager.get_defaults_with_dll_detection(dll_service) @@ -263,13 +240,10 @@ class ConfigurationService(BaseService): """Save profile data to config file""" toml_content = ConfigurationManager.generate_toml_content_multi_profile(profile_data) - # Ensure config directory exists self.config_dir.mkdir(parents=True, exist_ok=True) - # Write the updated config directly to preserve inode for file watchers self._write_file(self.config_file_path, toml_content, 0o644) - # Profile management methods def get_profiles(self) -> ProfilesResponse: """Get list of all profiles and current profile @@ -303,14 +277,11 @@ class ConfigurationService(BaseService): try: profile_data = self._get_profile_data() - # Use current profile as source if not specified if not source_profile: source_profile = profile_data["current_profile"] - # Create the new profile new_profile_data = ConfigurationManager.create_profile(profile_data, profile_name, source_profile) - # Save to file self._save_profile_data(new_profile_data) self.log.info(f"Created profile '{profile_name}' from '{source_profile}'") @@ -340,13 +311,10 @@ class ConfigurationService(BaseService): try: profile_data = self._get_profile_data() - # Delete the profile new_profile_data = ConfigurationManager.delete_profile(profile_data, profile_name) - # Save to file self._save_profile_data(new_profile_data) - # Update launch script if current profile changed script_result = self.update_lsfg_script_from_profile_data(new_profile_data) if not script_result["success"]: self.log.warning(f"Failed to update launch script: {script_result['error']}") @@ -379,13 +347,10 @@ class ConfigurationService(BaseService): try: profile_data = self._get_profile_data() - # Rename the profile new_profile_data = ConfigurationManager.rename_profile(profile_data, old_name, new_name) - # Save to file self._save_profile_data(new_profile_data) - # Update launch script if current profile changed script_result = self.update_lsfg_script_from_profile_data(new_profile_data) if not script_result["success"]: self.log.warning(f"Failed to update launch script: {script_result['error']}") @@ -417,13 +382,10 @@ class ConfigurationService(BaseService): try: profile_data = self._get_profile_data() - # Set current profile new_profile_data = ConfigurationManager.set_current_profile(profile_data, profile_name) - # Save to file self._save_profile_data(new_profile_data) - # Update launch script with new current profile script_result = self.update_lsfg_script_from_profile_data(new_profile_data) if not script_result["success"]: self.log.warning(f"Failed to update launch script: {script_result['error']}") @@ -461,24 +423,19 @@ class ConfigurationService(BaseService): f"Profile '{profile_name}' does not exist", config=None) - # Update the profile's config - profile_data["profiles"][profile_name] = config + new_profile_data = ConfigurationManager.update_profile_config(profile_data, profile_name, config) - # Update global config fields if they're in the config for field_name in ["dll", "no_fp16"]: if field_name in config: profile_data["global_config"][field_name] = config[field_name] - # Save to file self._save_profile_data(profile_data) - # Update launch script if this is the current profile if profile_name == profile_data["current_profile"]: script_result = self.update_lsfg_script_from_profile_data(profile_data) if not script_result["success"]: self.log.warning(f"Failed to update launch script: {script_result['error']}") - # Log with dynamic field listing field_values = ", ".join(f"{k}={repr(v)}" for k, v in config.items()) self.log.info(f"Updated profile '{profile_name}' configuration: {field_values}") |
