metadata: add support for parsing layer count in Cura

Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
This commit is contained in:
Pedro Lamas 2022-02-08 14:45:27 +00:00 committed by Eric Callahan
parent 94a2949c00
commit cb5ac86af7
1 changed files with 16 additions and 8 deletions

View File

@ -83,6 +83,16 @@ def _regex_find_first(pattern: str, data: str) -> Optional[float]:
return None
return val
def _regex_find_int(pattern: str, data: str) -> Optional[int]:
match = re.search(pattern, data)
val: Optional[int] = None
if match:
try:
val = int(match.group(1))
except Exception:
return None
return val
def _regex_find_string(pattern: str, data: str) -> Optional[str]:
match = re.search(pattern, data)
if match:
@ -387,14 +397,8 @@ class PrusaSlicer(BaseSlicer):
r";\snozzle_diameter\s=\s(\d+\.\d*)", self.footer_data)
def parse_layer_count(self) -> Optional[int]:
match = re.search(r"; total layers count = (\d+)", self.footer_data)
val: Optional[int] = None
if match:
try:
val = int(match.group(1))
except Exception:
return None
return val
return _regex_find_int(
r"; total layers count = (\d+)", self.footer_data)
class Slic3rPE(PrusaSlicer):
def check_identity(self, data: str) -> Optional[Dict[str, str]]:
@ -492,6 +496,10 @@ class Cura(BaseSlicer):
return _regex_find_first(
r"M190 S(\d+\.?\d*)", self.header_data)
def parse_layer_count(self) -> Optional[int]:
return _regex_find_int(
r";LAYER_COUNT\:(\d+)", self.header_data)
def parse_nozzle_diameter(self) -> Optional[float]:
return _regex_find_first(
r";Nozzle\sdiameter\s=\s(\d+\.\d*)", self.header_data)