platform_setting.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. """
  2. All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. its licensors.
  4. For complete copyright and license terms please see the LICENSE at the root of this
  5. distribution (the "License"). All use of this software is governed by the License,
  6. or, if provided, by the license below or the license accompanying this file. Do not
  7. remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. Class for querying and setting a system setting/preference.
  10. """
  11. import pytest
  12. import logging
  13. from typing import Optional, Any
  14. import ly_test_tools.lumberyard.pipeline_utils as utils
  15. logger = logging.getLogger(__name__)
  16. class PlatformSetting:
  17. """
  18. Interface for managing different platforms' system variables.
  19. """
  20. class DATA_TYPE:
  21. """Platform-agnostic data type enums"""
  22. INT = 1
  23. STR = 2
  24. STR_LIST = 3
  25. def __init__(self, workspace: pytest.fixture, subkey: str, key: str) -> None:
  26. self._workspace = workspace
  27. self._key = key
  28. self._subkey = subkey
  29. def get_value(self, get_type: bool = False) -> object:
  30. """Gets the current setting's value (and optionally type as tuple) from the system. Returns None if entry DNE"""
  31. raise NotImplementedError("Virtual PlatformSetting not implemented. Instantiate a specific platform")
  32. def set_value(self, value: any) -> bool:
  33. """Sets the current setting's value. Creates the entry if it DNE. Returns True for success."""
  34. raise NotImplementedError("Virtual PlatformSetting not implemented. Instantiate a specific platform")
  35. def delete_entry(self) -> bool:
  36. """Deletes the settings entry. Returns boolean for success."""
  37. raise NotImplementedError("Virtual PlatformSetting not implemented. Instantiate a specific platform")
  38. def entry_exists(self) -> bool:
  39. """Checks if the settings entry exists."""
  40. raise NotImplementedError("Virtual PlatformSetting not implemented. Instantiate a specific platform")
  41. @staticmethod
  42. def get_system_setting(workspace: pytest.fixture, subkey: str, key: str, hive: Optional[str] = None) -> Any:
  43. """Factory method creates a platform-specific system setting accessor"""
  44. if workspace.asset_processor_platform == 'windows':
  45. # import WindowsSetting and return an instance
  46. from automatedtesting_shared.windows_registry_setting import WindowsRegistrySetting
  47. return WindowsRegistrySetting(workspace, subkey, key, hive)
  48. # ########################################################
  49. # Insert Mac (and Linux?) Setting implementations
  50. # ########################################################
  51. else:
  52. raise NotImplementedError(f"Platform: {workspace.platform} not supported yet")