summaryrefslogtreecommitdiffstats
path: root/meta/lib/oe/license.py
diff options
context:
space:
mode:
authorChristopher Larson <kergoth@gmail.com>2011-12-04 20:03:51 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2011-12-08 15:24:29 +0000
commit9fb67f895c2616c4dfb8521d3dd5c36758570d83 (patch)
treed89b3e073b0eb281a31ebc9e08c12293413f52dc /meta/lib/oe/license.py
parenta57de1ac9de96eef13f1fd6d37f3f73808d075ac (diff)
downloadpoky-9fb67f895c2616c4dfb8521d3dd5c36758570d83.tar.gz
oe.license: add license flattening code
This flattens a license tree by selecting one side of each OR operation (chosen via the user supplied function). (From OE-Core rev: 6984961314c8ba2aceab9acabb658f96ed249fef) Signed-off-by: Christopher Larson <kergoth@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oe/license.py')
-rw-r--r--meta/lib/oe/license.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/meta/lib/oe/license.py b/meta/lib/oe/license.py
index b230d3ef45..7ab66e762f 100644
--- a/meta/lib/oe/license.py
+++ b/meta/lib/oe/license.py
@@ -30,3 +30,33 @@ class LicenseVisitor(ast.NodeVisitor):
30 new_elements.append(element) 30 new_elements.append(element)
31 31
32 self.visit(ast.parse(' '.join(new_elements))) 32 self.visit(ast.parse(' '.join(new_elements)))
33
34class FlattenVisitor(LicenseVisitor):
35 """Flatten a license tree (parsed from a string) by selecting one of each
36 set of OR options, in the way the user specifies"""
37 def __init__(self, choose_licenses):
38 self.choose_licenses = choose_licenses
39 self.licenses = []
40 LicenseVisitor.__init__(self)
41
42 def visit_Str(self, node):
43 self.licenses.append(node.s)
44
45 def visit_BinOp(self, node):
46 if isinstance(node.op, ast.BitOr):
47 left = FlattenVisitor(self.choose_licenses)
48 left.visit(node.left)
49
50 right = FlattenVisitor(self.choose_licenses)
51 right.visit(node.right)
52
53 selected = self.choose_licenses(left.licenses, right.licenses)
54 self.licenses.extend(selected)
55 else:
56 self.generic_visit(node)
57
58def flattened_licenses(licensestr, choose_licenses):
59 """Given a license string and choose_licenses function, return a flat list of licenses"""
60 flatten = FlattenVisitor(choose_licenses)
61 flatten.visit_string(licensestr)
62 return flatten.licenses