@@ -44,116 +44,117 @@ 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 = f"TOTAL FILE COUNT: { len ( scancode_file_list ) } \n "
47+ msg = " "
4848
4949 prev_dir = ""
5050 prev_dir_value = False
5151 regex = re .compile (r'licenseref-(\S)+' )
5252
53- for file in scancode_file_list :
54- try :
55- is_binary = False
56- is_dir = False
57- file_path = file ["path" ]
58-
59- if "is_binary" in file :
60- is_binary = file ["is_binary" ]
61- if "type" in file :
62- is_dir = file ["type" ] == "directory"
63- if is_dir :
64- prev_dir_value = is_exclude_dir (file_path )
65- prev_dir = file_path
66-
67- if not is_binary and not is_dir :
68- licenses = file ["licenses" ]
69- copyright_list = file ["copyrights" ]
70-
71- result_item = ScanItem (file_path )
72-
73- if has_error and "scan_errors" in file :
74- error_msg = file ["scan_errors" ]
75- if len (error_msg ) > 0 :
76- logger .debug (f"Test_msg { file_path } :{ error_msg } " )
77- result_item .comment = "," .join (error_msg )
78- scancode_file_item .append (result_item )
53+ if scancode_file_list :
54+ for file in scancode_file_list :
55+ try :
56+ is_binary = False
57+ is_dir = False
58+ file_path = file ["path" ]
59+
60+ if "is_binary" in file :
61+ is_binary = file ["is_binary" ]
62+ if "type" in file :
63+ is_dir = file ["type" ] == "directory"
64+ if is_dir :
65+ prev_dir_value = is_exclude_dir (file_path )
66+ prev_dir = file_path
67+
68+ if not is_binary and not is_dir :
69+ licenses = file ["licenses" ]
70+ copyright_list = file ["copyrights" ]
71+
72+ result_item = ScanItem (file_path )
73+
74+ if has_error and "scan_errors" in file :
75+ error_msg = file ["scan_errors" ]
76+ if len (error_msg ) > 0 :
77+ logger .debug (f"Test_msg { file_path } :{ error_msg } " )
78+ result_item .comment = "," .join (error_msg )
79+ scancode_file_item .append (result_item )
80+ continue
81+
82+ copyright_value_list = [x ["value" ] for x in copyright_list ]
83+ result_item .copyright = copyright_value_list
84+
85+ # Set the license value
86+ license_detected = []
87+ if licenses is None or licenses == "" :
7988 continue
8089
81- copyright_value_list = [x ["value" ] for x in copyright_list ]
82- result_item .copyright = copyright_value_list
83-
84- # Set the license value
85- license_detected = []
86- if licenses is None or licenses == "" :
87- continue
88-
89- license_expression_list = file ["license_expressions" ]
90- if len (license_expression_list ) > 0 :
91- license_expression_list = [
92- x .lower () for x in license_expression_list
93- if x is not None ]
94-
95- for lic_item in licenses :
96- license_value = ""
97- key = lic_item ["key" ]
98- spdx = lic_item ["spdx_license_key" ]
99- # logger.debug("LICENSE_KEY:"+str(key)+",SPDX:"+str(spdx))
100-
101- if key is not None and key != "" :
102- key = key .lower ()
103- license_value = key
104- if key in license_expression_list :
105- license_expression_list .remove (key )
106- if spdx is not None and spdx != "" :
107- # Print SPDX instead of Key.
108- license_value = spdx .lower ()
109-
110- if license_value != "" :
111- if key == "unknown-spdx" :
112- try :
90+ license_expression_list = file ["license_expressions" ]
91+ if len (license_expression_list ) > 0 :
92+ license_expression_list = [
93+ x .lower () for x in license_expression_list
94+ if x is not None ]
95+
96+ for lic_item in licenses :
97+ license_value = ""
98+ key = lic_item ["key" ]
99+ spdx = lic_item ["spdx_license_key" ]
100+ # logger.debug("LICENSE_KEY:"+str(key)+",SPDX:"+str(spdx))
101+
102+ if key is not None and key != "" :
103+ key = key .lower ()
104+ license_value = key
105+ if key in license_expression_list :
106+ license_expression_list .remove (key )
107+ if spdx is not None and spdx != "" :
108+ # Print SPDX instead of Key.
109+ license_value = spdx .lower ()
110+
111+ if license_value != "" :
112+ if key == "unknown-spdx" :
113+ 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 ())
119+ except Exception :
120+ pass
121+
122+ for word in replace_word :
123+ if word in license_value :
124+ license_value = license_value .replace (word , "" )
125+ license_detected .append (license_value )
126+
127+ # Add matched licenses
128+ if need_matched_license and "category" in lic_item :
129+ lic_category = lic_item ["category" ]
113130 if "matched_text" in lic_item :
114- matched_txt = lic_item ["matched_text" ].lower ()
115- matched = regex .search (matched_txt )
116- if matched :
117- license_value = str (matched .group ())
118- except Exception :
119- pass
120-
121- for word in replace_word :
122- if word in license_value :
123- license_value = license_value .replace (word , "" )
124- license_detected .append (license_value )
125-
126- # Add matched licenses
127- if need_matched_license and "category" in lic_item :
128- lic_category = lic_item ["category" ]
129- if "matched_text" in lic_item :
130- lic_matched_text = lic_item ["matched_text" ]
131- lic_matched_key = license_value + lic_matched_text
132- if lic_matched_key in license_list :
133- license_list [lic_matched_key ].set_files (file_path )
134- else :
135- lic_info = MatchedLicense (license_value , lic_category , lic_matched_text , file_path )
136- license_list [lic_matched_key ] = lic_info
137-
138- matched_rule = lic_item ["matched_rule" ]
139- if matched_rule ["is_license_text" ]:
140- result_item .is_license_text = True
141-
142- if len (license_detected ) > 0 :
143- result_item .licenses = license_detected
131+ lic_matched_text = lic_item ["matched_text" ]
132+ lic_matched_key = license_value + lic_matched_text
133+ if lic_matched_key in license_list :
134+ license_list [lic_matched_key ].set_files (file_path )
135+ else :
136+ lic_info = MatchedLicense (license_value , lic_category , lic_matched_text , file_path )
137+ license_list [lic_matched_key ] = lic_info
138+
139+ matched_rule = lic_item ["matched_rule" ]
140+ if matched_rule ["is_license_text" ]:
141+ result_item .is_license_text = True
142+
143+ if len (license_detected ) > 0 :
144+ result_item .licenses = license_detected
145+
146+ if len (license_expression_list ) > 0 :
147+ license_expression_list = list (
148+ set (license_expression_list ))
149+ result_item .comment = ',' .join (license_expression_list )
150+
151+ if is_exclude_file (file_path , prev_dir , prev_dir_value ):
152+ result_item .exclude = True
153+ scancode_file_item .append (result_item )
144154
145- if len (license_expression_list ) > 0 :
146- license_expression_list = list (
147- set (license_expression_list ))
148- result_item .comment = ',' .join (license_expression_list )
149-
150- if is_exclude_file (file_path , prev_dir , prev_dir_value ):
151- result_item .exclude = True
152- scancode_file_item .append (result_item )
153-
154- except Exception as ex :
155- msg += f"* Error Parsing item: { ex } "
156- rc = False
157- logger .debug (msg )
155+ except Exception as ex :
156+ msg = f"* Error Parsing item: { ex } "
157+ rc = False
158+ logger .debug (msg )
158159
159160 return rc , scancode_file_item , msg .strip (), license_list
0 commit comments