change: Use a compiled regex and use the included match groups instead

of matching yet again.
This commit is contained in:
Harm Weites 2014-08-26 18:10:03 +00:00
parent 80b10e1ac4
commit a59c1f02e8

View File

@ -69,17 +69,17 @@ class Distro(distros.Distro):
# quotes are ignored:
# hostname="bla"
def loadrcconf(self):
RE_MATCH = re.compile(r'^(\w+)="?(\w+)"?')
conf = {}
lines = util.load_file(self.rc_conf_fn).splitlines()
for line in lines:
if not re.match(r'^(.+)=(.+)', line):
m = RE_MATCH.match(line)
if not m:
LOG.debug("Skipping line from /etc/rc.conf: %s", line)
continue
# TODO: just use the matches please...
tok = line.split('=')
key = tok[0]
val = re.sub(r'^"|"$', '', tok[1].rstrip())
key = m.group(1).rstrip()
val = m.group(2).rstrip()
conf[key] = val
return conf