[bin] meshroom_photogrammetry: setup cache folder according to --save path

except if --cache is set explicitly
This commit is contained in:
Fabien Castan 2019-09-12 21:36:36 +02:00
parent ee2fc63bd5
commit 979ee4ba94
2 changed files with 16 additions and 8 deletions

View file

@ -38,7 +38,7 @@ parser.add_argument('--cache', metavar='FOLDER', type=str,
'If not set, the default cache folder will be used: ' + meshroom.core.defaultCacheFolder)
parser.add_argument('--save', metavar='FILE', type=str, required=False,
help='Save the configured Meshroom project to a file.')
help='Save the configured Meshroom graph to a project file. It will setup the cache folder accordingly if not explicitly changed by --cache.')
parser.add_argument('--compute', metavar='<yes/no>', type=lambda x: bool(distutils.util.strtobool(x)), default=True, required=False,
help='You can set it to <no/false/0> to disable the computation.')
@ -130,13 +130,13 @@ if args.scale > 0:
for node in graph.nodesByType('DepthMap'):
node.downscale.value = args.scale
if args.save:
graph.save(args.save)
print('File successfully saved:', args.save)
# setup cache directory
graph.cacheDir = args.cache if args.cache else meshroom.core.defaultCacheFolder
if args.save:
graph.save(args.save, fileLink=not bool(args.cache))
print('File successfully saved: "{}"'.format(args.save))
if not args.output:
print('No output set, results will be available in the cache folder: "{}"'.format(graph.cacheDir))

View file

@ -905,7 +905,7 @@ class Graph(BaseObject):
def asString(self):
return str(self.toDict())
def save(self, filepath=None):
def save(self, filepath=None, fileLink=True):
path = filepath or self._filepath
if not path:
raise ValueError("filepath must be specified for unsaved files.")
@ -929,7 +929,7 @@ class Graph(BaseObject):
with open(path, 'w') as jsonFile:
json.dump(data, jsonFile, indent=4)
if path != self._filepath:
if path != self._filepath and fileLink:
self._setFilepath(path)
def _setFilepath(self, filepath):
@ -939,7 +939,9 @@ class Graph(BaseObject):
Args:
filepath: the graph file path
"""
assert os.path.isfile(filepath)
if not os.path.isfile(filepath):
self._unsetFilepath()
return
if self._filepath == filepath:
return
@ -951,6 +953,12 @@ class Graph(BaseObject):
self.cacheDir = os.path.join(os.path.abspath(os.path.dirname(filepath)), meshroom.core.cacheFolderName)
self.filepathChanged.emit()
def _unsetFilepath(self):
self._filepath = ""
self.name = ""
self.cacheDir = meshroom.core.defaultCacheFolder
self.filepathChanged.emit()
def updateInternals(self, startNodes=None, force=False):
nodes, edges = self.dfsOnFinish(startNodes=startNodes)
for node in nodes: