projects.py fix: Read_value() does not return entire section

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2019-06-18 07:37:15 +00:00
commit 3a180033d4
2 changed files with 32 additions and 30 deletions

View file

@ -181,43 +181,44 @@ class Projects(object):
return r.rstrip()
def read_value(self, path, section, key):
self.debug("opening ", path)
def scan_section(f, key):
if key is None:
r = ''
for line in f:
if len(line) and line[0] == '[':
break
r += line
return r if len(r) else None
for line in f:
if len(line) and line[0] == '[':
return None
rr = re.findall('^ *' + key + ' *= *(.*)', line)
if len(rr) > 0:
return rr[0]
return None
def scan_section_debug(f, key):
rr = scan_section(f, key)
#self.debug(" returning", rr)
return rr
try:
file = open(path)
#self.debug("looking for {}::[{}].{}".format(path, section, key))
with open(path, 'r') as f:
if not len(section):
rr = scan_section(f, key)
pat = '[' + section + ']'
for line in f:
if line.rstrip() == pat:
return scan_section(f, key)
return None
except:
self.debug(path, "not found")
# TODO: handle this special case cleaner somewhere up the stack
if section == 'build' and key == 'libname':
return 'none'
return None
r = []
if not len(section):
for line in file:
r = re.findall('^ *' + key + ' *= *(.*)', line)
if (len(r) > 0):
break
else:
in_section = False
pat = '[' + section + ']'
for line in file:
if (line.rstrip() == pat):
in_section = True
continue
if in_section:
if len(line) and line[0] == '[':
break
if key is None:
r.append(line)
else:
r = re.findall('^ *' + key + ' *= *(.*)', line)
#self.debug("key " + key + ": parsed line >" + line + "<, result is " + ' '.join(r))
if (len(r) > 0):
break
file.close()
if len(r):
return r[0]
return None
def get_value(self, name, section, key):
self.debug("getting value [%s].%s for project %s (%s)" %(section, key, name, self.top_name))