mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-07-25 12:37:33 +02:00
[bin] add toNode argument with partial name support
This commit is contained in:
parent
18d2e4bd39
commit
0655d1b7d1
2 changed files with 29 additions and 12 deletions
|
@ -7,9 +7,9 @@ parser = argparse.ArgumentParser(description='Execute a Graph of processes.')
|
||||||
parser.add_argument('graphFile', metavar='GRAPHFILE.mg', type=str,
|
parser.add_argument('graphFile', metavar='GRAPHFILE.mg', type=str,
|
||||||
help='Filepath to a graph file.')
|
help='Filepath to a graph file.')
|
||||||
parser.add_argument('--node', metavar='NODE_NAME', type=str,
|
parser.add_argument('--node', metavar='NODE_NAME', type=str,
|
||||||
help='Process the node alone.')
|
help='Process the node. It will generate an error if the dependencies are not already computed.')
|
||||||
parser.add_argument('--graph', metavar='NODE_NAME', type=str,
|
parser.add_argument('--toNode', metavar='NODE_NAME', type=str,
|
||||||
help='Process the node and all previous nodes needed.')
|
help='Process the node with its dependencies.')
|
||||||
parser.add_argument("--force", help="Force recompute",
|
parser.add_argument("--force", help="Force recompute",
|
||||||
action="store_true")
|
action="store_true")
|
||||||
|
|
||||||
|
@ -27,8 +27,6 @@ if args.node:
|
||||||
if args.force or node.status.status != pg.Status.SUCCESS:
|
if args.force or node.status.status != pg.Status.SUCCESS:
|
||||||
node.process()
|
node.process()
|
||||||
else:
|
else:
|
||||||
startNodes = None
|
toNodes = graph.findNodes(args.toNode)
|
||||||
if args.graph:
|
pg.execute(graph, toNodes=toNodes, force=args.force)
|
||||||
startNodes = [graph.node(args.graph)]
|
|
||||||
pg.execute(graph, startNodes=startNodes, force=args.force)
|
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import hashlib
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import psutil
|
import psutil
|
||||||
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
|
@ -606,6 +607,21 @@ class Graph(BaseObject):
|
||||||
def node(self, nodeName):
|
def node(self, nodeName):
|
||||||
return self._nodes.get(nodeName)
|
return self._nodes.get(nodeName)
|
||||||
|
|
||||||
|
def findNodeCandidates(self, nodeNameExpr):
|
||||||
|
pattern = re.compile(nodeNameExpr)
|
||||||
|
return [v for k, v in self._nodes.objects.items() if pattern.match(k)]
|
||||||
|
|
||||||
|
def findNodes(self, nodesExpr):
|
||||||
|
out = []
|
||||||
|
for nodeName in nodesExpr:
|
||||||
|
candidates = self.findNodeCandidates('^' + nodeName)
|
||||||
|
if not candidates:
|
||||||
|
raise KeyError('No node candidate for "{}"'.format(nodeName))
|
||||||
|
elif len(candidates) > 1:
|
||||||
|
raise KeyError('Multiple node candidates for "{}": {}'.format(nodeName, str([c.name for c in candidates])))
|
||||||
|
out.append(candidates[0])
|
||||||
|
return out
|
||||||
|
|
||||||
def edge(self, dstAttributeName):
|
def edge(self, dstAttributeName):
|
||||||
return self._edges.get(dstAttributeName)
|
return self._edges.get(dstAttributeName)
|
||||||
|
|
||||||
|
@ -635,7 +651,10 @@ class Graph(BaseObject):
|
||||||
inputDepths = [e.src.node.depth for e in inputEdges]
|
inputDepths = [e.src.node.depth for e in inputEdges]
|
||||||
return min(inputDepths) + 1
|
return min(inputDepths) + 1
|
||||||
|
|
||||||
def _getNodeEdges(self):
|
def getInputEdges(self, node):
|
||||||
|
return set([edge for edge in self.edges if edge.dst.node is node])
|
||||||
|
|
||||||
|
def _getInputEdgesPerNode(self):
|
||||||
nodeEdges = defaultdict(set)
|
nodeEdges = defaultdict(set)
|
||||||
|
|
||||||
for edge in self.edges:
|
for edge in self.edges:
|
||||||
|
@ -644,7 +663,7 @@ class Graph(BaseObject):
|
||||||
return nodeEdges
|
return nodeEdges
|
||||||
|
|
||||||
def dfs(self, visitor, startNodes=None):
|
def dfs(self, visitor, startNodes=None):
|
||||||
nodeChildren = self._getNodeEdges()
|
nodeChildren = self._getInputEdgesPerNode()
|
||||||
colors = {}
|
colors = {}
|
||||||
for u in self._nodes:
|
for u in self._nodes:
|
||||||
colors[u] = WHITE
|
colors[u] = WHITE
|
||||||
|
@ -762,13 +781,13 @@ def getAlreadySubmittedNodes(nodes):
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
def execute(graph, startNodes=None, force=False):
|
def execute(graph, toNodes=None, force=False):
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
if force:
|
if force:
|
||||||
nodes = graph.dfsNodesOnFinish(startNodes=startNodes)
|
nodes = graph.dfsNodesOnFinish(startNodes=toNodes)
|
||||||
else:
|
else:
|
||||||
nodes = graph.dfsNodesToProcess(startNodes=startNodes)
|
nodes = graph.dfsNodesToProcess(startNodes=toNodes)
|
||||||
nodesInConflict = getAlreadySubmittedNodes(nodes)
|
nodesInConflict = getAlreadySubmittedNodes(nodes)
|
||||||
|
|
||||||
if nodesInConflict:
|
if nodesInConflict:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue