Skip to content

Commit 7fee595

Browse files
authored
Merge pull request #64 from fosslight/develop
Change the scanoss-related packages
2 parents df49b97 + 68e2458 commit 7fee595

File tree

6 files changed

+33
-32
lines changed

6 files changed

+33
-32
lines changed

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"Programming Language :: Python :: 3.8",
3232
"Programming Language :: Python :: 3.9", ],
3333
install_requires=required,
34-
extras_require={":python_version>'3.6'": ["scanoss>=0.7.0"]},
34+
extras_require={":python_version>'3.6'": ["scanoss>=0.7.0"],
35+
":python_version<'3.7'": ["dataclasses", "scanoss"]},
3536
entry_points={
3637
"console_scripts": [
3738
"fosslight_convert = fosslight_source.convert_scancode:main",

src/fosslight_source/_parsing_scancode_file_item.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def get_error_from_header(header_item):
3535
str_error = '{}...({})'.format(errors[0], error_cnt)
3636
break
3737
except Exception as ex:
38-
logger.debug("error_parsing_header:"+str(ex))
38+
logger.debug(f"Error_parsing_header: {ex}")
3939
return has_error, str_error
4040

4141

@@ -44,7 +44,7 @@ def parsing_file_item(scancode_file_list, has_error, need_matched_license=False)
4444
rc = True
4545
scancode_file_item = []
4646
license_list = {} # Key :[license]+[matched_text], value: MatchedLicense()
47-
msg = "TOTAL FILE COUNT: " + str(len(scancode_file_list)) + "\n"
47+
msg = f"TOTAL FILE COUNT: {len(scancode_file_list)} \n"
4848

4949
prev_dir = ""
5050
prev_dir_value = False
@@ -73,7 +73,7 @@ def parsing_file_item(scancode_file_list, has_error, need_matched_license=False)
7373
if has_error and "scan_errors" in file:
7474
error_msg = file["scan_errors"]
7575
if len(error_msg) > 0:
76-
logger.debug("test_msg" + file_path + ":" + str(error_msg))
76+
logger.debug(f"Test_msg {file_path}:{error_msg}")
7777
result_item.set_comment(",".join(error_msg))
7878
scancode_file_item.append(result_item)
7979
continue
@@ -153,7 +153,7 @@ def parsing_file_item(scancode_file_list, has_error, need_matched_license=False)
153153
scancode_file_item.append(result_item)
154154

155155
except Exception as ex:
156-
msg += "* Error Parsing item:"+str(ex)
156+
msg += f"* Error Parsing item: {ex}"
157157
rc = False
158158
logger.debug(msg)
159159

src/fosslight_source/_parsing_scanoss_file.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ def parsing_scanResult(scanoss_report):
4949
result_item.set_fileURL(findings[0]['file_url'])
5050
if 'matched' in findings[0]:
5151
if 'lines' in findings[0]:
52-
result_item.set_matched_lines(findings[0]['matched'] + " (" + findings[0]['lines'] + ")")
52+
result_item.set_matched_lines(f"{findings[0]['matched']} ({findings[0]['lines']})")
5353
else:
54-
result_item.set_matched_lines(findings[0]['matched'])
54+
result_item.set_matched_lines(f"{findings[0]['matched']}")
5555
elif 'lines' in findings[0]:
56-
result_item.set_matched_lines("(" + findings[0]['lines'] + ")")
56+
result_item.set_matched_lines(f"({findings[0]['lines']})")
5757

5858
scanoss_file_item.append(result_item)
5959

src/fosslight_source/run_scancode.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ def run_scan(path_to_scan, output_file_name="",
5050
if not called_by_cli:
5151
if output_file == "":
5252
if output_extension == _json_ext:
53-
output_file = "Opossum_input_" + start_time
53+
output_file = f"Opossum_input_{start_time}"
5454
else:
55-
output_file = "FOSSLight-Report_" + start_time
55+
output_file = f"FOSSLight-Report_{start_time}"
5656

5757
if _write_json_file:
5858
output_json_file = os.path.join(output_path, "scancode_raw_result.json")
5959
else:
6060
output_json_file = ""
6161

6262
if not called_by_cli:
63-
logger, _result_log = init_log(os.path.join(output_path, "fosslight_src_log_"+start_time+".txt"),
63+
logger, _result_log = init_log(os.path.join(output_path, f"fosslight_src_log_{start_time}.txt"),
6464
True, logging.INFO, logging.DEBUG, _PKG_NAME, path_to_scan)
6565

6666
if path_to_scan == "":
@@ -116,23 +116,23 @@ def run_scan(path_to_scan, output_file_name="",
116116
except Exception as ex:
117117
success = False
118118
msg = str(ex)
119-
logger.error("Analyze " + path_to_scan + ":" + msg)
119+
logger.error(f"Analyze {path_to_scan}: {msg}")
120120
else:
121121
success = False
122122
msg = "Check the path to scan. :" + path_to_scan
123123

124124
if not return_results:
125125
result_list = []
126126

127-
scan_result_msg = str(success) if msg == "" else str(success) + ", " + msg
127+
scan_result_msg = str(success) if msg == "" else f"{success}, {msg}"
128128
_result_log["Scan Result"] = scan_result_msg
129129
_result_log["Output Directory"] = output_path
130130
try:
131131
_str_final_result_log = yaml.safe_dump(_result_log, allow_unicode=True, sort_keys=True)
132132
logger.info(_str_final_result_log)
133133
except Exception as ex:
134-
logger.warning("Failed to print result log. " + str(ex))
134+
logger.warning(f"Failed to print result log. {ex}")
135135

136136
if not success:
137-
logger.error("Failed to run:" + str(scan_result_msg))
137+
logger.error(f"Failed to run: {scan_result_msg}")
138138
return success, _result_log["Scan Result"], result_list, license_list

src/fosslight_source/run_scanoss.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def run_scanoss_py(path_to_scan, output_file_name="", format="", called_by_cli=F
5959

6060
output_json_file = os.path.join(output_path, output_file)
6161

62-
scan_command += output_json_file + " " + path_to_scan
62+
scan_command += f"{output_json_file} {path_to_scan}"
6363

6464
if num_threads > 0:
6565
scan_command += " -T " + str(num_threads)
@@ -69,24 +69,24 @@ def run_scanoss_py(path_to_scan, output_file_name="", format="", called_by_cli=F
6969
try:
7070
os.system(scan_command)
7171
st_json = open(output_json_file, "r")
72-
logger.info("SCANOSS Start parsing " + path_to_scan)
72+
logger.info(f"SCANOSS Start parsing {path_to_scan}")
7373
with open(output_json_file, "r") as st_json:
7474
st_python = json.load(st_json)
7575
scanoss_file_list = parsing_scanResult(st_python)
7676
except Exception as error:
77-
logger.warning("Parsing " + path_to_scan + ":" + str(error))
78-
logger.info("|---Number of files detected with SCANOSS: " + str(len(scanoss_file_list)))
77+
logger.warning(f"Parsing {path_to_scan}: {error}")
78+
logger.info(f"|---Number of files detected with SCANOSS: {(len(scanoss_file_list))}")
7979

8080
if not write_json_file:
8181
try:
82-
os.system("rm " + output_json_file)
82+
os.system(f"rm {output_json_file}")
8383
os.system("rm scanner_output.wfp")
8484
except Exception as error:
85-
logger.debug("Deleting scanoss result failed.:" + str(error))
85+
logger.debug(f"Deleting scanoss result failed.: {error}")
8686
else:
8787
try:
88-
os.system("mv scanner_output.wfp " + output_path + "/scanoss_fingerprint.wfp")
88+
os.system(f"mv scanner_output.wfp {output_path}/scanoss_fingerprint.wfp")
8989
except Exception as error:
90-
logger.debug("Moving scanoss fingerprint file failed.:" + str(error))
90+
logger.debug(f"Moving scanoss fingerprint file failed.: {error}")
9191

9292
return scanoss_file_list

tests/test_files/run_scancode.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ def run_scan(path_to_scan, output_file_name="",
7070
start_time = datetime.now().strftime('%Y%m%d_%H%M%S')
7171

7272
if output_file_name == "":
73-
output_file = "FOSSLight-Report_" + start_time
74-
output_json_file = "scancode_" + start_time
73+
output_file = f"FOSSLight-Report_{start_time}"
74+
output_json_file = f"scancode_{start_time}"
7575
output_dir = os.getcwd()
7676
else:
7777
output_file = output_file_name
7878
output_json_file = output_file_name
7979
output_dir = os.path.dirname(os.path.abspath(output_file_name))
8080

81-
logger, _result_log = init_log(os.path.join(output_dir, "fosslight_src_log_"+start_time+".txt"),
81+
logger, _result_log = init_log(os.path.join(output_dir, f"fosslight_src_log_{start_time}.txt"),
8282
True, logging.INFO, logging.DEBUG, _PKG_NAME, path_to_scan)
8383

8484
if path_to_scan == "":
@@ -91,7 +91,7 @@ def run_scan(path_to_scan, output_file_name="",
9191

9292
if os.path.isdir(path_to_scan):
9393
try:
94-
output_json_file = output_json_file+".json" if _write_json_file\
94+
output_json_file = f"{output_json_file}.json" if _write_json_file\
9595
else ""
9696

9797
rc, results = cli.run_scan(path_to_scan, max_depth=100,
@@ -127,16 +127,16 @@ def run_scan(path_to_scan, output_file_name="",
127127

128128
success_to_write, writing_msg = write_excel_and_csv(
129129
output_file, sheet_list)
130-
logger.info("Writing excel :" + str(success_to_write) + " " + writing_msg)
130+
logger.info(f"Writing excel : {success_to_write} {writing_msg}")
131131
if success_to_write:
132-
_result_log["FOSSLight Report"] = output_file + ".xlsx"
132+
_result_log["FOSSLight Report"] = f"{output_file}.xlsx"
133133
except Exception as ex:
134134
success = False
135135
msg = str(ex)
136-
logger.error("Analyze " + path_to_scan + ":" + msg)
136+
logger.error(f"Analyze {path_to_scan}: {msg}")
137137
else:
138138
success = False
139-
msg = "Check the path to scan. :" + path_to_scan
139+
msg = f"Check the path to scan. : {path_to_scan}"
140140

141141
if not return_results:
142142
result_list = []
@@ -148,7 +148,7 @@ def run_scan(path_to_scan, output_file_name="",
148148
_str_final_result_log = yaml.safe_dump(_result_log, allow_unicode=True, sort_keys=True)
149149
logger.info(_str_final_result_log)
150150
except Exception as ex:
151-
logger.warning("Failed to print result log. " + str(ex))
151+
logger.warning(f"Failed to print result log. {ex}")
152152
return success, _result_log["Scan Result"], result_list
153153

154154

0 commit comments

Comments
 (0)