Skip to content

Commit 48fe83d

Browse files
fix use of mmap
1 parent 697d4b0 commit 48fe83d

File tree

5 files changed

+9
-24
lines changed

5 files changed

+9
-24
lines changed

src/fosslight_source/_parsing_scancode_file_item.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def parsing_file_item(scancode_file_list, has_error, path_to_scan, need_matched_
5252
prev_dir = ""
5353
prev_dir_value = False
5454
regex = re.compile(r'licenseref-(\S+)', re.IGNORECASE)
55+
find_word = re.compile(rb"SPDX-PackageDownloadLocation\s*:\s*(\S+)", re.IGNORECASE)
5556

5657
if scancode_file_list:
5758
for file in scancode_file_list:
@@ -73,29 +74,17 @@ def parsing_file_item(scancode_file_list, has_error, path_to_scan, need_matched_
7374

7475
result_item = ScanItem(file_path)
7576

76-
fullpath = os.path.join(path_to_scan, file_path)
77+
fullpath = os.path.join(path_to_scan, file_path)
7778

7879
urls = file.get("urls", [])
7980
url_list = []
80-
print("!!!!!!!! : ",fullpath)
8181

8282
if urls:
83-
search_term = "SPDX-PackageDownloadLocation:".encode()
8483
with open(fullpath, "r") as f:
85-
with mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as m:
86-
start = 0
87-
while True:
88-
# Find the next occurrence of the search term
89-
start = m.find(search_term, start)
90-
if start == -1:
91-
break
92-
# Extract the line that contains the search term
93-
line = m[start:].split(b"\n")[0].decode()
94-
spdx_download_location = re.sub(
95-
r'.*?SPDX-PackageDownloadLocation: ', '', line)
96-
url_list.append(spdx_download_location)
97-
# Move the start position to the end of the line
98-
start += len(line)
84+
with mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as mmap_obj:
85+
for word in find_word.findall(mmap_obj):
86+
url_list.append(word.decode('utf-8'))
87+
9988
if has_error and "scan_errors" in file:
10089
error_msg = file.get("scan_errors", [])
10190
if len(error_msg) > 0:

src/fosslight_source/cli.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ def main():
7070
parser.add_argument('-c', '--cores', type=int, required=False, default=-1)
7171
parser.add_argument('--no_correction', action='store_true', required=False)
7272
parser.add_argument('--correct_fpath', nargs=1, type=str, required=False)
73-
# parser.add_argument('-u', '--url', action='store_true', required=False)
7473

7574
args = parser.parse_args()
7675

@@ -96,8 +95,6 @@ def main():
9695
correct_filepath = path_to_scan
9796
if args.correct_fpath:
9897
correct_filepath = ''.join(args.correct_fpath)
99-
#if args.url:
100-
#print_url = True
10198

10299
time_out = args.timeout
103100
core = args.cores

src/fosslight_source/run_scancode.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ def run_scan(path_to_scan, output_file_name="",
9090
_result_log["Error_files"] = error_msg
9191
msg = "Failed to analyze :" + error_msg
9292
if "files" in results:
93-
rc, result_list, parsing_msg, license_list = parsing_file_item(results["files"], has_error, path_to_scan, need_license)
93+
rc, result_list, parsing_msg, license_list = parsing_file_item(results["files"],
94+
has_error, path_to_scan, need_license)
9495
if parsing_msg:
9596
_result_log["Parsing Log"] = parsing_msg
9697
if rc:

tests/test_files/run_scancode.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# -*- coding: utf-8 -*-
33
# Copyright (c) 2020 LG Electronics Inc.
44
# SPDX-License-Identifier: Apache-2.0
5+
56
# SPDX-PackageDownloadLocation: https://dummy_url_for_test.com
67
# The code is not licensed under GPL-2.0.
78

tox.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ commands =
4242
fosslight_source -p tests/test_files -m -j -o test_scan2/
4343
ls test_scan2/
4444

45-
fosslight_source -p tests/test_files -m -j -o test_scan3/ -s all -u
46-
ls test_scan3/
47-
4845
fosslight_convert -p tests/scancode_raw.json -o test_convert -f opossum
4946

5047
python tests/cli_test.py

0 commit comments

Comments
 (0)