|
30 | 30 | from attributecode import ERROR |
31 | 31 | from attributecode import Error |
32 | 32 | from attributecode.licenses import COMMON_LICENSES |
33 | | -from attributecode.model import parse_license_expression |
| 33 | +from attributecode.model import detect_special_char, parse_license_expression |
34 | 34 | from attributecode.util import add_unc |
35 | 35 | from attributecode.attrib_util import multi_sort |
36 | 36 |
|
@@ -88,9 +88,22 @@ def generate(abouts, template=None, variables=None): |
88 | 88 | sorted_license_key_and_context = collections.OrderedDict(sorted(license_key_and_context.items())) |
89 | 89 | license_file_name_and_key[license_text_name] = license_key |
90 | 90 |
|
91 | | - # Convert/map the key in license expression to license name |
92 | | - if about.license_expression.value and about.license_name.value: |
93 | | - special_char_in_expression, lic_list = parse_license_expression(about.license_expression.value) |
| 91 | + # Convert/map the key to name |
| 92 | + if (about.license_expression.value or about.license_key.value) and about.license_name.value: |
| 93 | + if about.license_expression.value: |
| 94 | + special_char, lic_list = parse_license_expression(about.license_expression.value) |
| 95 | + else: |
| 96 | + lic_list = about.license_key.value |
| 97 | + special_char = [] |
| 98 | + for lic in lic_list: |
| 99 | + special_char_list = detect_special_char(lic) |
| 100 | + if special_char_list: |
| 101 | + for char in special_char_list: |
| 102 | + special_char.append(char) |
| 103 | + if special_char: |
| 104 | + error = Error(CRITICAL, 'Special character(s) are not allowed in ' |
| 105 | + 'license_expression or license_key: %s' % special_char) |
| 106 | + return error, '' |
94 | 107 | lic_name_list = about.license_name.value |
95 | 108 | lic_name_expression_list = [] |
96 | 109 |
|
@@ -204,4 +217,4 @@ def generate_and_save(abouts, output_location, template_loc=None, variables=None |
204 | 217 | with io.open(output_location, 'w', encoding='utf-8') as of: |
205 | 218 | of.write(rendered) |
206 | 219 |
|
207 | | - return errors |
| 220 | + return errors, rendered |
0 commit comments