From 08d03ae0ebaf64fe3a79a8b636c0d21d33f1d4ba Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 16 Oct 2018 11:45:20 -0400 Subject: [PATCH] configfile: Strip trailing comments The Python 2.x ConfigParser doesn't support stripping of trailing '#' style comments. Do that manually before parsing the config. Signed-off-by: Kevin O'Connor --- klippy/configfile.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/klippy/configfile.py b/klippy/configfile.py index 57e61740..a7696324 100644 --- a/klippy/configfile.py +++ b/klippy/configfile.py @@ -150,6 +150,14 @@ class PrinterConfig: lines[lineno] = '#' + lines[lineno] return "\n".join(lines) def _build_config_wrapper(self, data): + # Strip trailing comments from config + lines = data.split('\n') + for i, line in enumerate(lines): + pos = line.find('#') + if pos >= 0: + lines[i] = line[:pos] + data = '\n'.join(lines) + # Read and process config file sfile = StringIO.StringIO(data) fileconfig = ConfigParser.RawConfigParser() fileconfig.readfp(sfile)