Skip to content

Commit 35639bd

Browse files
author
Makoto Koishi
committed
Logging level changed for exception from os.walk. Program description rephrased.
1 parent 9e45f93 commit 35639bd

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

examples/client/consolidated_file_report.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'''
2-
Created on August 23, 2023
2+
Created on August 30, 2023
33
44
@author: mkoishi
55
66
Generate reports which consolidates information on BOM components, versions with license information, BOM files with
77
license and copyright information from KB and license search (discoveries - file licenses or file copyrights),
8-
and BlackDuck unmatched files.
8+
and BlackDuck unmatched files in the target source code.
99
1010
Copyright (C) 2023 Synopsys, Inc.
1111
http://www.synopsys.com/
@@ -44,9 +44,10 @@
4444
from zipfile import ZipFile
4545

4646
program_description = \
47-
'''This script collects BlackDuck reports for version details and discoveries, and it generates new reports.
47+
'''This script collects BlackDuck reports for version details and discoveries and generates new reports.
4848
The newly generated reports are a report of BOM component-versions with license information, a report of BOM files that consolidates licenses and copyright texts information from KB and discoveries (e.g., file licenses, file copyrights), and a report of BlackDuck unmatched files.
49-
Optionally, Synopsys-Detect can be executed from the script, and if it is selected, it runs in synchronous mode. Please consider adjusting the "detect.timeout" detect parameter because completion of Synopsys-Detect is estimated to take longer.
49+
The generated reports are found in a folder named "blackduck_consolidated_file_report"
50+
Synopsys-Detect is executed from the script unless skip-detect option is chosen. Synopsys-Detect runs in synchronous mode and please consider adjusting the "detect.timeout" detect parameter if completion of Synopsys-Detect is estimated to take longer.
5051
5152
Config file:
5253
API Token, hub URL and two more options need to be placed in the .restconfig.json file that must be placed in the same folder where this script resides.
@@ -57,7 +58,7 @@
5758
2) Install PyPI modules "blackduck", "ijson" and "json2html.
5859
5960
Examples:
60-
1) If Synopsys-Detect is wanted to execute prior to the HTML report generation that includes file copyright texts, then
61+
1) If Synopsys-Detect is wanted to execute prior to the HTML report generation and the report should include file-copyright texts, then
6162
python3 ./consolidated_file_report.py <YOUR_BD_PROJECT_NAME> <YOUR_BD_PROJECT_VERSION_NAME> \
6263
-f html -cl 2 -rr 100 \
6364
-dp detect.blackduck.signature.scanner.snippet.matching=SNIPPET_MATCHING \
@@ -172,7 +173,7 @@ def parse_parameter():
172173
metavar="",
173174
type=int,
174175
default=0,
175-
help="Specify the included copyright text level. Level 0 is no copyright texts included, 1 is only copyright texts from KB included, 2 is copyright texts from KB and discoveries included.")
176+
help="Specify the included copyright text level. Level 0 (default value) is no copyright texts included, 1 is only copyright texts from KB included, 2 is copyright texts from KB and discoveries included.")
176177
parser.add_argument("-sd",
177178
"--skip_detect",
178179
action='store_true',
@@ -379,7 +380,7 @@ def get_os_path_for_unmatched(parent_dir, matched_paths):
379380
'total_files': 0
380381
}
381382

382-
log_onerror = lambda err: logging.warn(f"An error reported during folder and file traverse. {str(err)}")
383+
log_onerror = lambda err: logging.error(f"An error reported during OS folder and file traverse. OS file report may be uncompleted.{str(err)}")
383384
for path, folder_names, file_names in os.walk(parent_dir, onerror=log_onerror):
384385
os_path_stats['total_folders'] = os_path_stats['total_folders'] + len(folder_names)
385386
os_path_stats['total_files'] = os_path_stats['total_files'] + len(file_names)
@@ -699,11 +700,9 @@ def generate_file_report(hub_client, project_id, version_id, codelocations, copy
699700
for license in disc_license['licenses']:
700701
file_data['licenses'].append(license)
701702
else:
702-
logging.debug(f"No discovery license found for file with this component: {file_data['projectName']} \
703-
and {file_data['projectVersion']}")
703+
logging.debug(f"No discovery license found for file with this component: {file_data['projectName']} and {file_data['projectVersion']}")
704704
if len(disc_licenses) > 1:
705-
logging.warning(f"More than one discovery license: {disc_licenses} found for \
706-
{file_data['projectName']}" and file_data['projectVersion'])
705+
logging.warning(f"More than one discovery license: {disc_licenses} found for {file_data['projectName']}" and file_data['projectVersion'])
707706

708707
if copyright_level != 0:
709708
origin_name = file_data['channelReleaseExternalNamespace'] + ":" + file_data['channelReleaseExternalId']
@@ -719,8 +718,7 @@ def generate_file_report(hub_client, project_id, version_id, codelocations, copy
719718
else:
720719
logging.debug(f"No discovery copyright found for file with this origin: {origin_name}")
721720
if len(disc_copyrights) > 1:
722-
logging.warning(f"More than one discovery copyright: {disc_copyrights} found \
723-
for the same origin {origin_name}")
721+
logging.warning(f"More than one discovery copyright: {disc_copyrights} found for the same origin {origin_name}")
724722

725723
report_file_bom['bomFileEntries']['bomFiles'].append(file_data)
726724
logging.info(f"Number of the reported files {i+1}")

0 commit comments

Comments
 (0)