summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
authorAníbal Limón <anibal.limon@linux.intel.com>2015-05-08 20:41:30 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-05-09 22:28:14 +0100
commitbb3469f9d32ff18cf308a308869c0ae3500b5a15 (patch)
treef796fe4021604aef60398664936a7c0b2fef0533 /meta/lib
parent8c7082de0ad2a963b5823834a83723127ddb454e (diff)
downloadpoky-bb3469f9d32ff18cf308a308869c0ae3500b5a15.tar.gz
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>
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oe/license.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/meta/lib/oe/license.py b/meta/lib/oe/license.py
index bc146a28c4..254279db53 100644
--- a/meta/lib/oe/license.py
+++ b/meta/lib/oe/license.py
@@ -44,8 +44,8 @@ license_operator = re.compile('([' + license_operator_chars + '])')
44license_pattern = re.compile('[a-zA-Z0-9.+_\-]+$') 44license_pattern = re.compile('[a-zA-Z0-9.+_\-]+$')
45 45
46class LicenseVisitor(ast.NodeVisitor): 46class LicenseVisitor(ast.NodeVisitor):
47 """Syntax tree visitor which can accept OpenEmbedded license strings""" 47 """Get elements based on OpenEmbedded license strings"""
48 def visit_string(self, licensestr): 48 def get_elements(self, licensestr):
49 new_elements = [] 49 new_elements = []
50 elements = filter(lambda x: x.strip(), license_operator.split(licensestr)) 50 elements = filter(lambda x: x.strip(), license_operator.split(licensestr))
51 for pos, element in enumerate(elements): 51 for pos, element in enumerate(elements):
@@ -57,7 +57,16 @@ class LicenseVisitor(ast.NodeVisitor):
57 raise InvalidLicense(element) 57 raise InvalidLicense(element)
58 new_elements.append(element) 58 new_elements.append(element)
59 59
60 self.visit(ast.parse(' '.join(new_elements))) 60 return new_elements
61
62 """Syntax tree visitor which can accept elements previously generated with
63 OpenEmbedded license string"""
64 def visit_elements(self, elements):
65 self.visit(ast.parse(' '.join(elements)))
66
67 """Syntax tree visitor which can accept OpenEmbedded license strings"""
68 def visit_string(self, licensestr):
69 self.visit_elements(self.get_elements(licensestr))
61 70
62class FlattenVisitor(LicenseVisitor): 71class FlattenVisitor(LicenseVisitor):
63 """Flatten a license tree (parsed from a string) by selecting one of each 72 """Flatten a license tree (parsed from a string) by selecting one of each