Skip to content

Commit 78f0799

Browse files
authored
Merge pull request #39 from fosslight/develop
Print message when comparison rows are over 100.
2 parents 666e455 + 5ea3872 commit 78f0799

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ openpyxl
66
progress
77
pyyaml
88
beautifulsoup4
9-
fosslight_util>=1.3.13
9+
fosslight_util>=1.4.1
1010
fosslight_dependency>=3.7.4
1111
fosslight_binary>=4.0.7
1212
fosslight_reuse>=2.2.1

src/fosslight_scanner/_run_compare.py

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,23 @@ def write_result_json_yaml(output_file, compared_result, file_ext):
3636

3737
def parse_result_for_table(oi, status):
3838
compared_row = []
39-
if status == ADD:
40-
oss_after = f"{oi['name']} ({oi['version']})"
41-
license_after = f"{', '.join(oi['license'])}"
42-
compared_row = [status, '', '', oss_after, license_after]
43-
elif status == DELETE:
44-
oss_before = f"{oi['name']} ({oi['version']})"
45-
license_before = f"{', '.join(oi['license'])}"
46-
compared_row = [status, oss_before, license_before, '', '']
39+
if status == ADD or status == DELETE:
40+
oi_ver = '' if oi['version'] == '' else f"({oi['version']})"
41+
oss_info = f"{oi['name']}{oi_ver}"
42+
license_info = f"{', '.join(oi['license'])}"
43+
if status == ADD:
44+
compared_row = [status, '', '', oss_info, license_info]
45+
elif status == DELETE:
46+
compared_row = [status, oss_info, license_info, '', '']
4747
elif status == CHANGE:
4848
oss_before, oss_after, license_before, license_after = [], [], [], []
4949
for prev_i in oi['prev']:
50-
oss_before.append(f"{oi['name']} ({prev_i['version']})")
50+
prev_i_ver = '' if prev_i['version'] == '' else f"({prev_i['version']})"
51+
oss_before.append(f"{oi['name']}{prev_i_ver}")
5152
license_before.append(f"{', '.join(prev_i['license'])}")
5253
for now_i in oi['now']:
53-
oss_after.append(f"{oi['name']} ({now_i['version']})")
54+
now_i_ver = '' if now_i['version'] == '' else f"({now_i['version']})"
55+
oss_after.append(f"{oi['name']}{now_i_ver}")
5456
license_after.append(f"{', '.join(now_i['license'])}")
5557
compared_row = [status, ' / '.join(oss_before), ' / '.join(license_before),
5658
' / '.join(oss_after), ' / '.join(license_after)]
@@ -93,6 +95,7 @@ def write_result_html(output_file, compared_result, before_yaml, after_yaml):
9395

9496
status = [ADD, DELETE, CHANGE]
9597
row = 2
98+
MIN_ROW_NUM = 100
9699
for st in status:
97100
for oi in compared_result[st]:
98101
compared_row = parse_result_for_table(oi, st)
@@ -104,6 +107,16 @@ def write_result_html(output_file, compared_result, before_yaml, after_yaml):
104107
tr.insert(i, td)
105108
table_html.insert(row, tr)
106109
row += 1
110+
if row >= MIN_ROW_NUM + 2:
111+
p = f.new_tag('p')
112+
p.string = "(!) There are so many different oss.\
113+
See the attached excel file for the full comparison result."
114+
p.attrs = {"style": "font-weight:bold; color:red; font-size:15px"}
115+
table_html.insert_before(p)
116+
break
117+
else:
118+
continue
119+
break
107120

108121
if row == 2:
109122
tr = f.new_tag('tr')
@@ -163,26 +176,35 @@ def write_compared_result(output_file, compared_result, file_ext, before_yaml=''
163176
if file_ext == "" or file_ext == ".xlsx":
164177
success = write_result_xlsx(output_file, compared_result)
165178
elif file_ext == ".html":
179+
output_xlsx_file = os.path.splitext(output_file)[0] + ".xlsx"
180+
success_xlsx = write_result_xlsx(output_xlsx_file, compared_result)
166181
success = write_result_html(output_file, compared_result, before_yaml, after_yaml)
182+
if not success_xlsx:
183+
logger.error("Fail to write comparison excel file.")
184+
else:
185+
logger.info(f"In html format, {output_xlsx_file} is generated by default.")
186+
output_file = f"{output_xlsx_file}, {output_file}"
167187
elif file_ext == ".json":
168188
success = write_result_json_yaml(output_file, compared_result, file_ext)
169189
elif file_ext == ".yaml":
170190
success = write_result_json_yaml(output_file, compared_result, file_ext)
171191
else:
172192
logger.info("Not supported file extension")
173193

174-
return success
194+
return success, output_file
175195

176196

177197
def run_compare(before_yaml, after_yaml, output_file, file_ext):
178198
ret = False
179199
logger.info("Start compare mode")
200+
logger.info(f"before file: {before_yaml}")
201+
logger.info(f"after file: {after_yaml}")
180202

181203
compared_result = compare_yaml(before_yaml, after_yaml)
182204
if compared_result != '':
183-
ret = write_compared_result(output_file, compared_result, file_ext, before_yaml, after_yaml)
205+
ret, result_file = write_compared_result(output_file, compared_result, file_ext, before_yaml, after_yaml)
184206
if ret:
185-
logger.info(f"Success to write compared result: {output_file}")
207+
logger.info(f"Success to write compared result: {result_file}")
186208
else:
187209
logger.error("Fail to write compared result file.")
188210

src/fosslight_scanner/fosslight_scanner.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ def run_dependency(path_to_analyze, output_file_with_path, params=""):
7676
except Exception as ex:
7777
logger.warning(f"Set dependency Param: {ex}")
7878

79+
timer = TimerThread()
80+
timer.setDaemon(True)
81+
timer.start()
82+
7983
try:
8084
success, result = call_analysis_api(path_to_analyze, "Dependency Analysis",
8185
1, run_dependency_scanner,

0 commit comments

Comments
 (0)