mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-05-29 08:56:33 +02:00
fix python nodes being blocked by log
...when ran on command line with meshroom_photogrammetry or meshroom_compute
This commit is contained in:
parent
95a28cb0a7
commit
f75fc91436
3 changed files with 58 additions and 64 deletions
|
@ -132,9 +132,6 @@ class LogManager:
|
||||||
|
|
||||||
def __init__(self, chunk):
|
def __init__(self, chunk):
|
||||||
self.chunk = chunk
|
self.chunk = chunk
|
||||||
self.chunk.statusChanged.connect(self.clear)
|
|
||||||
self.progressBar = False
|
|
||||||
self.cleared = False
|
|
||||||
self.logger = logging.getLogger(chunk.node.getName())
|
self.logger = logging.getLogger(chunk.node.getName())
|
||||||
|
|
||||||
class Formatter(logging.Formatter):
|
class Formatter(logging.Formatter):
|
||||||
|
@ -151,27 +148,22 @@ class LogManager:
|
||||||
handler.setFormatter(formatter)
|
handler.setFormatter(formatter)
|
||||||
self.logger.addHandler(handler)
|
self.logger.addHandler(handler)
|
||||||
|
|
||||||
def clear(self):
|
def start(self, level):
|
||||||
if self.chunk.statusName == 'RUNNING' and not self.cleared:
|
# Clear log file
|
||||||
open(self.chunk.logFile, 'w').close()
|
open(self.chunk.logFile, 'w').close()
|
||||||
self.configureLogger()
|
|
||||||
self.cleared = True
|
self.configureLogger()
|
||||||
# When the node gets ran again the log needs to be cleared
|
self.logger.setLevel(self.textToLevel(level))
|
||||||
elif self.chunk.statusName in ['ERROR', 'SUCCESS']:
|
self.progressBar = False
|
||||||
for handler in self.logger.handlers[:]:
|
|
||||||
# Stops the file being locked
|
|
||||||
handler.close()
|
|
||||||
self.cleared = False
|
|
||||||
self.progressBar = False
|
|
||||||
|
|
||||||
def waitUntilCleared(self):
|
def end(self):
|
||||||
while not self.cleared:
|
for handler in self.logger.handlers[:]:
|
||||||
time.sleep(0.01)
|
# Stops the file being locked
|
||||||
|
handler.close()
|
||||||
|
|
||||||
def makeProgressBar(self, end, message=''):
|
def makeProgressBar(self, end, message=''):
|
||||||
assert end > 0
|
assert end > 0
|
||||||
assert not self.progressBar
|
assert not self.progressBar
|
||||||
self.waitUntilCleared()
|
|
||||||
|
|
||||||
self.progressEnd = end
|
self.progressEnd = end
|
||||||
self.currentProgressTics = 0
|
self.currentProgressTics = 0
|
||||||
|
@ -194,7 +186,6 @@ class LogManager:
|
||||||
def updateProgressBar(self, value):
|
def updateProgressBar(self, value):
|
||||||
assert self.progressBar
|
assert self.progressBar
|
||||||
assert value <= self.progressEnd
|
assert value <= self.progressEnd
|
||||||
self.waitUntilCleared()
|
|
||||||
|
|
||||||
tics = round((value/self.progressEnd)*51)
|
tics = round((value/self.progressEnd)*51)
|
||||||
|
|
||||||
|
|
|
@ -50,27 +50,29 @@ class Publish(desc.Node):
|
||||||
return paths
|
return paths
|
||||||
|
|
||||||
def processChunk(self, chunk):
|
def processChunk(self, chunk):
|
||||||
chunk.logManager.waitUntilCleared()
|
try:
|
||||||
chunk.logger.setLevel(chunk.logManager.textToLevel(chunk.node.verboseLevel.value))
|
chunk.logManager.start(chunk.node.verboseLevel.value)
|
||||||
|
|
||||||
if not chunk.node.inputFiles:
|
if not chunk.node.inputFiles:
|
||||||
chunk.logger.warning('Nothing to publish')
|
chunk.logger.warning('Nothing to publish')
|
||||||
return
|
return
|
||||||
if not chunk.node.output.value:
|
if not chunk.node.output.value:
|
||||||
return
|
return
|
||||||
|
|
||||||
outFiles = self.resolvedPaths(chunk.node.inputFiles.value, chunk.node.output.value)
|
outFiles = self.resolvedPaths(chunk.node.inputFiles.value, chunk.node.output.value)
|
||||||
|
|
||||||
if not outFiles:
|
if not outFiles:
|
||||||
error = 'Publish: input files listed, but nothing to publish'
|
error = 'Publish: input files listed, but nothing to publish'
|
||||||
chunk.logger.error(error)
|
chunk.logger.error(error)
|
||||||
chunk.logger.info('Listed input files: {}'.format([i.value for i in chunk.node.inputFiles.value]))
|
chunk.logger.info('Listed input files: {}'.format([i.value for i in chunk.node.inputFiles.value]))
|
||||||
raise RuntimeError(error)
|
raise RuntimeError(error)
|
||||||
|
|
||||||
if not os.path.exists(chunk.node.output.value):
|
if not os.path.exists(chunk.node.output.value):
|
||||||
os.mkdir(chunk.node.output.value)
|
os.mkdir(chunk.node.output.value)
|
||||||
|
|
||||||
for iFile, oFile in outFiles.items():
|
for iFile, oFile in outFiles.items():
|
||||||
chunk.logger.info('Publish file {} into {}'.format(iFile, oFile))
|
chunk.logger.info('Publish file {} into {}'.format(iFile, oFile))
|
||||||
shutil.copyfile(iFile, oFile)
|
shutil.copyfile(iFile, oFile)
|
||||||
chunk.logger.info('Publish end')
|
chunk.logger.info('Publish end')
|
||||||
|
finally:
|
||||||
|
chunk.logManager.end()
|
||||||
|
|
|
@ -216,31 +216,30 @@ class SketchfabUpload(desc.Node):
|
||||||
return self._stopped
|
return self._stopped
|
||||||
|
|
||||||
def processChunk(self, chunk):
|
def processChunk(self, chunk):
|
||||||
self._stopped = False
|
|
||||||
chunk.logManager.waitUntilCleared()
|
|
||||||
chunk.logger.setLevel(chunk.logManager.textToLevel(chunk.node.verboseLevel.value))
|
|
||||||
|
|
||||||
if not chunk.node.inputFiles:
|
|
||||||
chunk.logger.warning('Nothing to upload')
|
|
||||||
return
|
|
||||||
if chunk.node.apiToken.value == '':
|
|
||||||
chunk.logger.error('Need API token.')
|
|
||||||
raise RuntimeError()
|
|
||||||
if len(chunk.node.title.value) > 48:
|
|
||||||
chunk.logger.error('Title cannot be longer than 48 characters.')
|
|
||||||
raise RuntimeError()
|
|
||||||
if len(chunk.node.description.value) > 1024:
|
|
||||||
chunk.logger.error('Description cannot be longer than 1024 characters.')
|
|
||||||
raise RuntimeError()
|
|
||||||
tags = [ i.value.replace(' ', '-') for i in chunk.node.tags.value.values() ]
|
|
||||||
if all(len(i) > 48 for i in tags) and len(tags) > 0:
|
|
||||||
chunk.logger.error('Tags cannot be longer than 48 characters.')
|
|
||||||
raise RuntimeError()
|
|
||||||
if len(tags) > 42:
|
|
||||||
chunk.logger.error('Maximum of 42 separate tags.')
|
|
||||||
raise RuntimeError()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
self._stopped = False
|
||||||
|
chunk.logManager.start(chunk.node.verboseLevel.value)
|
||||||
|
|
||||||
|
if not chunk.node.inputFiles:
|
||||||
|
chunk.logger.warning('Nothing to upload')
|
||||||
|
return
|
||||||
|
if chunk.node.apiToken.value == '':
|
||||||
|
chunk.logger.error('Need API token.')
|
||||||
|
raise RuntimeError()
|
||||||
|
if len(chunk.node.title.value) > 48:
|
||||||
|
chunk.logger.error('Title cannot be longer than 48 characters.')
|
||||||
|
raise RuntimeError()
|
||||||
|
if len(chunk.node.description.value) > 1024:
|
||||||
|
chunk.logger.error('Description cannot be longer than 1024 characters.')
|
||||||
|
raise RuntimeError()
|
||||||
|
tags = [ i.value.replace(' ', '-') for i in chunk.node.tags.value.values() ]
|
||||||
|
if all(len(i) > 48 for i in tags) and len(tags) > 0:
|
||||||
|
chunk.logger.error('Tags cannot be longer than 48 characters.')
|
||||||
|
raise RuntimeError()
|
||||||
|
if len(tags) > 42:
|
||||||
|
chunk.logger.error('Maximum of 42 separate tags.')
|
||||||
|
raise RuntimeError()
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'name': chunk.node.title.value,
|
'name': chunk.node.title.value,
|
||||||
'description': chunk.node.description.value,
|
'description': chunk.node.description.value,
|
||||||
|
@ -276,5 +275,7 @@ class SketchfabUpload(desc.Node):
|
||||||
os.remove(uploadFile)
|
os.remove(uploadFile)
|
||||||
chunk.logger.debug('Deleted {}'.format(uploadFile))
|
chunk.logger.debug('Deleted {}'.format(uploadFile))
|
||||||
|
|
||||||
|
chunk.logManager.end()
|
||||||
|
|
||||||
def stopProcess(self, chunk):
|
def stopProcess(self, chunk):
|
||||||
self._stopped = True
|
self._stopped = True
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue