@@ -44,59 +44,58 @@ def parsing_file_item(scancode_file_list, has_error, need_matched_license=False)
4444 rc = True
4545 scancode_file_item = []
4646 license_list = {} # Key :[license]+[matched_text], value: MatchedLicense()
47- msg = ""
47+ msg = []
4848
4949 prev_dir = ""
5050 prev_dir_value = False
51- regex = re .compile (r'licenseref-(\S)+' )
51+ regex = re .compile (r'licenseref-(\S+)' , re . IGNORECASE )
5252
5353 if scancode_file_list :
5454 for file in scancode_file_list :
5555 try :
56- is_binary = False
5756 is_dir = False
58- file_path = file [ "path" ]
59-
60- if "is_binary" in file :
61- is_binary = file [ "is_binary" ]
57+ file_path = file . get ( "path" , "" )
58+ if not file_path :
59+ continue
60+ is_binary = file . get ( "is_binary" , False )
6261 if "type" in file :
6362 is_dir = file ["type" ] == "directory"
6463 if is_dir :
6564 prev_dir_value = is_exclude_dir (file_path )
6665 prev_dir = file_path
6766
6867 if not is_binary and not is_dir :
69- licenses = file [ "licenses" ]
70- copyright_list = file [ "copyrights" ]
68+ licenses = file . get ( "licenses" , [])
69+ copyright_list = file . get ( "copyrights" , [])
7170
7271 result_item = ScanItem (file_path )
7372
7473 if has_error and "scan_errors" in file :
75- error_msg = file [ "scan_errors" ]
74+ error_msg = file . get ( "scan_errors" , [])
7675 if len (error_msg ) > 0 :
77- logger .debug (f"Test_msg { file_path } :{ error_msg } " )
7876 result_item .comment = "," .join (error_msg )
7977 scancode_file_item .append (result_item )
8078 continue
81-
82- copyright_value_list = [x ["value" ] for x in copyright_list ]
79+ copyright_value_list = []
80+ for x in copyright_list :
81+ copyright_value_list .append (x .get ("value" , "" ))
8382 result_item .copyright = copyright_value_list
8483
8584 # Set the license value
8685 license_detected = []
8786 if licenses is None or licenses == "" :
8887 continue
8988
90- license_expression_list = file [ "license_expressions" ]
89+ license_expression_list = file . get ( "license_expressions" , {})
9190 if len (license_expression_list ) > 0 :
9291 license_expression_list = [
9392 x .lower () for x in license_expression_list
9493 if x is not None ]
9594
9695 for lic_item in licenses :
9796 license_value = ""
98- key = lic_item [ "key" ]
99- spdx = lic_item [ "spdx_license_key" ]
97+ key = lic_item . get ( "key" , "" )
98+ spdx = lic_item . get ( "spdx_license_key" , "" )
10099 # logger.debug("LICENSE_KEY:"+str(key)+",SPDX:"+str(spdx))
101100
102101 if key is not None and key != "" :
@@ -111,11 +110,10 @@ def parsing_file_item(scancode_file_list, has_error, need_matched_license=False)
111110 if license_value != "" :
112111 if key == "unknown-spdx" :
113112 try :
114- if "matched_text" in lic_item :
115- matched_txt = lic_item ["matched_text" ].lower ()
116- matched = regex .search (matched_txt )
117- if matched :
118- license_value = str (matched .group ())
113+ matched_txt = lic_item .get ("matched_text" , "" )
114+ matched = regex .search (matched_txt )
115+ if matched :
116+ license_value = str (matched .group ())
119117 except Exception :
120118 pass
121119
@@ -136,9 +134,8 @@ def parsing_file_item(scancode_file_list, has_error, need_matched_license=False)
136134 lic_info = MatchedLicense (license_value , lic_category , lic_matched_text , file_path )
137135 license_list [lic_matched_key ] = lic_info
138136
139- matched_rule = lic_item ["matched_rule" ]
140- if matched_rule ["is_license_text" ]:
141- result_item .is_license_text = True
137+ matched_rule = lic_item .get ("matched_rule" , {})
138+ result_item .is_license_text = matched_rule .get ("is_license_text" , False )
142139
143140 if len (license_detected ) > 0 :
144141 result_item .licenses = license_detected
@@ -153,8 +150,7 @@ def parsing_file_item(scancode_file_list, has_error, need_matched_license=False)
153150 scancode_file_item .append (result_item )
154151
155152 except Exception as ex :
156- msg = f"* Error Parsing item: { ex } "
153+ msg . append ( f" Error Parsing item: { ex } ")
157154 rc = False
158- logger .debug (msg )
159-
160- return rc , scancode_file_item , msg .strip (), license_list
155+ msg = list (set (msg ))
156+ return rc , scancode_file_item , msg , license_list
0 commit comments