summaryrefslogtreecommitdiffstats
path: root/meta/lib/oe
diff options
context:
space:
mode:
authorChristopher Larson <chris_larson@mentor.com>2012-01-09 15:02:34 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-01-17 14:53:19 +0000
commit7ce97336aad5e6ecefb5e735a13e345d1b8bd8fb (patch)
tree270b4abfa31518895add0e9f2fbea7722288d07c /meta/lib/oe
parent49a0821376ef6146345d673b1e9eddd34aee931a (diff)
downloadpoky-7ce97336aad5e6ecefb5e735a13e345d1b8bd8fb.tar.gz
oe.license: add is_included convenience function
Given a license string and whitelist and blacklist, determine if the license string matches the whitelist and does not match the blacklist. When encountering an OR, it prefers the side with the highest weight (more included licenses). It then checks the inclusion of the flattened list of licenses from there. Returns a tuple holding the boolean state and a list of the applicable licenses which were excluded (or None, if the state is True) Examples: is_included, excluded = oe.license.is_included(licensestr, ['GPL*', 'LGPL*']) is_included, excluded = oe.license.is_included(licensestr, blacklist=['Proprietary', 'CLOSED']) (From OE-Core rev: 7903433898b4683a1c09cc9a6a379421bc9bbd58) Signed-off-by: Christopher Larson <chris_larson@mentor.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oe')
-rw-r--r--meta/lib/oe/license.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/meta/lib/oe/license.py b/meta/lib/oe/license.py
index 7ab66e762f..3543cfe1f6 100644
--- a/meta/lib/oe/license.py
+++ b/meta/lib/oe/license.py
@@ -3,6 +3,7 @@
3 3
4import ast 4import ast
5import re 5import re
6from fnmatch import fnmatchcase as fnmatch
6 7
7class InvalidLicense(StandardError): 8class InvalidLicense(StandardError):
8 def __init__(self, license): 9 def __init__(self, license):
@@ -60,3 +61,38 @@ def flattened_licenses(licensestr, choose_licenses):
60 flatten = FlattenVisitor(choose_licenses) 61 flatten = FlattenVisitor(choose_licenses)
61 flatten.visit_string(licensestr) 62 flatten.visit_string(licensestr)
62 return flatten.licenses 63 return flatten.licenses
64
65def is_included(licensestr, whitelist=None, blacklist=None):
66 """Given a license string and whitelist and blacklist, determine if the
67 license string matches the whitelist and does not match the blacklist.
68
69 Returns a tuple holding the boolean state and a list of the applicable
70 licenses which were excluded (or None, if the state is True)
71 """
72
73 def include_license(license):
74 return (any(fnmatch(license, pattern) for pattern in whitelist) and not
75 any(fnmatch(license, pattern) for pattern in blacklist))
76
77 def choose_licenses(alpha, beta):
78 """Select the option in an OR which is the 'best' (has the most
79 included licenses)."""
80 alpha_weight = len(filter(include_license, alpha))
81 beta_weight = len(filter(include_license, beta))
82 if alpha_weight > beta_weight:
83 return alpha
84 else:
85 return beta
86
87 if not whitelist:
88 whitelist = ['*']
89
90 if not blacklist:
91 blacklist = []
92
93 licenses = flattened_licenses(licensestr, choose_licenses)
94 excluded = filter(lambda lic: not include_license(lic), licenses)
95 if excluded:
96 return False, excluded
97 else:
98 return True, None