Skip to content

Commit 00fd800

Browse files
committed
Prioritize specific categories when sorting
1 parent fb68ace commit 00fd800

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

src/fosslight_source/_license_matched.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@
88
logger = logging.getLogger(constant.LOGGER_NAME)
99
HEADER = ['No', 'Category', 'License',
1010
'Matched Text', 'File Count', 'Files']
11+
LOW_PRIORITY = ['Permissive', 'Public Domain']
12+
1113

1214
class MatchedLicense:
1315
license = ""
1416
files = []
1517
category = ""
1618
matched_text = ""
19+
priority = 0
1720

1821
def __init__(self, lic, category, text, file):
1922
self.files = [file]
2023
self.license = lic
21-
self.category = category
2224
self.matched_text = text
25+
self.set_category(category)
2326

2427
def __del__(self):
2528
pass
@@ -32,6 +35,10 @@ def set_files(self, value):
3235

3336
def set_category(self, value):
3437
self.category = value
38+
if value in LOW_PRIORITY:
39+
self.priority = 1
40+
else:
41+
self.priority = 0
3542

3643
def set_matched_text(self, value):
3744
self.matched_text = value
@@ -43,7 +50,7 @@ def get_row_to_print(self):
4350

4451
def get_license_list_to_print(license_list):
4552
license_items = license_list.values()
46-
license_items = sorted(license_items, key=lambda row: (row.category, row.license))
53+
license_items = sorted(license_items, key=lambda row: (row.priority, row.category, row.license))
4754
license_rows = [lic_item.get_row_to_print() for lic_item in license_items]
4855
license_rows.insert(0, HEADER)
4956
return license_rows

src/fosslight_source/_parsing_scancode_file_item.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def parsing_file_item(scancode_file_list, has_error, need_matched_license=False)
121121

122122
rc = True
123123
scancode_file_item = []
124-
license_list = {} # Key :[license]+[matched_text], value: MatchedLicense()
124+
license_list = {} # Key :[license]+[matched_text], value: MatchedLicense()
125125
msg = "TOTAL FILE COUNT: " + str(len(scancode_file_list)) + "\n"
126126

127127
prev_dir = ""

src/fosslight_source/convert_scancode.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ def convert_json_to_excel(scancode_json, excel_name, result_log, need_license=Fa
5252
file_name = os.path.basename(file)
5353
file_list = sorted(
5454
file_list, key=lambda row: (''.join(row.licenses)))
55-
sheet_list[sheet_SRC_prefix +"_" + file_name] = [scan_item.get_row_to_print() for scan_item in file_list]
55+
sheet_name = sheet_SRC_prefix + "_" + file_name
56+
sheet_list[sheet_name] = [scan_item.get_row_to_print() for scan_item in file_list]
5657
if need_license:
57-
sheet_list[sheet_license_prefix+"_" + file_name] = get_license_list_to_print(lic_list)
58+
lic_sheet_name = sheet_license_prefix + "_" + file_name
59+
sheet_list[lic_sheet_name] = get_license_list_to_print(lic_list)
5860
except Exception as ex:
5961
logger.warning("Error parsing "+file+":" + str(ex))
6062

tox.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ commands =
2323
fosslight_source -p tests/test_files -j -o test_scan/scan_result -m
2424
cat test_scan/scan_result_SRC.csv
2525
fosslight_convert -p tests/json_result/scan_has_error.json -o test_convert/convert_result2
26-
fosslight_convert -p test_scan/scan_result.json -o test_convert/convert_result
26+
fosslight_convert -p test_scan/scan_result.json -o test_convert/convert_result -m
2727
cat test_convert/convert_result_SRC.csv
2828
python tests/cli_test.py
2929

@@ -34,10 +34,10 @@ deps =
3434
commands =
3535
fosslight_source -h
3636
fosslight_convert -h
37-
fosslight_source -p tests/test_files -j -o test_scan/scan_result
37+
fosslight_source -p tests/test_files -j -o test_scan/scan_result -m
3838
cat test_scan/scan_result_SRC.csv
3939
fosslight_convert -p tests/json_result/scan_has_error.json -o test_convert/convert_result2
40-
fosslight_convert -p test_scan/scan_result.json -o test_convert/convert_result
40+
fosslight_convert -p test_scan/scan_result.json -o test_convert/convert_result -m
4141
cat test_convert/convert_result_SRC.csv
4242
python tests/cli_test.py
4343
pytest -v --flake8

0 commit comments

Comments
 (0)