[core] cache directory per graph

This commit is contained in:
Fabien Castan 2017-10-26 12:22:06 +02:00
parent e533c588dd
commit 40974149ee
4 changed files with 44 additions and 14 deletions

View file

@ -12,10 +12,15 @@ parser.add_argument('--toNode', metavar='NODE_NAME', type=str,
help='Process the node with its dependencies.') 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")
parser.add_argument('--cache', metavar='FOLDER', type=str,
default=None,
help='Override the cache folder')
args = parser.parse_args() args = parser.parse_args()
graph = pg.loadGraph(args.graphFile) graph = pg.loadGraph(args.graphFile)
if args.cache:
graph.cacheDir = args.cache
graph.update() graph.update()
if args.node: if args.node:

View file

@ -1,5 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
import argparse import argparse
import os
import meshroom.core import meshroom.core
from meshroom import multiview from meshroom import multiview
@ -15,8 +16,8 @@ parser.add_argument('--toNode', metavar='NODE', type=str, nargs='*',
default=None, default=None,
help='Process the node(s) with its dependencies.') help='Process the node(s) with its dependencies.')
parser.add_argument('--cache', metavar='FOLDER', type=str, parser.add_argument('--cache', metavar='FOLDER', type=str,
default=meshroom.core.cacheFolder, default=None,
help='Cache folder') help='Choose a custom cache folder')
parser.add_argument('--save', metavar='FOLDER', type=str, required=False, parser.add_argument('--save', metavar='FOLDER', type=str, required=False,
help='Save the workflow to a meshroom files.') help='Save the workflow to a meshroom files.')
@ -33,9 +34,16 @@ if args.input:
if args.save: if args.save:
graph.save(args.save) graph.save(args.save)
if not args.cache:
graph.cacheDir = os.path.abspath(os.path.dirname(args.save))
if args.cache:
graph.cacheDir = args.cache
if not graph.cacheDir:
graph.cacheDir = meshroom.core.defaultCacheFolder
if args.output: if args.output:
meshroom.core.cacheFolder = args.cache
graph.update() graph.update()
toNodes = None toNodes = None
if args.toNode: if args.toNode:

View file

@ -8,8 +8,9 @@ from contextlib import contextmanager
from . import desc from . import desc
cacheFolder = os.environ.get('MESHROOM_CACHE', os.path.join(tempfile.gettempdir(), 'MeshroomCache')) cacheFolderName = 'MeshroomCache'
cacheFolder = cacheFolder.replace("\\", "/") defaultCacheFolder = os.environ.get('MESHROOM_CACHE', os.path.join(tempfile.gettempdir(), cacheFolderName))
defaultCacheFolder = defaultCacheFolder.replace("\\", "/")
nodesDesc = {} nodesDesc = {}

View file

@ -17,7 +17,7 @@ import logging
from . import stats from . import stats
from . import desc from . import desc
from meshroom import core as pg import meshroom.core
from meshroom.common import BaseObject, DictModel, Slot, Signal, Property, Variant, ListModel from meshroom.common import BaseObject, DictModel, Slot, Signal, Property, Variant, ListModel
# Replace default encoder to support Enums # Replace default encoder to support Enums
@ -66,9 +66,9 @@ def attribute_factory(description, name, value, node, parent=None):
:param parent: (optional) parent Attribute (must be ListAttribute or GroupAttribute) :param parent: (optional) parent Attribute (must be ListAttribute or GroupAttribute)
:return: :return:
""" """
if isinstance(description, pg.desc.GroupAttribute): if isinstance(description, meshroom.core.desc.GroupAttribute):
cls = GroupAttribute cls = GroupAttribute
elif isinstance(description, pg.desc.ListAttribute): elif isinstance(description, meshroom.core.desc.ListAttribute):
cls = ListAttribute cls = ListAttribute
else: else:
cls = Attribute cls = Attribute
@ -322,7 +322,7 @@ class Node(BaseObject):
super(Node, self).__init__(parent) super(Node, self).__init__(parent)
self._name = None # type: str self._name = None # type: str
self.graph = None # type: Graph self.graph = None # type: Graph
self.nodeDesc = pg.nodesDesc[nodeDesc]() self.nodeDesc = meshroom.core.nodesDesc[nodeDesc]()
self._cmdVars = {} self._cmdVars = {}
self._attributes = DictModel(keyAttrName='name', parent=self) self._attributes = DictModel(keyAttrName='name', parent=self)
self.attributesPerUid = defaultdict(set) self.attributesPerUid = defaultdict(set)
@ -377,7 +377,7 @@ class Node(BaseObject):
def _initFromDesc(self): def _initFromDesc(self):
# Init from class and instance members # Init from class and instance members
for name, desc in vars(self.nodeDesc.__class__).items() + vars(self.nodeDesc).items(): for name, desc in vars(self.nodeDesc.__class__).items() + vars(self.nodeDesc).items():
if issubclass(desc.__class__, pg.desc.Attribute): if issubclass(desc.__class__, meshroom.core.desc.Attribute):
self._attributes.add(attribute_factory(desc, name, None, self)) self._attributes.add(attribute_factory(desc, name, None, self))
# List attributes per uid # List attributes per uid
@ -418,7 +418,7 @@ class Node(BaseObject):
self._updateUid() self._updateUid()
self._cmdVars = { self._cmdVars = {
'cache': pg.cacheFolder, 'cache': self.graph.cacheDir,
} }
for uidIndex, associatedAttributes in self.attributesPerUid.items(): for uidIndex, associatedAttributes in self.attributesPerUid.items():
assAttr = [(a.getName(), a.uid()) for a in associatedAttributes] assAttr = [(a.getName(), a.uid()) for a in associatedAttributes]
@ -467,13 +467,13 @@ class Node(BaseObject):
return self.nodeDesc.commandLine.format(nodeType=self.nodeType, **self._cmdVars) return self.nodeDesc.commandLine.format(nodeType=self.nodeType, **self._cmdVars)
def statusFile(self): def statusFile(self):
return os.path.join(pg.cacheFolder, self.internalFolder, 'status') return os.path.join(self.graph.cacheDir, self.internalFolder, 'status')
def statisticsFile(self): def statisticsFile(self):
return os.path.join(pg.cacheFolder, self.internalFolder, 'statistics') return os.path.join(self.graph.cacheDir, self.internalFolder, 'statistics')
def logFile(self): def logFile(self):
return os.path.join(pg.cacheFolder, self.internalFolder, 'log') return os.path.join(self.graph.cacheDir, self.internalFolder, 'log')
def updateStatusFromCache(self): def updateStatusFromCache(self):
""" """
@ -667,6 +667,7 @@ class Graph(BaseObject):
self.name = name self.name = name
self._nodes = DictModel(keyAttrName='name', parent=self) self._nodes = DictModel(keyAttrName='name', parent=self)
self._edges = DictModel(keyAttrName='dst', parent=self) # use dst attribute as unique key since it can only have one input connection self._edges = DictModel(keyAttrName='dst', parent=self) # use dst attribute as unique key since it can only have one input connection
self._cacheDir = ''
def clear(self): def clear(self):
self._nodes.clear() self._nodes.clear()
@ -680,6 +681,7 @@ class Graph(BaseObject):
if not isinstance(graphData, dict): if not isinstance(graphData, dict):
raise RuntimeError('loadGraph error: Graph is not a dict. File: {}'.format(filepath)) raise RuntimeError('loadGraph error: Graph is not a dict. File: {}'.format(filepath))
self._cacheDir = os.path.join(os.path.abspath(os.path.dirname(filepath)), meshroom.core.cacheFolderName)
self.name = os.path.splitext(os.path.basename(filepath))[0] self.name = os.path.splitext(os.path.basename(filepath))[0]
for nodeName, nodeData in graphData.items(): for nodeName, nodeData in graphData.items():
if not isinstance(nodeData, dict): if not isinstance(nodeData, dict):
@ -1057,11 +1059,25 @@ class Graph(BaseObject):
def edges(self): def edges(self):
return self._edges return self._edges
@property
def cacheDir(self):
return self._cacheDir
@cacheDir.setter
def cacheDir(self, value):
if self._cacheDir == value:
return
self._cacheDir = value
self.cacheDirChanged.emit()
nodes = Property(BaseObject, nodes.fget, constant=True) nodes = Property(BaseObject, nodes.fget, constant=True)
edges = Property(BaseObject, edges.fget, constant=True) edges = Property(BaseObject, edges.fget, constant=True)
cacheDirChanged = Signal()
cacheDir = Property(str, cacheDir.fget, cacheDir.fset, notify=cacheDirChanged)
stopExecutionRequested = Signal() stopExecutionRequested = Signal()
def loadGraph(filepath): def loadGraph(filepath):
""" """
""" """