platform_setting.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. """
  2. Copyright (c) Contributors to the Open 3D Engine Project.
  3. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. Class for querying and setting a system setting/preference.
  6. """
  7. import pytest
  8. import logging
  9. from typing import Optional, Any
  10. import ly_test_tools.o3de.pipeline_utils as utils
  11. logger = logging.getLogger(__name__)
  12. class PlatformSetting:
  13. """
  14. Interface for managing different platforms' system variables.
  15. """
  16. class DATA_TYPE:
  17. """Platform-agnostic data type enums"""
  18. INT = 1
  19. STR = 2
  20. STR_LIST = 3
  21. def __init__(self, workspace: pytest.fixture, subkey: str, key: str) -> None:
  22. self._workspace = workspace
  23. self._key = key
  24. self._subkey = subkey
  25. def get_value(self, get_type: bool = False) -> object:
  26. """Gets the current setting's value (and optionally type as tuple) from the system. Returns None if entry DNE"""
  27. raise NotImplementedError("Virtual PlatformSetting not implemented. Instantiate a specific platform")
  28. def set_value(self, value: any) -> bool:
  29. """Sets the current setting's value. Creates the entry if it DNE. Returns True for success."""
  30. raise NotImplementedError("Virtual PlatformSetting not implemented. Instantiate a specific platform")
  31. def delete_entry(self) -> bool:
  32. """Deletes the settings entry. Returns boolean for success."""
  33. raise NotImplementedError("Virtual PlatformSetting not implemented. Instantiate a specific platform")
  34. def entry_exists(self) -> bool:
  35. """Checks if the settings entry exists."""
  36. raise NotImplementedError("Virtual PlatformSetting not implemented. Instantiate a specific platform")
  37. @staticmethod
  38. def get_system_setting(workspace: pytest.fixture, subkey: str, key: str, hive: Optional[str] = None) -> Any:
  39. """Factory method creates a platform-specific system setting accessor"""
  40. if workspace.asset_processor_platform == 'windows':
  41. # import WindowsSetting and return an instance
  42. from automatedtesting_shared.windows_registry_setting import WindowsRegistrySetting
  43. return WindowsRegistrySetting(workspace, subkey, key, hive)
  44. # ########################################################
  45. # Insert Mac (and Linux?) Setting implementations
  46. # ########################################################
  47. else:
  48. raise NotImplementedError(f"Platform: {workspace.platform} not supported yet")