@@ -235,7 +235,7 @@ class StringField(Field):
235235 def _validate (self , * args , ** kwargs ):
236236 errors = super (StringField , self )._validate (* args , ** kwargs )
237237 no_special_char_field = [
238- 'license_expression' , 'license_key' , 'license_name' ]
238+ 'license_expression' , 'license_key' , 'license_name' , 'declared_license_expression' , 'other_license_expression ' ]
239239 name = self .name
240240 if name in no_special_char_field :
241241 val = self .value
@@ -904,6 +904,8 @@ def set_standard_fields(self):
904904 ('license_url' , UrlListField ()),
905905 ('spdx_license_expression' , SingleLineField ()),
906906 ('spdx_license_key' , ListField ()),
907+ ('declared_license_expression' , SingleLineField ()),
908+ ('other_license_expression' , SingleLineField ()),
907909 ('copyright' , StringField ()),
908910 ('notice_file' , FileTextField ()),
909911 ('notice_url' , UrlField ()),
@@ -1500,34 +1502,53 @@ def dump_lic(self, location, license_dict):
15001502 if not posixpath .exists (parent ):
15011503 os .makedirs (add_unc (parent ))
15021504
1505+ licenses_list = []
15031506 if self .license_expression .present :
15041507 special_char_in_expression , lic_list , invalid_lic_exp = parse_license_expression (
15051508 self .license_expression .value )
1506- self .license_key .value = lic_list
1509+ if lic_list :
1510+ for lic in lic_list :
1511+ if lic not in licenses_list :
1512+ licenses_list .append (lic )
1513+ if self .declared_license_expression .present :
1514+ special_char_in_expression , lic_list , invalid_lic_exp = parse_license_expression (
1515+ self .declared_license_expression .value )
1516+ if lic_list :
1517+ for lic in lic_list :
1518+ if lic not in licenses_list :
1519+ licenses_list .append (lic )
1520+ if self .other_license_expression .present :
1521+ special_char_in_expression , lic_list , invalid_lic_exp = parse_license_expression (
1522+ self .other_license_expression .value )
1523+ if lic_list :
1524+ for lic in lic_list :
1525+ if lic not in licenses_list :
1526+ licenses_list .append (lic )
1527+ if licenses_list :
1528+ self .license_key .value = licenses_list
15071529 self .license_key .present = True
1508- if not special_char_in_expression and not invalid_lic_exp :
1509- for lic_key in lic_list :
1510- license_name = ''
1511- license_filename = ''
1512- license_context = ''
1513- license_url = ''
1514- spdx_license_key = ''
1515- if lic_key in license_dict :
1516- license_path = posixpath .join (parent , lic_key )
1517- license_path += u'.LICENSE'
1518- license_path = add_unc (license_path )
1519- license_name , license_filename , license_context , license_url , spdx_license_key = license_dict [
1520- lic_key ]
1521- license_info = (lic_key , license_name , license_filename ,
1522- license_context , license_url , spdx_license_key )
1523- license_key_name_context_url .append (license_info )
1524- with open (license_path , mode = 'w' , encoding = 'utf-8' , newline = '\n ' , errors = 'replace' ) as lic :
1525- lic .write (license_context )
1526- else :
1527- # Invalid license issue is already handled
1528- license_info = (lic_key , license_name , license_filename ,
1529- license_context , license_url , spdx_license_key )
1530- license_key_name_context_url .append (license_info )
1530+ for lic_key in licenses_list :
1531+ license_name = ''
1532+ license_filename = ''
1533+ license_context = ''
1534+ license_url = ''
1535+ spdx_license_key = ''
1536+ if lic_key in license_dict :
1537+ license_path = posixpath .join (parent , lic_key )
1538+ license_path += u'.LICENSE'
1539+ license_path = add_unc (license_path )
1540+ license_name , license_filename , license_context , license_url , spdx_license_key = license_dict [
1541+ lic_key ]
1542+ license_info = (lic_key , license_name , license_filename ,
1543+ license_context , license_url , spdx_license_key )
1544+ license_key_name_context_url .append (license_info )
1545+ with open (license_path , mode = 'w' , encoding = 'utf-8' , newline = '\n ' , errors = 'replace' ) as lic :
1546+ lic .write (license_context )
1547+ else :
1548+ # Invalid license issue is already handled
1549+ license_info = (lic_key , license_name , license_filename ,
1550+ license_context , license_url , spdx_license_key )
1551+ license_key_name_context_url .append (license_info )
15311552
15321553 return license_key_name_context_url
15331554
@@ -1903,17 +1924,29 @@ def pre_process_and_fetch_license_dict(abouts, from_check=False, api_url=None, a
19031924 about .license_expression .value = lic_exp
19041925 about .license_expression .present = True
19051926
1927+ afp = ''
1928+ if about .about_file_path :
1929+ afp = about .about_file_path
1930+
19061931 if not about .license_expression .value and about .spdx_license_expression .value :
19071932 lic_exp_value = ""
19081933 special_char_in_expression , lic_list , invalid_lic_exp = parse_license_expression (
19091934 about .spdx_license_expression .value )
19101935 if special_char_in_expression or invalid_lic_exp :
19111936 if special_char_in_expression :
1912- msg = (about .about_file_path + u": The following character(s) cannot be in the spdx_license_expression: " +
1913- str (special_char_in_expression ))
1937+ if afp :
1938+ msg = (afp + u": The following character(s) cannot be in the spdx_license_expression: " +
1939+ str (special_char_in_expression ))
1940+ else :
1941+ msg = (u"The following character(s) cannot be in the spdx_license_expression: " +
1942+ str (special_char_in_expression ))
19141943 else :
1915- msg = (about .about_file_path + u": This spdx_license_expression is invalid: " +
1916- str (invalid_lic_exp ))
1944+ if afp :
1945+ msg = (afp + u": This spdx_license_expression is invalid: " +
1946+ str (invalid_lic_exp ))
1947+ else :
1948+ msg = (u"This spdx_license_expression is invalid: " +
1949+ str (invalid_lic_exp ))
19171950 errors .append (Error (ERROR , msg ))
19181951 else :
19191952 spdx_lic_exp_segment = about .spdx_license_expression .value .split ()
@@ -1928,83 +1961,139 @@ def pre_process_and_fetch_license_dict(abouts, from_check=False, api_url=None, a
19281961 about .license_expression .value = lic_exp_value
19291962 about .license_expression .present = True
19301963
1964+ lic_exp_list = []
1965+
1966+ if about .declared_license_expression .value :
1967+ special_char_in_expression , lic_list , invalid_lic_exp = parse_license_expression (
1968+ about .declared_license_expression .value )
1969+ if special_char_in_expression :
1970+ if afp :
1971+ msg = (afp + u": The following character(s) cannot be in the declared_license_expression: " +
1972+ str (special_char_in_expression ))
1973+ else :
1974+ msg = (u"The following character(s) cannot be in the declared_license_expression: " +
1975+ str (special_char_in_expression ))
1976+ errors .append (Error (ERROR , msg ))
1977+ if invalid_lic_exp :
1978+ if afp :
1979+ msg = (afp + u": This declared_license_expression is invalid: " +
1980+ str (invalid_lic_exp ))
1981+ else :
1982+ msg = (u"This declared_license_expression is invalid: " +
1983+ str (invalid_lic_exp ))
1984+ errors .append (Error (ERROR , msg ))
1985+ if lic_list :
1986+ lic_exp_list .extend (lic_list )
1987+
1988+ if about .other_license_expression .value :
1989+ special_char_in_expression , lic_list , invalid_lic_exp = parse_license_expression (
1990+ about .other_license_expression .value )
1991+ if special_char_in_expression :
1992+ if afp :
1993+ msg = (afp + u": The following character(s) cannot be in the other_license_expression: " +
1994+ str (special_char_in_expression ))
1995+ else :
1996+ msg = (u"This declared_license_expression is invalid: " +
1997+ str (invalid_lic_exp ))
1998+ errors .append (Error (ERROR , msg ))
1999+ if invalid_lic_exp :
2000+ if afp :
2001+ msg = (afp + u": This other_license_expression is invalid: " +
2002+ str (invalid_lic_exp ))
2003+ else :
2004+ msg = (u"This other_license_expression is invalid: " +
2005+ str (invalid_lic_exp ))
2006+ errors .append (Error (ERROR , msg ))
2007+ if lic_list :
2008+ lic_exp_list .extend (lic_list )
2009+
19312010 if about .license_expression .value :
19322011 special_char_in_expression , lic_list , invalid_lic_exp = parse_license_expression (
19332012 about .license_expression .value )
1934- if special_char_in_expression or invalid_lic_exp :
1935- if special_char_in_expression :
1936- msg = (about . about_file_path + u": The following character(s) cannot be in the license_expression: " +
2013+ if special_char_in_expression :
2014+ if afp :
2015+ msg = (afp + u": The following character(s) cannot be in the license_expression: " +
19372016 str (special_char_in_expression ))
19382017 else :
1939- msg = (about .about_file_path + u": This license_expression is invalid: " +
2018+ msg = (u"The following character(s) cannot be in the license_expression: " +
2019+ str (special_char_in_expression ))
2020+ errors .append (Error (ERROR , msg ))
2021+ if invalid_lic_exp :
2022+ if afp :
2023+ msg = (afp + u": This license_expression is invalid: " +
2024+ str (invalid_lic_exp ))
2025+ else :
2026+ msg = (u"This license_expression is invalid: " +
19402027 str (invalid_lic_exp ))
19412028 errors .append (Error (ERROR , msg ))
1942- else :
1943- for lic_key in lic_list :
1944- if not lic_key in captured_license :
1945- lic_url = ''
1946- license_name = ''
1947- license_filename = ''
1948- license_text = ''
1949- spdx_license_key = ''
1950- detail_list = []
1951- captured_license .append (lic_key )
1952- if api_key :
1953- license_data , errs = api .get_license_details_from_api (
1954- url , api_key , lic_key )
1955- # Catch incorrect API URL
1956- if errs :
1957- _ , msg = errs [0 ]
1958- if msg == "Invalid '--api_url'. License generation is skipped." :
1959- errors .extend (errs )
1960- return key_text_dict , errors
1961- for severity , message in errs :
1962- msg = (about .about_file_path + ": " + message )
1963- errors .append (Error (severity , msg ))
1964- # We don't want to actually get the license information from the
1965- # check utility
2029+ if lic_list :
2030+ lic_exp_list .extend (lic_list )
2031+ if not about .license_key .value :
2032+ about .license_key .value = lic_list
2033+
2034+ if lic_exp_list :
2035+ for lic_key in lic_exp_list :
2036+ if not lic_key in captured_license :
2037+ lic_url = ''
2038+ license_name = ''
2039+ license_filename = ''
2040+ license_text = ''
2041+ spdx_license_key = ''
2042+ detail_list = []
2043+ captured_license .append (lic_key )
2044+ if api_key :
2045+ license_data , errs = api .get_license_details_from_api (
2046+ url , api_key , lic_key )
2047+ # Catch incorrect API URL
2048+ if errs :
2049+ _ , msg = errs [0 ]
2050+ if msg == "Invalid '--api_url'. License generation is skipped." :
2051+ errors .extend (errs )
2052+ return key_text_dict , errors
2053+ for severity , message in errs :
2054+ msg = (afp + ": " + message )
2055+ errors .append (Error (severity , msg ))
2056+ # We don't want to actually get the license information from the
2057+ # check utility
2058+ if from_check :
2059+ continue
2060+ if not license_data :
2061+ continue
2062+ license_name = license_data .get ('short_name' , '' )
2063+ license_text = license_data .get ('full_text' , '' )
2064+ spdx_license_key = license_data .get (
2065+ 'spdx_license_key' , '' )
2066+ license_filename = lic_key + '.LICENSE'
2067+ lic_url = lic_urn + lic_key
2068+ else :
2069+ license_url = url + lic_key + '.json'
2070+ license_text_url = url + lic_key + '.LICENSE'
2071+ try :
2072+ json_url_content = get (license_url ).text
2073+ # We don't want to actually get the license
2074+ # information from the check utility
19662075 if from_check :
19672076 continue
1968- if not license_data :
1969- continue
1970- license_name = license_data .get ('short_name' , '' )
1971- license_text = license_data .get ('full_text' , '' )
1972- spdx_license_key = license_data .get (
1973- 'spdx_license_key' , '' )
1974- license_filename = lic_key + '.LICENSE'
1975- lic_url = lic_urn + lic_key
1976- else :
1977- license_url = url + lic_key + '.json'
1978- license_text_url = url + lic_key + '.LICENSE'
1979- try :
1980- json_url_content = get (license_url ).text
1981- # We don't want to actually get the license
1982- # information from the check utility
1983- if from_check :
1984- continue
1985- data = json .loads (json_url_content )
1986- license_name = data ['short_name' ]
1987- license_text = get (license_text_url ).text
1988- license_filename = data ['key' ] + '.LICENSE'
1989- lic_url = url + license_filename
1990- spdx_license_key = data ['spdx_license_key' ]
1991- except :
1992- try :
1993- msg = about .about_file_path + u" : Invalid 'license': " + lic_key
1994- except :
1995- msg = u"Invalid 'license': " + lic_key
1996- errors .append (Error (ERROR , msg ))
1997- continue
1998- if not from_check :
1999- detail_list .append (license_name )
2000- detail_list .append (license_filename )
2001- detail_list .append (license_text )
2002- detail_list .append (lic_url )
2003- detail_list .append (spdx_license_key )
2004- key_text_dict [lic_key ] = detail_list
2005- if not about .license_key .value :
2006- about .license_key .value = lic_list
2007-
2077+ data = json .loads (json_url_content )
2078+ license_name = data ['short_name' ]
2079+ license_text = get (license_text_url ).text
2080+ license_filename = data ['key' ] + '.LICENSE'
2081+ lic_url = url + license_filename
2082+ spdx_license_key = data ['spdx_license_key' ]
2083+ except :
2084+ if afp :
2085+ msg = afp + u" : Invalid 'license': " + lic_key
2086+ else :
2087+ msg = u"Invalid 'license': " + lic_key
2088+ errors .append (Error (ERROR , msg ))
2089+ continue
2090+ if not from_check :
2091+ detail_list .append (license_name )
2092+ detail_list .append (license_filename )
2093+ detail_list .append (license_text )
2094+ detail_list .append (lic_url )
2095+ detail_list .append (spdx_license_key )
2096+ key_text_dict [lic_key ] = detail_list
20082097 return key_text_dict , errors
20092098
20102099
0 commit comments