From 3a180033d4e7d5dc51f7d90f9ab136caae261e52 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Tue, 18 Jun 2019 07:37:15 +0000 Subject: [PATCH] projects.py fix: Read_value() does not return entire section Signed-off-by: Jan Lindemann --- conf/jcs/Makefile | 1 + scripts/projects.py | 61 +++++++++++++++++++++++---------------------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/conf/jcs/Makefile b/conf/jcs/Makefile index 378763a4..08bdad94 100644 --- a/conf/jcs/Makefile +++ b/conf/jcs/Makefile @@ -2,6 +2,7 @@ TOPDIR = ../.. SUBTREE_INSTALL_PREFIX ?= /etc/jcs SUBTREE_FILES += ./templates/dir/module/Makefile ./templates/dir/src/Makefile +SUBTREE_DIRS += $(dir $(SUBTREE_FILES)) include $(TOPDIR)/make/proj.mk include $(MODDIR)/make/subtree.mk diff --git a/scripts/projects.py b/scripts/projects.py index db6329c8..1c1cf61e 100644 --- a/scripts/projects.py +++ b/scripts/projects.py @@ -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))