Skip to content

Commit 2a5cd7e

Browse files
authored
Merge pull request #162 from SeongjunJo/amend_exclude
Amend exclude option
2 parents 1301aa5 + 91337ea commit 2a5cd7e

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/fosslight_source/run_scancode.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,23 @@ def run_scan(path_to_scan, output_file_name="",
7474
pretty_params["path_to_exclude"] = path_to_exclude
7575
pretty_params["output_file"] = output_file_name
7676
total_files_to_excluded = []
77+
7778
if path_to_exclude:
79+
target_path = os.path.basename(path_to_scan) if os.path.isabs(path_to_scan) else path_to_scan
80+
7881
for path in path_to_exclude:
79-
path = os.path.join(path_to_scan, path)
80-
if os.path.isdir(path):
81-
for root, _, files in os.walk(path):
82+
exclude_path = path
83+
isabs_exclude = os.path.isabs(path)
84+
if isabs_exclude:
85+
exclude_path = os.path.relpath(path, os.path.abspath(path_to_scan))
86+
87+
exclude_path = os.path.join(target_path, exclude_path)
88+
if os.path.isdir(exclude_path):
89+
for root, _, files in os.walk(exclude_path):
8290
total_files_to_excluded.extend([os.path.normpath(os.path.join(root, file)).replace("\\", "/")
8391
for file in files])
84-
elif os.path.isfile(path):
85-
total_files_to_excluded.append(os.path.normpath(path).replace("\\", "/"))
92+
elif os.path.isfile(exclude_path):
93+
total_files_to_excluded.append(os.path.normpath(exclude_path).replace("\\", "/"))
8694

8795
rc, results = cli.run_scan(path_to_scan, max_depth=100,
8896
strip_root=True, license=True,

src/fosslight_source/run_scanoss.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ def run_scanoss_py(path_to_scan, output_file_name="", format="", called_by_cli=F
7777
total_files_to_excluded = []
7878
if path_to_exclude:
7979
for path in path_to_exclude:
80-
path = os.path.join(path_to_scan, path)
80+
path = os.path.join(path_to_scan, os.path.relpath(path, os.path.abspath(path_to_scan))) \
81+
if not os.path.isabs(path_to_scan) and os.path.isabs(path) else os.path.join(path_to_scan, path)
8182
if os.path.isdir(path):
8283
for root, _, files in os.walk(path):
8384
root = root[len(path_to_scan) + 1:]

0 commit comments

Comments
 (0)