|
15 | 15 | from fosslight_util.parsing_yaml import find_sbom_yaml_files, parsing_yml |
16 | 16 | from fosslight_util.output_format import check_output_format |
17 | 17 | from datetime import datetime |
18 | | -from fosslight_prechecker._precheck import precheck_for_project, precheck_for_files, dump_error_msg, get_path_to_find |
| 18 | +from fosslight_prechecker._precheck import precheck_for_project, precheck_for_files, dump_error_msg, \ |
| 19 | + get_path_to_find, DEFAULT_EXCLUDE_EXTENSION_FILES |
| 20 | +from fosslight_prechecker._result import get_total_file_list |
19 | 21 | from reuse.header import run as reuse_header |
20 | 22 | from reuse.download import run as reuse_download |
21 | 23 | from reuse._comment import EXTENSION_COMMENT_STYLE_MAP_LOWERCASE |
|
36 | 38 | logger = logging.getLogger(constant.LOGGER_NAME) |
37 | 39 |
|
38 | 40 |
|
39 | | -def check_file_extension(file_list, is_all_file_list=False): |
40 | | - if file_list != "": |
41 | | - for file in file_list: |
42 | | - try: |
43 | | - file_extension = os.path.splitext(file)[1].lower() |
44 | | - if file_extension == "" and is_all_file_list: |
45 | | - logger.info(f" No extension file : {file}") |
46 | | - if file_extension in EXTENSION_COMMENT_STYLE_MAP_LOWERCASE: |
47 | | - yield file |
48 | | - except Exception as ex: |
49 | | - dump_error_msg(f"Error - Unknown error to check file extension: {ex}") |
50 | | - |
51 | | - |
52 | | -def check_license_and_copyright(path_to_find, all_files, missing_license, missing_copyright): |
53 | | - # Check file extension for each list |
54 | | - all_files_filtered = list(check_file_extension(all_files, True)) |
55 | | - missing_license_filtered = list(check_file_extension(missing_license)) |
56 | | - missing_copyright_filtered = list(check_file_extension(missing_copyright)) |
57 | | - |
58 | | - skip_files = sorted(set(all_files_filtered) - set(missing_license_filtered) - set(missing_copyright_filtered)) |
59 | | - logger.info(f"\n# File list that have both license and copyright : {len(skip_files)} / {len(all_files_filtered)}") |
60 | | - |
61 | | - precheck_for_files(path_to_find, skip_files) |
62 | | - |
63 | | - return missing_license_filtered, missing_copyright_filtered |
64 | | - |
65 | | - |
66 | 41 | def convert_to_spdx_style(input_string): |
67 | 42 | input_string = input_string.replace(" ", "-") |
68 | 43 | input_converted = f"LicenseRef-{input_string}" |
@@ -444,26 +419,31 @@ def add_content(target_path="", input_license="", input_copyright="", output_pat |
444 | 419 | # Download license text file of OSS-pkg-info.yaml |
445 | 420 | download_oss_info_license(path_to_find, input_license) |
446 | 421 |
|
447 | | - # Get all files List in path |
448 | | - all_files_list = get_allfiles_list(path_to_find) |
449 | | - |
450 | 422 | # Get missing license / copyright file list |
451 | | - missing_license, missing_copyright, _, project, _ = precheck_for_project(path_to_find, 'add') |
| 423 | + missing_license, missing_copyright, _, project, prj_report = precheck_for_project(path_to_find) |
452 | 424 |
|
453 | | - # Print Skipped Files |
454 | | - missing_license_filtered, missing_copyright_filtered = \ |
455 | | - check_license_and_copyright(path_to_find, all_files_list, missing_license, missing_copyright) |
| 425 | + # Get total files except excluded file |
| 426 | + total_files_excluded = get_total_file_list(path_to_find, prj_report, DEFAULT_EXCLUDE_EXTENSION_FILES) |
| 427 | + skip_files = sorted(set(total_files_excluded) - set(missing_license) - set(missing_copyright)) |
| 428 | + logger.info(f"\n# File list that have both license and copyright : {len(skip_files)} / {len(total_files_excluded)}") |
| 429 | + |
| 430 | + # Filter by file extension |
| 431 | + missing_license = [file for file in missing_license if os.path.splitext(file)[1].lower() in EXTENSION_COMMENT_STYLE_MAP_LOWERCASE] |
| 432 | + missing_copyright = [file for file in missing_copyright if os.path.splitext(file)[1].lower() in EXTENSION_COMMENT_STYLE_MAP_LOWERCASE] |
| 433 | + |
| 434 | + # Check license and copyright of each file |
| 435 | + precheck_for_files(path_to_find, skip_files) |
456 | 436 |
|
457 | 437 | # Set missing license and copyright |
458 | | - set_missing_license_copyright(missing_license_filtered, |
459 | | - missing_copyright_filtered, |
| 438 | + set_missing_license_copyright(missing_license, |
| 439 | + missing_copyright, |
460 | 440 | project, |
461 | 441 | path_to_find, |
462 | 442 | input_license, |
463 | 443 | input_copyright) |
464 | 444 |
|
465 | 445 | # Find and create representative license file |
466 | | - if input_license != "": |
| 446 | + if input_license != "" and len(missing_license) > 0: |
467 | 447 | find_representative_license(path_to_find, input_license) |
468 | 448 |
|
469 | 449 | save_result_log() |
0 commit comments