extract_metadata: Improve error reporting
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
1d520310ac
commit
b3f02a73a4
|
@ -10,6 +10,7 @@ import re
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import traceback
|
||||||
|
|
||||||
# regex helpers
|
# regex helpers
|
||||||
def _regex_find_floats(pattern, data, strict=False):
|
def _regex_find_floats(pattern, data, strict=False):
|
||||||
|
@ -113,13 +114,13 @@ class PrusaSlicer(BaseSlicer):
|
||||||
data = "".join(lines[1:-1])
|
data = "".join(lines[1:-1])
|
||||||
if len(info) != 3:
|
if len(info) != 3:
|
||||||
self.log.append(
|
self.log.append(
|
||||||
{'MetadataError': "Error parsing thumbnail header: %s"
|
f"MetadataError: Error parsing thumbnail"
|
||||||
% (lines[0])})
|
f" header: {lines[0]}")
|
||||||
continue
|
continue
|
||||||
if len(data) != info[2]:
|
if len(data) != info[2]:
|
||||||
self.log.append(
|
self.log.append(
|
||||||
{'MetadataError': "Thumbnail Size Mismatch: detected %d, "
|
f"MetadataError: Thumbnail Size Mismatch: "
|
||||||
"actual %d" % (info[2], len(data))})
|
f"detected {info[2]}, actual {len(data)}")
|
||||||
continue
|
continue
|
||||||
parsed_matches.append({
|
parsed_matches.append({
|
||||||
'width': info[0], 'height': info[1],
|
'width': info[0], 'height': info[1],
|
||||||
|
@ -291,15 +292,9 @@ SUPPORTED_DATA = [
|
||||||
'first_layer_height', 'layer_height', 'object_height',
|
'first_layer_height', 'layer_height', 'object_height',
|
||||||
'filament_total', 'estimated_time', 'thumbnails']
|
'filament_total', 'estimated_time', 'thumbnails']
|
||||||
|
|
||||||
|
def extract_metadata(file_path, log):
|
||||||
def main(path, filename):
|
|
||||||
file_path = os.path.join(path, filename)
|
|
||||||
slicers = [s() for s in SUPPORTED_SLICERS]
|
|
||||||
log = []
|
|
||||||
metadata = {}
|
metadata = {}
|
||||||
if not os.path.isfile(file_path):
|
slicers = [s() for s in SUPPORTED_SLICERS]
|
||||||
log.append("File Not Found: %s" % (file_path))
|
|
||||||
else:
|
|
||||||
header_data = footer_data = slicer = None
|
header_data = footer_data = slicer = None
|
||||||
size = os.path.getsize(file_path)
|
size = os.path.getsize(file_path)
|
||||||
metadata['size'] = size
|
metadata['size'] = size
|
||||||
|
@ -328,6 +323,19 @@ def main(path, filename):
|
||||||
result = func()
|
result = func()
|
||||||
if result is not None:
|
if result is not None:
|
||||||
metadata[key] = result
|
metadata[key] = result
|
||||||
|
return metadata
|
||||||
|
|
||||||
|
def main(path, filename):
|
||||||
|
file_path = os.path.join(path, filename)
|
||||||
|
log = []
|
||||||
|
metadata = {}
|
||||||
|
if not os.path.isfile(file_path):
|
||||||
|
log.append(f"File Not Found: {file_path}")
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
metadata = extract_metadata(file_path, log)
|
||||||
|
except Exception:
|
||||||
|
log.append(traceback.format_exc())
|
||||||
fd = sys.stdout.fileno()
|
fd = sys.stdout.fileno()
|
||||||
data = json.dumps(
|
data = json.dumps(
|
||||||
{'file': filename, 'log': log, 'metadata': metadata}).encode()
|
{'file': filename, 'log': log, 'metadata': metadata}).encode()
|
||||||
|
|
Loading…
Reference in New Issue