mirror of
https://git.yoctoproject.org/poky
synced 2026-05-31 12:49:46 +00:00
oe.license: avoid the need to catch SyntaxError
(From OE-Core rev: cace9ddc0edd654877d968643960fa4343472b58) Signed-off-by: Christopher Larson <chris_larson@mentor.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
7ce97336aa
commit
19247e44a3
@@ -48,10 +48,8 @@ def copyleft_should_include(d):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
is_included, excluded = oe.license.is_included(d.getVar('LICENSE', True), include, exclude)
|
is_included, excluded = oe.license.is_included(d.getVar('LICENSE', True), include, exclude)
|
||||||
except oe.license.InvalidLicense as exc:
|
except oe.license.LicenseError as exc:
|
||||||
bb.fatal('%s: %s' % (d.getVar('PF', True), exc))
|
bb.fatal('%s: %s' % (d.getVar('PF', True), exc))
|
||||||
except SyntaxError as exc:
|
|
||||||
bb.warn('%s: error when parsing the LICENSE variable: %s' % (d.getVar('P', True), exc))
|
|
||||||
else:
|
else:
|
||||||
if is_included:
|
if is_included:
|
||||||
return True, None
|
return True, None
|
||||||
|
|||||||
+21
-6
@@ -5,13 +5,25 @@ import ast
|
|||||||
import re
|
import re
|
||||||
from fnmatch import fnmatchcase as fnmatch
|
from fnmatch import fnmatchcase as fnmatch
|
||||||
|
|
||||||
class InvalidLicense(StandardError):
|
class LicenseError(StandardError):
|
||||||
def __init__(self, license):
|
pass
|
||||||
self.license = license
|
|
||||||
StandardError.__init__(self)
|
class LicenseSyntaxError(LicenseError):
|
||||||
|
def __init__(self, licensestr, exc):
|
||||||
|
self.licensestr = licensestr
|
||||||
|
self.exc = exc
|
||||||
|
LicenseError.__init__(self)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "invalid license '%s'" % self.license
|
return "error in '%s': %s" % (self.licensestr, self.exc)
|
||||||
|
|
||||||
|
class InvalidLicense(LicenseError):
|
||||||
|
def __init__(self, license):
|
||||||
|
self.license = license
|
||||||
|
LicenseError.__init__(self)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "invalid characters in license '%s'" % self.license
|
||||||
|
|
||||||
license_operator = re.compile('([&|() ])')
|
license_operator = re.compile('([&|() ])')
|
||||||
license_pattern = re.compile('[a-zA-Z0-9.+_\-]+$')
|
license_pattern = re.compile('[a-zA-Z0-9.+_\-]+$')
|
||||||
@@ -59,7 +71,10 @@ class FlattenVisitor(LicenseVisitor):
|
|||||||
def flattened_licenses(licensestr, choose_licenses):
|
def flattened_licenses(licensestr, choose_licenses):
|
||||||
"""Given a license string and choose_licenses function, return a flat list of licenses"""
|
"""Given a license string and choose_licenses function, return a flat list of licenses"""
|
||||||
flatten = FlattenVisitor(choose_licenses)
|
flatten = FlattenVisitor(choose_licenses)
|
||||||
flatten.visit_string(licensestr)
|
try:
|
||||||
|
flatten.visit_string(licensestr)
|
||||||
|
except SyntaxError as exc:
|
||||||
|
raise LicenseSyntaxError(licensestr, exc)
|
||||||
return flatten.licenses
|
return flatten.licenses
|
||||||
|
|
||||||
def is_included(licensestr, whitelist=None, blacklist=None):
|
def is_included(licensestr, whitelist=None, blacklist=None):
|
||||||
|
|||||||
Reference in New Issue
Block a user