|
1 | 1 | #!/usr/bin/env python
|
2 | 2 | # coding:utf-8
|
3 | 3 |
|
4 |
| -from meshroom.core import pipelineTemplates, Version |
| 4 | +from meshroom.core import unregisterNodeType, pipelineTemplates, Version |
5 | 5 | from meshroom.core.node import CompatibilityIssue, CompatibilityNode
|
6 | 6 | from meshroom.core.graphIO import GraphIO
|
7 | 7 |
|
8 | 8 | import meshroom
|
9 | 9 |
|
10 | 10 | import json
|
11 | 11 |
|
12 |
| -def checkTemplateVersions(path: str) -> bool: |
| 12 | +def checkTemplateVersions(path: str, nodesAlreadyLoaded: bool = False) -> bool: |
13 | 13 | """ Check whether there is a compatibility issue with the nodes saved in the template provided with "path". """
|
14 |
| - meshroom.core.initNodes() |
| 14 | + if not nodesAlreadyLoaded: |
| 15 | + meshroom.core.initNodes() |
15 | 16 |
|
16 | 17 | with open(path) as jsonFile:
|
17 | 18 | fileData = json.load(jsonFile)
|
18 | 19 |
|
19 |
| - graphData = fileData.get(GraphIO.Keys.Graph, fileData) |
20 |
| - if not isinstance(graphData, dict): |
21 |
| - return False |
22 |
| - |
23 |
| - header = fileData.get(GraphIO.Keys.Header, {}) |
24 |
| - if not header.get("template", False): |
25 |
| - return False |
26 |
| - nodesVersions = header.get(GraphIO.Keys.NodesVersions, {}) |
27 |
| - |
28 |
| - for _, nodeData in graphData.items(): |
29 |
| - nodeType = nodeData["nodeType"] |
30 |
| - if not nodeType in meshroom.core.nodesDesc: |
| 20 | + try: |
| 21 | + graphData = fileData.get(GraphIO.Keys.Graph, fileData) |
| 22 | + if not isinstance(graphData, dict): |
31 | 23 | return False
|
32 | 24 |
|
33 |
| - nodeDesc = meshroom.core.nodesDesc[nodeType] |
34 |
| - currentNodeVersion = meshroom.core.nodeVersion(nodeDesc) |
35 |
| - |
36 |
| - inputs = nodeData.get("inputs", {}) |
37 |
| - internalInputs = nodeData.get("internalInputs", {}) |
38 |
| - version = nodesVersions.get(nodeType, None) |
39 |
| - |
40 |
| - compatibilityIssue = None |
41 |
| - |
42 |
| - if version and currentNodeVersion and Version(version).major != Version(currentNodeVersion).major: |
43 |
| - compatibilityIssue = CompatibilityIssue.VersionConflict |
44 |
| - else: |
45 |
| - for attrName, value in inputs.items(): |
46 |
| - if not CompatibilityNode.attributeDescFromName(nodeDesc.inputs, attrName, value): |
47 |
| - compatibilityIssue = CompatibilityIssue.DescriptionConflict |
48 |
| - break |
49 |
| - for attrName, value in internalInputs.items(): |
50 |
| - if not CompatibilityNode.attributeDescFromName(nodeDesc.internalInputs, attrName, value): |
51 |
| - compatibilityIssue = CompatibilityIssue.DescriptionConflict |
52 |
| - break |
53 |
| - |
54 |
| - if compatibilityIssue is not None: |
55 |
| - print("{} in {} for node {}".format(compatibilityIssue, path, nodeType)) |
| 25 | + header = fileData.get(GraphIO.Keys.Header, {}) |
| 26 | + if not header.get("template", False): |
56 | 27 | return False
|
| 28 | + nodesVersions = header.get(GraphIO.Keys.NodesVersions, {}) |
| 29 | + |
| 30 | + for _, nodeData in graphData.items(): |
| 31 | + nodeType = nodeData["nodeType"] |
| 32 | + if not nodeType in meshroom.core.nodesDesc: |
| 33 | + return False |
| 34 | + |
| 35 | + nodeDesc = meshroom.core.nodesDesc[nodeType] |
| 36 | + currentNodeVersion = meshroom.core.nodeVersion(nodeDesc) |
| 37 | + |
| 38 | + inputs = nodeData.get("inputs", {}) |
| 39 | + internalInputs = nodeData.get("internalInputs", {}) |
| 40 | + version = nodesVersions.get(nodeType, None) |
57 | 41 |
|
58 |
| - return True |
| 42 | + compatibilityIssue = None |
| 43 | + |
| 44 | + if version and currentNodeVersion and Version(version).major != Version(currentNodeVersion).major: |
| 45 | + compatibilityIssue = CompatibilityIssue.VersionConflict |
| 46 | + else: |
| 47 | + for attrName, value in inputs.items(): |
| 48 | + if not CompatibilityNode.attributeDescFromName(nodeDesc.inputs, attrName, value): |
| 49 | + compatibilityIssue = CompatibilityIssue.DescriptionConflict |
| 50 | + break |
| 51 | + for attrName, value in internalInputs.items(): |
| 52 | + if not CompatibilityNode.attributeDescFromName(nodeDesc.internalInputs, attrName, value): |
| 53 | + compatibilityIssue = CompatibilityIssue.DescriptionConflict |
| 54 | + break |
| 55 | + |
| 56 | + if compatibilityIssue is not None: |
| 57 | + print("{} in {} for node {}".format(compatibilityIssue, path, nodeType)) |
| 58 | + return False |
| 59 | + |
| 60 | + return True |
| 61 | + |
| 62 | + finally: |
| 63 | + if not nodesAlreadyLoaded: |
| 64 | + nodeTypes = [nodeType for _, nodeType in meshroom.core.nodesDesc.items()] |
| 65 | + for nodeType in nodeTypes: |
| 66 | + unregisterNodeType(nodeType) |
59 | 67 |
|
60 | 68 |
|
61 | 69 | def checkAllTemplatesVersions() -> bool:
|
| 70 | + meshroom.core.initNodes() |
62 | 71 | meshroom.core.initPipelines()
|
63 | 72 |
|
64 | 73 | validVersions = []
|
65 | 74 | for _, path in pipelineTemplates.items():
|
66 |
| - validVersions.append(checkTemplateVersions(path)) |
| 75 | + validVersions.append(checkTemplateVersions(path, nodesAlreadyLoaded=True)) |
67 | 76 |
|
68 | 77 | return all(validVersions)
|
0 commit comments