From cb5ac86af74b3c773d81022b11d9df2f8520143a Mon Sep 17 00:00:00 2001 From: Pedro Lamas Date: Tue, 8 Feb 2022 14:45:27 +0000 Subject: [PATCH] metadata: add support for parsing layer count in Cura Signed-off-by: Pedro Lamas --- moonraker/components/file_manager/metadata.py | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/moonraker/components/file_manager/metadata.py b/moonraker/components/file_manager/metadata.py index b0762a3..8a03874 100644 --- a/moonraker/components/file_manager/metadata.py +++ b/moonraker/components/file_manager/metadata.py @@ -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)