mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
Merge remote-tracking branch 'origin/feature/909-define-basic-trait-type-using-dataclasses' into feature/911-new-traits-based-integrator
This commit is contained in:
commit
228cde58cd
2 changed files with 36 additions and 0 deletions
|
|
@ -170,3 +170,20 @@ class UDIM(TraitBase):
|
|||
if udim_index == udim:
|
||||
return location
|
||||
return None
|
||||
|
||||
def get_udim_from_file_location(
|
||||
self, file_location: FileLocation) -> Optional[int]:
|
||||
"""Get UDIM from file location.
|
||||
|
||||
Args:
|
||||
file_location (FileLocation): File location.
|
||||
|
||||
Returns:
|
||||
Optional[int]: UDIM value.
|
||||
|
||||
"""
|
||||
pattern = re.compile(self.udim_regex)
|
||||
result = re.search(pattern, file_location.file_path.name)
|
||||
if result:
|
||||
return int(result.group("udim"))
|
||||
return None
|
||||
|
|
|
|||
|
|
@ -41,3 +41,22 @@ def test_get_file_location_for_udim() -> None:
|
|||
file_locations=representation.get_trait(FileLocations),
|
||||
udim=1001
|
||||
) == file_locations_list[0]
|
||||
|
||||
def test_get_udim_from_file_location() -> None:
|
||||
"""Test get_udim_from_file_location."""
|
||||
file_location_1 = FileLocation(
|
||||
file_path=Path("/path/to/file.1001.exr"),
|
||||
file_size=1024,
|
||||
file_hash=None,
|
||||
)
|
||||
|
||||
file_location_2 = FileLocation(
|
||||
file_path=Path("/path/to/file.xxxxx.exr"),
|
||||
file_size=1024,
|
||||
file_hash=None,
|
||||
)
|
||||
assert UDIM(udim=[1001]).get_udim_from_file_location(
|
||||
file_location_1) == 1001
|
||||
|
||||
assert UDIM(udim=[1001]).get_udim_from_file_location(
|
||||
file_location_2) is None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue