Commit 6cd15818 authored by Alain Takoudjou's avatar Alain Takoudjou

use regex to fix parse error on '+ =' when using buildout 2

parent 73c7af4b
...@@ -35,6 +35,7 @@ import slapos.slap ...@@ -35,6 +35,7 @@ import slapos.slap
import netaddr import netaddr
import logging import logging
import errno import errno
import re
import zc.buildout import zc.buildout
...@@ -59,14 +60,16 @@ class SlapConfigParser(ConfigParser, object): ...@@ -59,14 +60,16 @@ class SlapConfigParser(ConfigParser, object):
if sys.version_info[0] > 2: if sys.version_info[0] > 2:
return super(SlapConfigParser, self).write(fp) return super(SlapConfigParser, self).write(fp)
regex = re.compile(r'^(.*)\s+([+-]{1})$')
if self._defaults: if self._defaults:
fp.write("[%s]\n" % DEFAULTSECT) fp.write("[%s]\n" % DEFAULTSECT)
for (key, value) in self._defaults.items(): for (key, value) in self._defaults.items():
if key.endswith(" +") or key.endswith(" -"): op = ""
line = "%s += %s\n" % (key.replace(' +', '').replace(' -', ''), result = regex.match(key)
str(value).replace('\n', '\n\t')) if result is not None:
else: key, op = result.groups()
line = "%s = %s\n" % (key, str(value).replace('\n', '\n\t'))
line = "%s %s= %s\n" % (key, op, str(value).replace('\n', '\n\t'))
fp.write(line) fp.write(line)
fp.write("\n") fp.write("\n")
for section in self._sections: for section in self._sections:
...@@ -75,11 +78,12 @@ class SlapConfigParser(ConfigParser, object): ...@@ -75,11 +78,12 @@ class SlapConfigParser(ConfigParser, object):
if key == "__name__": if key == "__name__":
continue continue
if (value is not None) or (self._optcre == self.OPTCRE): if (value is not None) or (self._optcre == self.OPTCRE):
if key.endswith(" +") or key.endswith(" -"): op = ""
key = " += ".join((key.replace(' +', '').replace(' -', ''), result = regex.match(key)
str(value).replace('\n', '\n\t'))) if result is not None:
else: key, op = result.groups()
key = " = ".join((key, str(value).replace('\n', '\n\t'))) key = "%s %s= %s" % (key, op, str(value).replace('\n', '\n\t'))
fp.write("%s\n" % key) fp.write("%s\n" % key)
fp.write("\n") fp.write("\n")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment