@@ -50,6 +50,8 @@ def generate(abouts, template_string=None):
5050 license_key_and_context = {}
5151 sorted_license_key_and_context = {}
5252 license_text_name_and_key = {}
53+ license_key_to_license_name = {}
54+ # FIXME: This need to be simplified
5355 for about in abouts :
5456 # about.license_file.value is a OrderDict with license_text_name as
5557 # the key and the license text as the value
@@ -67,8 +69,37 @@ def generate(abouts, template_string=None):
6769 sorted_license_key_and_context = collections .OrderedDict (sorted (license_key_and_context .items ()))
6870 license_text_name_and_key [license_text_name ] = license_key
6971
72+ # Convert/map the key in license expression to license name
73+ if about .license_expression .value and about .license_name .value :
74+ # Split the license expression into list with license key and condition keyword
75+ lic_expression_list = about .license_expression .value .split ()
76+
77+
78+ lic_name_list = about .license_name .value
79+ lic_name_expression_list = []
80+
81+ # The order of the license_name and key should be the same
82+ # The length for both list should be the same excluding the condition keyword
83+ # such as 'and' and 'or'
84+ assert len (lic_name_list ) <= len (lic_expression_list )
85+
86+ # Map the licence key to license name
87+ index_for_license_name_list = 0
88+ for key in lic_expression_list :
89+ if key .lower () == 'and' or key .lower () == 'or' :
90+ lic_name_expression_list .append (key )
91+ else :
92+ lic_name_expression_list .append (lic_name_list [index_for_license_name_list ])
93+ license_key_to_license_name [key ] = lic_name_list [index_for_license_name_list ]
94+ index_for_license_name_list = index_for_license_name_list + 1
95+ # Join the license name expression into a single string
96+ lic_name_expression = ' ' .join (lic_name_expression_list )
97+
98+ # Add the license name expression string into the about object
99+ about .license_name_expression = lic_name_expression
100+
70101 rendered = template .render (abouts = abouts , common_licenses = COMMON_LICENSES , license_key_and_context = sorted_license_key_and_context ,
71- license_text_name_and_key = license_text_name_and_key )
102+ license_text_name_and_key = license_text_name_and_key , license_key_to_license_name = license_key_to_license_name )
72103 except Exception , e :
73104 line = getattr (e , 'lineno' , None )
74105 ln_msg = ' at line: %r' % line if line else ''
0 commit comments