mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
🎨 add get padding from files
This commit is contained in:
parent
fc30b854f0
commit
13e56429ba
2 changed files with 38 additions and 2 deletions
|
|
@ -4,11 +4,15 @@ from __future__ import annotations
|
||||||
from enum import Enum, auto
|
from enum import Enum, auto
|
||||||
from typing import TYPE_CHECKING, ClassVar, Optional
|
from typing import TYPE_CHECKING, ClassVar, Optional
|
||||||
|
|
||||||
|
import clique
|
||||||
from pydantic import Field
|
from pydantic import Field
|
||||||
|
|
||||||
from .trait import MissingTraitError, TraitBase
|
from .trait import MissingTraitError, TraitBase
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from .content import FileLocations
|
||||||
from .representation import Representation
|
from .representation import Representation
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -141,6 +145,21 @@ class Sequence(TraitBase):
|
||||||
except MissingTraitError:
|
except MissingTraitError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_frame_padding(file_locations: FileLocations) -> int:
|
||||||
|
"""Get frame padding."""
|
||||||
|
files: list[Path] = [
|
||||||
|
file.file_path.as_posix()
|
||||||
|
for file in file_locations.file_paths
|
||||||
|
]
|
||||||
|
src_collections, _ = clique.assemble(files)
|
||||||
|
|
||||||
|
src_collection = src_collections[0]
|
||||||
|
destination_indexes = list(src_collection.indexes)
|
||||||
|
# Use last frame for minimum padding
|
||||||
|
# - that should cover both 'udim' and 'frame' minimum padding
|
||||||
|
return len(str(destination_indexes[-1]))
|
||||||
|
|
||||||
# Do we need one for drop and non-drop frame?
|
# Do we need one for drop and non-drop frame?
|
||||||
class SMPTETimecode(TraitBase):
|
class SMPTETimecode(TraitBase):
|
||||||
"""SMPTE Timecode trait model."""
|
"""SMPTE Timecode trait model."""
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ from ayon_core.pipeline.traits import (
|
||||||
PixelBased,
|
PixelBased,
|
||||||
Planar,
|
Planar,
|
||||||
Representation,
|
Representation,
|
||||||
|
Sequence,
|
||||||
TraitBase,
|
TraitBase,
|
||||||
)
|
)
|
||||||
from ayon_core.pipeline.traits.trait import TraitValidationError
|
from ayon_core.pipeline.traits.trait import TraitValidationError
|
||||||
|
|
@ -358,7 +359,6 @@ def test_file_locations_validation() -> None:
|
||||||
sequence_trait = FrameRanged(
|
sequence_trait = FrameRanged(
|
||||||
frame_start=1001,
|
frame_start=1001,
|
||||||
frame_end=1050,
|
frame_end=1050,
|
||||||
frame_padding=4,
|
|
||||||
frames_per_second="25"
|
frames_per_second="25"
|
||||||
)
|
)
|
||||||
representation.add_trait(sequence_trait)
|
representation.add_trait(sequence_trait)
|
||||||
|
|
@ -382,10 +382,27 @@ def test_file_locations_validation() -> None:
|
||||||
invalid_sequence_trait = FrameRanged(
|
invalid_sequence_trait = FrameRanged(
|
||||||
frame_start=1001,
|
frame_start=1001,
|
||||||
frame_end=1051,
|
frame_end=1051,
|
||||||
frame_padding=4,
|
|
||||||
frames_per_second="25"
|
frames_per_second="25"
|
||||||
)
|
)
|
||||||
|
|
||||||
representation.add_trait(invalid_sequence_trait)
|
representation.add_trait(invalid_sequence_trait)
|
||||||
with pytest.raises(TraitValidationError):
|
with pytest.raises(TraitValidationError):
|
||||||
file_locations_trait.validate(representation)
|
file_locations_trait.validate(representation)
|
||||||
|
|
||||||
|
def test_sequence_get_frame_padding() -> None:
|
||||||
|
"""Test getting frame padding from FileLocations trait."""
|
||||||
|
file_locations_list = [
|
||||||
|
FileLocation(
|
||||||
|
file_path=Path(f"/path/to/file.{frame}.exr"),
|
||||||
|
file_size=1024,
|
||||||
|
file_hash=None,
|
||||||
|
)
|
||||||
|
for frame in range(1001, 1051)
|
||||||
|
]
|
||||||
|
|
||||||
|
representation = Representation(name="test", traits=[
|
||||||
|
FileLocations(file_paths=file_locations_list)
|
||||||
|
])
|
||||||
|
|
||||||
|
assert Sequence.get_frame_padding(
|
||||||
|
file_locations=representation.get_trait(FileLocations)) == 4
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue