license: Split visit_string in LicenseVisitor
Create get_elements and visit_elements in LicenseVisitor based on visit_string this allow to do modifications on elements before parsing with AST. (From OE-Core rev: c16cf0a0331d128e4ba7341fe28510a9bfb7ee16) Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
parent
8c7082de0a
commit
bb3469f9d3
|
@ -44,8 +44,8 @@ license_operator = re.compile('([' + license_operator_chars + '])')
|
||||||
license_pattern = re.compile('[a-zA-Z0-9.+_\-]+$')
|
license_pattern = re.compile('[a-zA-Z0-9.+_\-]+$')
|
||||||
|
|
||||||
class LicenseVisitor(ast.NodeVisitor):
|
class LicenseVisitor(ast.NodeVisitor):
|
||||||
"""Syntax tree visitor which can accept OpenEmbedded license strings"""
|
"""Get elements based on OpenEmbedded license strings"""
|
||||||
def visit_string(self, licensestr):
|
def get_elements(self, licensestr):
|
||||||
new_elements = []
|
new_elements = []
|
||||||
elements = filter(lambda x: x.strip(), license_operator.split(licensestr))
|
elements = filter(lambda x: x.strip(), license_operator.split(licensestr))
|
||||||
for pos, element in enumerate(elements):
|
for pos, element in enumerate(elements):
|
||||||
|
@ -57,7 +57,16 @@ class LicenseVisitor(ast.NodeVisitor):
|
||||||
raise InvalidLicense(element)
|
raise InvalidLicense(element)
|
||||||
new_elements.append(element)
|
new_elements.append(element)
|
||||||
|
|
||||||
self.visit(ast.parse(' '.join(new_elements)))
|
return new_elements
|
||||||
|
|
||||||
|
"""Syntax tree visitor which can accept elements previously generated with
|
||||||
|
OpenEmbedded license string"""
|
||||||
|
def visit_elements(self, elements):
|
||||||
|
self.visit(ast.parse(' '.join(elements)))
|
||||||
|
|
||||||
|
"""Syntax tree visitor which can accept OpenEmbedded license strings"""
|
||||||
|
def visit_string(self, licensestr):
|
||||||
|
self.visit_elements(self.get_elements(licensestr))
|
||||||
|
|
||||||
class FlattenVisitor(LicenseVisitor):
|
class FlattenVisitor(LicenseVisitor):
|
||||||
"""Flatten a license tree (parsed from a string) by selecting one of each
|
"""Flatten a license tree (parsed from a string) by selecting one of each
|
||||||
|
|
Loading…
Reference in New Issue