mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-02 00:44:52 +01:00
override states are now int based objects
This commit is contained in:
parent
a08721b5b4
commit
e095b0e35b
1 changed files with 53 additions and 8 deletions
|
|
@ -1,6 +1,3 @@
|
|||
import enum
|
||||
|
||||
|
||||
# Metadata keys for work with studio and project overrides
|
||||
M_OVERRIDEN_KEY = "__overriden_keys__"
|
||||
# Metadata key for storing information about environments
|
||||
|
|
@ -34,8 +31,56 @@ __all__ = (
|
|||
)
|
||||
|
||||
|
||||
class OverrideState(enum.Enum):
|
||||
NOT_DEFINED = object()
|
||||
DEFAULTS = object()
|
||||
STUDIO = object()
|
||||
PROJECT = object()
|
||||
class OverrideStateItem:
|
||||
values = set()
|
||||
|
||||
def __init__(self, value, name):
|
||||
self.name = name
|
||||
if value in self.__class__.values:
|
||||
raise ValueError(
|
||||
"Implementation bug: Override State with same value as other."
|
||||
)
|
||||
self.__class__.values.add(value)
|
||||
self.value = value
|
||||
|
||||
def __repr__(self):
|
||||
return "<object {}> {} {}".format(
|
||||
self.__class__.__name__, self.value, self.name
|
||||
)
|
||||
|
||||
def __eq__(self, other):
|
||||
"""Defines behavior for the equality operator, ==."""
|
||||
if isinstance(other, OverrideStateItem):
|
||||
return self.value == other.value
|
||||
return self.value == other
|
||||
|
||||
def __gt__(self, other):
|
||||
"""Defines behavior for the greater-than operator, >."""
|
||||
if isinstance(other, OverrideStateItem):
|
||||
return self.value > other.value
|
||||
return self.value > other
|
||||
|
||||
def __lt__(self, other):
|
||||
"""Defines behavior for the less-than operator, <."""
|
||||
if isinstance(other, OverrideStateItem):
|
||||
return self.value < other.value
|
||||
return self.value < other
|
||||
|
||||
def __le__(self, other):
|
||||
"""Defines behavior for the less-than-or-equal-to operator, <=."""
|
||||
return self.__eq__(other) or self.__lt__(other)
|
||||
|
||||
def __ge__(self, other):
|
||||
"""Defines behavior for the greater-than-or-equal-to operator, >=."""
|
||||
return self.__eq__(other) or self.__gt__(other)
|
||||
|
||||
|
||||
class OverrideState:
|
||||
"""Enumeration of override states.
|
||||
|
||||
Each state should have unique value.
|
||||
"""
|
||||
NOT_DEFINED = OverrideStateItem(-1, "Not defined")
|
||||
DEFAULTS = OverrideStateItem(0, "Defaults")
|
||||
STUDIO = OverrideStateItem(1, "Studio overrides")
|
||||
PROJECT = OverrideStateItem(2, "Project Overrides")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue