From 4eb81aae9d8709ce7b7e0916a1517486e4ccc833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 29 Oct 2018 17:41:57 +0100 Subject: [PATCH] cura: workaround for broken placeholders in profiles Apparently some exports contain ?print_temperature? instead of {print_temperature} style placeholders? At least that was observed in the example in #2629. This fixes such placeholders. --- src/octoprint/plugins/cura/profile.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/octoprint/plugins/cura/profile.py b/src/octoprint/plugins/cura/profile.py index b3ff3c0f3..ac60d7074 100644 --- a/src/octoprint/plugins/cura/profile.py +++ b/src/octoprint/plugins/cura/profile.py @@ -359,6 +359,8 @@ class Profile(object): regex_print_temperature = re.compile("print_temperature(\d?)") regex_strip_comments = re.compile(";.*$", flags=re.MULTILINE) + regex_broken_replacements = re.compile("\?([a-zA-Z0-9_]*)\?") + @classmethod def from_cura_ini(cls, path): import logging @@ -685,9 +687,9 @@ class Profile(object): gcode = defaults[key] if key in ("start_gcode", "end_gcode"): - return gcode[extruder_count-1] + return self.regex_broken_replacements.sub("{\\1}", gcode[extruder_count-1]) else: - return gcode + return self.regex_broken_replacements.sub("{\\1}", gcode) def get_profile_string(self): import base64 @@ -758,6 +760,7 @@ class Profile(object): def get_start_gcode_prefix(self, contents, extruder_count=1): prefix = "" + without_comments = Profile.regex_strip_comments.sub("", contents) gcode_parameter_key = "S" if self.get("gcode_flavor") == GcodeFlavors.MACH3: @@ -771,12 +774,12 @@ class Profile(object): bed_temp = 0 if self.get_boolean("has_heated_bed"): bed_temp = self.get_float("print_bed_temperature") - include_bed_temp = bed_temp > 0 and not "{print_bed_temperature}" in Profile.regex_strip_comments.sub("", contents) + include_bed_temp = bed_temp > 0 and not "{print_bed_temperature}" in without_comments if include_bed_temp: prefix += "M140 {param}{bed_temp}\n".format(param=gcode_parameter_key, bed_temp=bed_temp) - if temp > 0 and not "{print_temperature}" in Profile.regex_strip_comments.sub("", contents): + if temp > 0 and not "{print_temperature}" in without_comments: if extruder_count > 0: def temp_line(temp, extruder, param, template): t = temp