[core][ui] add upgradeAllNodes methods

+ check if node is upgradable in UpgradeNodeCommand
This commit is contained in:
Yann Lanthony 2018-07-20 17:54:06 +02:00
parent 8679fd8bf7
commit dd3d9cd54b
4 changed files with 54 additions and 0 deletions

View file

@ -442,6 +442,13 @@ class Graph(BaseObject):
return inEdges, outEdges return inEdges, outEdges
def upgradeAllNodes(self):
""" Upgrade all upgradable CompatibilityNode instances in the graph. """
nodeNames = [name for name, n in self._compatibilityNodes.items() if n.canUpgrade]
with GraphModification(self):
for nodeName in nodeNames:
self.upgradeNode(nodeName)
@Slot(str, result=Attribute) @Slot(str, result=Attribute)
def attribute(self, fullName): def attribute(self, fullName):
# type: (str) -> Attribute # type: (str) -> Attribute

View file

@ -270,6 +270,8 @@ class UpgradeNodeCommand(GraphCommand):
self.setText("Upgrade Node {}".format(self.nodeName)) self.setText("Upgrade Node {}".format(self.nodeName))
def redoImpl(self): def redoImpl(self):
if not self.graph.node(self.nodeName).canUpgrade:
return False
inEdges, self.outEdges = self.graph.upgradeNode(self.nodeName) inEdges, self.outEdges = self.graph.upgradeNode(self.nodeName)
return True return True

View file

@ -302,6 +302,14 @@ class UIGraph(QObject):
""" Upgrade a CompatibilityNode. """ """ Upgrade a CompatibilityNode. """
self.push(commands.UpgradeNodeCommand(self._graph, node)) self.push(commands.UpgradeNodeCommand(self._graph, node))
@Slot()
def upgradeAllNodes(self):
""" Upgrade all upgradable CompatibilityNode instances in the graph. """
with self.groupedGraphModification("Upgrade all Nodes"):
nodes = [n for n in self._graph._compatibilityNodes.values() if n.canUpgrade]
for node in nodes:
self.upgradeNode(node)
@Slot(Attribute, QJsonValue) @Slot(Attribute, QJsonValue)
def appendAttribute(self, attribute, value=QJsonValue()): def appendAttribute(self, attribute, value=QJsonValue()):
if isinstance(value, QJsonValue): if isinstance(value, QJsonValue):

View file

@ -112,3 +112,40 @@ def test_description_conflict():
assert hasattr(n, "in") assert hasattr(n, "in")
# check uid has changed (not the same set of attributes) # check uid has changed (not the same set of attributes)
assert n.internalFolder != internalFolder assert n.internalFolder != internalFolder
unregisterNodeType(SampleNodeV1)
def test_upgradeAllNodes():
registerNodeType(SampleNodeV1)
registerNodeType(SampleNodeV2)
g = Graph('')
n1 = g.addNewNode("SampleNodeV1")
n2 = g.addNewNode("SampleNodeV2")
n1Name = n1.name
n2Name = n2.name
graphFile = os.path.join(tempfile.mkdtemp(), "test_description_conflict.mg")
g.save(graphFile)
# make SampleNodeV2 an unknown type
unregisterNodeType(SampleNodeV2)
# replace SampleNodeV1 by SampleNodeV2
meshroom.core.nodesDesc[SampleNodeV1.__name__] = SampleNodeV2
# reload file
g = loadGraph(graphFile)
os.remove(graphFile)
# both nodes are CompatibilityNodes
assert len(g.compatibilityNodes) == 2
assert g.node(n1Name).canUpgrade # description conflict
assert not g.node(n2Name).canUpgrade # unknown type
# upgrade all upgradable nodes
g.upgradeAllNodes()
# only the node with an unknown type has not been upgraded
assert len(g.compatibilityNodes) == 1
assert n2Name in g.compatibilityNodes.keys()
unregisterNodeType(SampleNodeV1)