@@ -64,7 +64,7 @@ def __init__( # noqa: PLR0913
6464 explicit : str = None ,
6565 ):
6666 """
67- Initialize the Copyleft class.
67+ Initialise the Copyleft class.
6868
6969 :param debug: Enable debug mode
7070 :param trace: Enable trace mode (default True)
@@ -111,25 +111,7 @@ def _markdown(self, components: list[Component]) -> Dict[str, Any]:
111111 :param components: List of components with copyleft licenses
112112 :return: Dictionary with formatted Markdown details and summary
113113 """
114- # A component is considered unique by its combination of PURL (Package URL) and license
115- component_licenses = self ._group_components_by_license (components )
116- headers = ['Component' , 'License' , 'URL' , 'Copyleft' ]
117- centered_columns = [1 , 4 ]
118- rows : [[]] = []
119- for comp_lic_item in component_licenses :
120- row = [
121- comp_lic_item ['purl' ],
122- comp_lic_item ['spdxid' ],
123- comp_lic_item ['url' ],
124- 'YES' if comp_lic_item ['copyleft' ] else 'NO' ,
125- ]
126- rows .append (row )
127- # End license loop
128- # End component loop
129- return {
130- 'details' : f'### Copyleft licenses\n { self .generate_table (headers , rows , centered_columns )} \n ' ,
131- 'summary' : f'{ len (component_licenses )} component(s) with copyleft licenses were found.\n ' ,
132- }
114+ return self ._md_summary_generator (components , self .generate_table )
133115
134116 def _jira_markdown (self , components : list [Component ]) -> Dict [str , Any ]:
135117 """
@@ -138,27 +120,51 @@ def _jira_markdown(self, components: list[Component]) -> Dict[str, Any]:
138120 :param components: List of components with copyleft licenses
139121 :return: Dictionary with formatted Markdown details and summary
140122 """
123+ return self ._md_summary_generator (components , self .generate_jira_table )
124+
125+ def _md_summary_generator (self , components : list [Component ], table_generator ):
126+ """
127+ Generates a Markdown summary for components with a focus on copyleft licenses.
128+
129+ This function processes a list of components and groups them by their licenses.
130+ For each group, the components are mapped with their license data and a tabular representation is created.
131+ The generated Markdown summary includes a detailed table and a summary overview.
132+
133+ Parameters:
134+ components: list[Component]
135+ A list of Component objects to process for generating the summary.
136+ table_generator
137+ A callable function to generate tabular data for components.
138+
139+ Returns:
140+ dict
141+ A dictionary containing two keys:
142+ - 'details': A detailed Markdown representation including a table of components
143+ and associated copyleft license data.
144+ - 'summary': A textual summary highlighting the total number of components
145+ with copyleft licenses.
146+ """
141147 # A component is considered unique by its combination of PURL (Package URL) and license
142148 component_licenses = self ._group_components_by_license (components )
143149 headers = ['Component' , 'License' , 'URL' , 'Copyleft' ]
144150 centered_columns = [1 , 4 ]
145- rows : [[]] = []
151+ rows = []
146152 for comp_lic_item in component_licenses :
147- row = [
148- comp_lic_item ['purl' ],
149- comp_lic_item ['spdxid' ],
150- comp_lic_item ['url' ],
151- 'YES' if comp_lic_item ['copyleft' ] else 'NO' ,
152- ]
153- rows .append (row )
154- # End license loop
153+ row = [
154+ comp_lic_item ['purl' ],
155+ comp_lic_item ['spdxid' ],
156+ comp_lic_item ['url' ],
157+ 'YES' if comp_lic_item ['copyleft' ] else 'NO' ,
158+ ]
159+ rows .append (row )
160+ # End license loop
155161 # End component loop
156162 return {
157- 'details' : f'{ self . generate_jira_table (headers , rows , centered_columns )} ' ,
163+ 'details' : f'### Copyleft Licenses \n { table_generator (headers , rows , centered_columns )} . \n ' ,
158164 'summary' : f'{ len (component_licenses )} component(s) with copyleft licenses were found.\n ' ,
159165 }
160166
161- def _get_components_with_copyleft_licenses (self , components : list ) -> list [Component ]:
167+ def _get_components_with_copyleft_licenses (self , components : list ) -> list [Dict ]:
162168 """
163169 Filter the components list to include only those with copyleft licenses.
164170
@@ -223,21 +229,8 @@ def run(self):
223229 return PolicyStatus .ERROR .value , {}
224230 # Get a list of copyleft components if they exist
225231 copyleft_components = self ._get_components_with_copyleft_licenses (components )
226- # Get a formatter for the output results
227- formatter = self ._get_formatter ()
228- if formatter is None :
229- return PolicyStatus .ERROR .value , {}
230- # Format the results
231- data = formatter (copyleft_components )
232- ## Save outputs if required
233- self .print_to_file_or_stdout (data ['details' ], self .output )
234- self .print_to_file_or_stderr (data ['summary' ], self .status )
235- # Check to see if we have policy violations
236- if len (copyleft_components ) <= 0 :
237- return PolicyStatus .POLICY_FAIL .value , data
238- return PolicyStatus .POLICY_SUCCESS .value , data
239-
240-
232+ # Format the results and save to files if required
233+ return self ._generate_formatter_report (copyleft_components )
241234#
242235# End of Copyleft Class
243236#
0 commit comments