Skip to content

Commit

Permalink
Merge pull request #783 from ChemicalXandco/sketchfab_upload_node
Browse files Browse the repository at this point in the history
fix python nodes being blocked by log
  • Loading branch information
fabiencastan authored Mar 19, 2020
2 parents aa8aad5 + dcbee52 commit 9fe8d2b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 64 deletions.
33 changes: 12 additions & 21 deletions meshroom/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@ class LogManager:

def __init__(self, chunk):
self.chunk = chunk
self.chunk.statusChanged.connect(self.clear)
self.progressBar = False
self.cleared = False
self.logger = logging.getLogger(chunk.node.getName())

class Formatter(logging.Formatter):
Expand All @@ -151,27 +148,22 @@ def configureLogger(self):
handler.setFormatter(formatter)
self.logger.addHandler(handler)

def clear(self):
if self.chunk.statusName == 'RUNNING' and not self.cleared:
open(self.chunk.logFile, 'w').close()
self.configureLogger()
self.cleared = True
# When the node gets ran again the log needs to be cleared
elif self.chunk.statusName in ['ERROR', 'SUCCESS']:
for handler in self.logger.handlers[:]:
# Stops the file being locked
handler.close()
self.cleared = False
self.progressBar = False

def waitUntilCleared(self):
while not self.cleared:
time.sleep(0.01)
def start(self, level):
# Clear log file
open(self.chunk.logFile, 'w').close()

self.configureLogger()
self.logger.setLevel(self.textToLevel(level))
self.progressBar = False

def end(self):
for handler in self.logger.handlers[:]:
# Stops the file being locked
handler.close()

def makeProgressBar(self, end, message=''):
assert end > 0
assert not self.progressBar
self.waitUntilCleared()

self.progressEnd = end
self.currentProgressTics = 0
Expand All @@ -194,7 +186,6 @@ def makeProgressBar(self, end, message=''):
def updateProgressBar(self, value):
assert self.progressBar
assert value <= self.progressEnd
self.waitUntilCleared()

tics = round((value/self.progressEnd)*51)

Expand Down
42 changes: 22 additions & 20 deletions meshroom/nodes/aliceVision/Publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,29 @@ def resolvedPaths(self, inputFiles, outDir):
return paths

def processChunk(self, chunk):
chunk.logManager.waitUntilCleared()
chunk.logger.setLevel(chunk.logManager.textToLevel(chunk.node.verboseLevel.value))

if not chunk.node.inputFiles:
chunk.logger.warning('Nothing to publish')
return
if not chunk.node.output.value:
return
try:
chunk.logManager.start(chunk.node.verboseLevel.value)
if not chunk.node.inputFiles:
chunk.logger.warning('Nothing to publish')
return
if not chunk.node.output.value:
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:
error = 'Publish: input files listed, but nothing to publish'
chunk.logger.error(error)
chunk.logger.info('Listed input files: {}'.format([i.value for i in chunk.node.inputFiles.value]))
raise RuntimeError(error)
if not outFiles:
error = 'Publish: input files listed, but nothing to publish'
chunk.logger.error(error)
chunk.logger.info('Listed input files: {}'.format([i.value for i in chunk.node.inputFiles.value]))
raise RuntimeError(error)

if not os.path.exists(chunk.node.output.value):
os.mkdir(chunk.node.output.value)
if not os.path.exists(chunk.node.output.value):
os.mkdir(chunk.node.output.value)

for iFile, oFile in outFiles.items():
chunk.logger.info('Publish file {} into {}'.format(iFile, oFile))
shutil.copyfile(iFile, oFile)
chunk.logger.info('Publish end')
for iFile, oFile in outFiles.items():
chunk.logger.info('Publish file {} into {}'.format(iFile, oFile))
shutil.copyfile(iFile, oFile)
chunk.logger.info('Publish end')
finally:
chunk.logManager.end()
48 changes: 25 additions & 23 deletions meshroom/nodes/aliceVision/SketchfabUpload.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,31 +216,31 @@ def stopped(self):
return self._stopped

def processChunk(self, chunk):
self._stopped = False
chunk.logManager.waitUntilCleared()
chunk.logger.setLevel(chunk.logManager.textToLevel(chunk.node.verboseLevel.value))
try:
self._stopped = False
chunk.logManager.start(chunk.node.verboseLevel.value)
uploadFile = ''

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()
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:
data = {
'name': chunk.node.title.value,
'description': chunk.node.description.value,
Expand Down Expand Up @@ -276,5 +276,7 @@ def processChunk(self, chunk):
os.remove(uploadFile)
chunk.logger.debug('Deleted {}'.format(uploadFile))

chunk.logManager.end()

def stopProcess(self, chunk):
self._stopped = True
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def __init__(self, script, initScript=None, base=None, targetName=None, icons=No
build_exe_options = {
# include dynamically loaded plugins
"packages": ["meshroom.nodes", "meshroom.submitters"],
"includes": [
"idna.idnadata", # Dependency needed by SketchfabUpload node, but not detected by cx_Freeze
],
"include_files": ["CHANGES.md", "COPYING.md", "LICENSE-MPL2.md", "README.md"]
}

Expand Down

0 comments on commit 9fe8d2b

Please sign in to comment.