@@ -36,21 +36,23 @@ def write_result_json_yaml(output_file, compared_result, file_ext):
3636
3737def 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
177197def 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
0 commit comments