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 <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-10-16 11:45:20 -04:00
parent 368703fd78
commit 08d03ae0eb
1 changed files with 8 additions and 0 deletions

View File

@ -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)