mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-05-30 01:16:33 +02:00
[core] Introducing new graphIO module
Move Graph.IO internal class to its own module, and rename it to `GraphIO`. This avoid nested classes within the core Graph class, and starts decoupling the management of graph's IO from the logic of the graph itself.
This commit is contained in:
parent
3064cb9b35
commit
a665200c38
4 changed files with 76 additions and 63 deletions
56
meshroom/core/graphIO.py
Normal file
56
meshroom/core/graphIO.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
from enum import Enum
|
||||
from typing import Union
|
||||
|
||||
from meshroom.core import Version
|
||||
|
||||
|
||||
class GraphIO:
|
||||
"""Centralize Graph file keys and IO version."""
|
||||
|
||||
__version__ = "2.0"
|
||||
|
||||
class Keys(object):
|
||||
"""File Keys."""
|
||||
|
||||
# Doesn't inherit enum to simplify usage (GraphIO.Keys.XX, without .value)
|
||||
Header = "header"
|
||||
NodesVersions = "nodesVersions"
|
||||
ReleaseVersion = "releaseVersion"
|
||||
FileVersion = "fileVersion"
|
||||
Graph = "graph"
|
||||
|
||||
class Features(Enum):
|
||||
"""File Features."""
|
||||
|
||||
Graph = "graph"
|
||||
Header = "header"
|
||||
NodesVersions = "nodesVersions"
|
||||
PrecomputedOutputs = "precomputedOutputs"
|
||||
NodesPositions = "nodesPositions"
|
||||
|
||||
@staticmethod
|
||||
def getFeaturesForVersion(fileVersion: Union[str, Version]) -> tuple["GraphIO.Features",...]:
|
||||
"""Return the list of supported features based on a file version.
|
||||
|
||||
Args:
|
||||
fileVersion (str, Version): the file version
|
||||
|
||||
Returns:
|
||||
tuple of GraphIO.Features: the list of supported features
|
||||
"""
|
||||
if isinstance(fileVersion, str):
|
||||
fileVersion = Version(fileVersion)
|
||||
|
||||
features = [GraphIO.Features.Graph]
|
||||
if fileVersion >= Version("1.0"):
|
||||
features += [
|
||||
GraphIO.Features.Header,
|
||||
GraphIO.Features.NodesVersions,
|
||||
GraphIO.Features.PrecomputedOutputs,
|
||||
]
|
||||
|
||||
if fileVersion >= Version("1.1"):
|
||||
features += [GraphIO.Features.NodesPositions]
|
||||
|
||||
return tuple(features)
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue