1+ """
2+ SPDX-License-Identifier: MIT
3+
4+ Copyright (c) 2021, SCANOSS
5+
6+ Permission is hereby granted, free of charge, to any person obtaining a copy
7+ of this software and associated documentation files (the "Software"), to deal
8+ in the Software without restriction, including without limitation the rights
9+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ copies of the Software, and to permit persons to whom the Software is
11+ furnished to do so, subject to the following conditions:
12+
13+ The above copyright notice and this permission notice shall be included in
14+ all copies or substantial portions of the Software.
15+
16+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ THE SOFTWARE.
23+ """
124import json
2- import sys
3- from typing import Dict , Any , Callable , List
25+ from typing import Dict , Any
426from scanoss .inspection .policy_check import PolicyCheck , PolicyStatus
5- from scanoss .inspection .utils .license_utils import license_util
6- from scanoss .inspection .utils .markdown_utils import generate_table
7-
827
928class Copyleft (PolicyCheck ):
1029 """
@@ -13,21 +32,23 @@ class Copyleft(PolicyCheck):
1332 """
1433
1534 def __init__ (self , debug : bool = False , trace : bool = True , quiet : bool = False , filepath : str = None ,
16- format : str = 'json' , status : str = None , output : str = None , include : str = None , exclude : str = None , explicit : str = None ):
35+ format_type : str = 'json' , status : str = None , output : str = None , include : str = None ,
36+ exclude : str = None , explicit : str = None ):
1737 """
1838 Initialize the Copyleft class.
1939 :param debug: Enable debug mode
2040 :param trace: Enable trace mode (default True)
2141 :param quiet: Enable quiet mode
2242 :param filepath: Path to the file containing component data
23- :param format : Output format ('json' or 'md')
43+ :param format_type : Output format ('json' or 'md')
2444 :param status: Path to save the status output
2545 :param output: Path to save detailed output
2646 :param include: Licenses to include in the analysis
2747 :param exclude: Licenses to exclude from the analysis
2848 :param explicit: Explicitly defined licenses
2949 """
30- super ().__init__ (debug , trace , quiet , filepath , format , status , output , name = 'Copyleft Policy' )
50+ super ().__init__ (debug , trace , quiet , filepath , format_type , status , output , name = 'Copyleft Policy' )
51+ self .license_util .init (include , exclude , explicit )
3152 self .filepath = filepath
3253 self .format = format
3354 self .output = output
@@ -74,25 +95,10 @@ def _markdown(self, components: list) -> Dict[str,Any]:
7495 rows .append (row )
7596
7697 return {
77- 'details' : f"### Copyleft licenses \n { generate_table (headers ,rows ,centeredColumns )} " ,
98+ 'details' : f"### Copyleft licenses \n { self . generate_table (headers ,rows ,centeredColumns )} " ,
7899 'summary' : f"{ len (components )} component(s) with copyleft licenses were found."
79100 }
80101
81- def _get_formatter (self )-> Callable [[List [dict ]], Dict [str ,Any ]] or None :
82- """
83- Get the appropriate formatter function based on the specified format.
84- :return: Formatter function (either _json or _markdown)
85- """
86- valid_format = self ._is_valid_format ()
87- if not valid_format :
88- return None
89-
90- function_map = {
91- 'json' : self ._json ,
92- 'md' : self ._markdown
93- }
94- return function_map [self .format ]
95-
96102 def _filter_components_with_copyleft_licenses (self , components : list ) -> list :
97103 """
98104 Filter the components list to include only those with copyleft licenses.
@@ -124,12 +130,8 @@ def run(self):
124130
125131 :return: Dictionary containing the inspection results
126132 """
127- if not self ._init ():
128- return PolicyStatus .ERROR .value , {}
129133
130134 self ._debug ()
131-
132- license_util .init (self .include , self .exclude , self .explicit )
133135 components = self ._get_components ()
134136 if components is None :
135137 return PolicyStatus .ERROR .value , {}
0 commit comments