Skip to content

Commit

Permalink
Update gcode_macro.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeanon committed Oct 18, 2023
1 parent ba4f0c0 commit 0efbdf2
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions klippy/extras/gcode_macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# This file may be distributed under the terms of the GNU GPLv3 license.
import traceback, logging, ast, copy, json
import jinja2
import pipes


######################################################################
Expand Down Expand Up @@ -72,14 +73,13 @@ class PrinterGCodeMacro:
def __init__(self, config):
self.printer = config.get_printer()
self.env = jinja2.Environment('{%', '%}', '{', '}')
self.env.add_extension('jinja2.ext.loopcontrols')

# jinja does not provide a boolean filter, so a filter is added here
def boolean(value):
lowercase_value = str(value).lower()
return lowercase_value in ["true", "1"]
self.env.add_extension('jinja2.ext.loopcontrols')
self.env.add_extension("jinja2.ext.do")

self.env.filters['boolean'] = boolean
self.env.filters["repr"] = repr
self.env.filters["shell_quote"] = pipes.quote

def load_template(self, config, option, default=None):
name = "%s:%s" % (config.get_name(), option)
Expand All @@ -88,6 +88,10 @@ def load_template(self, config, option, default=None):
else:
script = config.get(option, default)
return TemplateWrapper(self.printer, self.env, name, script)
# jinja does not provide a boolean filter, so a filter is added here
def boolean(self, value):
lowercase_value = str(value).lower()
return lowercase_value in ["true", "1"]
def _action_emergency_stop(self, msg="action_emergency_stop"):
self.printer.invoke_shutdown("Shutdown due to %s" % (msg,))
return ""
Expand Down

0 comments on commit 0efbdf2

Please sign in to comment.