Handle blank lines in element-deps
When merging feature/v2 we have re-enabled the centos-minimal test which has a blank line in the element-deps. The modified get_elements functions added in If97bcd21e45de1b5ed91023fdc441a4617051a6b were not handling this. Fixing this, we can extract this into some common code for element-deps and element-provides. Also, I noticed while debugging that the element list is an iterator from reverse(), so printing it doesn't help. Fix up the debug output. Change-Id: I8e9b079f586e8a36dba3797a0fc03ca1b2041a04
This commit is contained in:
parent
bfca36c772
commit
19f13958f7
@ -44,6 +44,30 @@ class InvalidElementDir(Exception):
|
|||||||
|
|
||||||
class Element(object):
|
class Element(object):
|
||||||
"""An element"""
|
"""An element"""
|
||||||
|
|
||||||
|
def _get_element_set(self, path):
|
||||||
|
"""Get element set from element-[deps|provides] file
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
:param path: path to element description
|
||||||
|
|
||||||
|
:return: the set of elements in the file, or a blank set if
|
||||||
|
the file is not found.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
with open(path) as f:
|
||||||
|
lines = (line.strip() for line in f)
|
||||||
|
# Strip blanks, but do we want to strip comment lines
|
||||||
|
# too? No use case at the moment, and comments might
|
||||||
|
# break other things that poke at the element-* files.
|
||||||
|
lines = (line for line in lines if line)
|
||||||
|
return set(lines)
|
||||||
|
except IOError as e:
|
||||||
|
if e.errno == errno.ENOENT:
|
||||||
|
return set([])
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
def __init__(self, name, path):
|
def __init__(self, name, path):
|
||||||
"""A new element
|
"""A new element
|
||||||
|
|
||||||
@ -53,29 +77,13 @@ class Element(object):
|
|||||||
"""
|
"""
|
||||||
self.name = name
|
self.name = name
|
||||||
self.path = path
|
self.path = path
|
||||||
self.provides = set()
|
|
||||||
self.depends = set()
|
|
||||||
|
|
||||||
# read the provides & depends files for this element into a
|
# read the provides & depends files for this element into a
|
||||||
# set; if the element has them.
|
# set; if the element has them.
|
||||||
provides = os.path.join(path, 'element-provides')
|
self.provides = self._get_element_set(
|
||||||
depends = os.path.join(path, 'element-deps')
|
os.path.join(path, 'element-provides'))
|
||||||
try:
|
self.depends = self._get_element_set(
|
||||||
with open(provides) as p:
|
os.path.join(path, 'element-deps'))
|
||||||
self.provides = set([line.strip() for line in p])
|
|
||||||
except IOError as e:
|
|
||||||
if e.errno == errno.ENOENT:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
raise
|
|
||||||
try:
|
|
||||||
with open(depends) as d:
|
|
||||||
self.depends = set([line.strip() for line in d])
|
|
||||||
except IOError as e:
|
|
||||||
if e.errno == errno.ENOENT:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
raise
|
|
||||||
|
|
||||||
logger.debug("New element : %s", str(self))
|
logger.debug("New element : %s", str(self))
|
||||||
|
|
||||||
@ -170,11 +178,11 @@ def _find_all_elements(paths=None):
|
|||||||
# ELEMENTS_PATH=path1:path2:path3
|
# ELEMENTS_PATH=path1:path2:path3
|
||||||
# we want the elements in "path1" to override "path3"
|
# we want the elements in "path1" to override "path3"
|
||||||
if not paths:
|
if not paths:
|
||||||
paths = reversed(_get_elements_dir().split(':'))
|
paths = list(reversed(_get_elements_dir().split(':')))
|
||||||
else:
|
else:
|
||||||
paths = reversed(paths.split(':'))
|
paths = list(reversed(paths.split(':')))
|
||||||
|
|
||||||
logger.debug("ELEMENTS_PATH is: %s" % paths)
|
logger.debug("ELEMENTS_PATH is: %s" % ":".join(paths))
|
||||||
|
|
||||||
for path in paths:
|
for path in paths:
|
||||||
if not os.path.isdir(path):
|
if not os.path.isdir(path):
|
||||||
|
Loading…
Reference in New Issue
Block a user