Skip to content

Commit f283a88

Browse files
authored
Merge pull request #48 from fosslight/develop
Change the report file name
2 parents 805c423 + 36c2f0d commit f283a88

File tree

2 files changed

+33
-35
lines changed

2 files changed

+33
-35
lines changed

src/fosslight_scanner/_run_compare.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def write_result_xlsx(output_file, compared_result):
155155
output_dir = os.path.dirname(output_file)
156156
Path(output_dir).mkdir(parents=True, exist_ok=True)
157157

158-
workbook = xlsxwriter.Workbook(os.path.basename(output_file))
158+
workbook = xlsxwriter.Workbook(output_file)
159159
worksheet = workbook.add_worksheet('BOM_compare')
160160
bold = workbook.add_format({'bold': True})
161161
worksheet.write_row(0, 0, HEADER, bold)
@@ -201,17 +201,18 @@ def write_compared_result(output_file, compared_result, file_ext, before_f='', a
201201

202202
def get_comparison_result_filename(output_path, output_file, output_extension, _start_time):
203203
result_file = ""
204+
compare_prefix = f"fosslight_compare_{_start_time}"
204205
if output_file != "":
205206
result_file = f"{output_file}{output_extension}"
206207
else:
207208
if output_extension == XLSX_EXT or output_extension == "":
208-
result_file = f"FOSSLight_Compare_{_start_time}{XLSX_EXT}"
209+
result_file = f"{compare_prefix}{XLSX_EXT}"
209210
elif output_extension == HTML_EXT:
210-
result_file = f"FOSSLight_Compare_{_start_time}{HTML_EXT}"
211+
result_file = f"{compare_prefix}{HTML_EXT}"
211212
elif output_extension == YAML_EXT:
212-
result_file = f"FOSSLight_Compare_{_start_time}{YAML_EXT}"
213+
result_file = f"{compare_prefix}{YAML_EXT}"
213214
elif output_extension == JSON_EXT:
214-
result_file = f"FOSSLight_Compare_{_start_time}{JSON_EXT}"
215+
result_file = f"{compare_prefix}{JSON_EXT}"
215216
else:
216217
logger.error("Not supported file extension")
217218

@@ -230,8 +231,10 @@ def count_compared_result(compared_result):
230231
logger.info(f"Comparison result: {count_str}")
231232

232233

233-
def run_compare(before_f, after_f, output_path, output_file, file_ext, _start_time):
234+
def run_compare(before_f, after_f, output_path, output_file, file_ext, _start_time, _output_dir):
234235
ret = False
236+
before_yaml = ''
237+
after_yaml = ''
235238
logger.info("Start compare mode")
236239
logger.info(f"before file: {before_f}")
237240
logger.info(f"after file: {after_f}")
@@ -245,8 +248,10 @@ def run_compare(before_f, after_f, output_path, output_file, file_ext, _start_ti
245248
logger.error(f"Compare mode only supports 'yaml' or 'xlsx' extension. (input extension:{before_ext})")
246249
return False
247250
else:
248-
before_yaml = before_f if before_ext == YAML_EXT else f'{before_f.rstrip(XLSX_EXT)}{YAML_EXT}'
249-
after_yaml = after_f if after_ext == YAML_EXT else f'{after_f.rstrip(XLSX_EXT)}{YAML_EXT}'
251+
tmp_b_yaml = f'{os.path.basename(before_f).rstrip(XLSX_EXT)}{YAML_EXT}'
252+
before_yaml = before_f if before_ext == YAML_EXT else os.path.join(_output_dir, tmp_b_yaml)
253+
tmp_a_yaml = f'{os.path.basename(after_f).rstrip(XLSX_EXT)}{YAML_EXT}'
254+
after_yaml = after_f if after_ext == YAML_EXT else os.path.join(_output_dir, tmp_a_yaml)
250255

251256
result_file = get_comparison_result_filename(output_path, output_file, file_ext, _start_time)
252257

src/fosslight_scanner/fosslight_scanner.py

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,11 @@
3434
except ModuleNotFoundError:
3535
fosslight_source_installed = False
3636

37-
OUTPUT_EXCEL_PREFIX = "FOSSLight-Report_"
38-
OUTPUT_YAML_PREFIX = "fosslight-sbom-info_"
37+
OUTPUT_REPORT_PREFIX = "fosslight_report_"
3938
PKG_NAME = "fosslight_scanner"
4039
logger = logging.getLogger(constant.LOGGER_NAME)
4140
warnings.simplefilter(action='ignore', category=FutureWarning)
42-
_output_dir = "fosslight_raw_data_"
41+
_output_dir = "fosslight_raw_data"
4342
_log_file = "fosslight_log_"
4443
_start_time = ""
4544
_executed_path = ""
@@ -111,11 +110,7 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
111110
success, final_excel_dir, result_log = init(output_path)
112111

113112
if output_file == "":
114-
if output_extension == ".yaml":
115-
output_prefix = OUTPUT_YAML_PREFIX
116-
else:
117-
output_prefix = OUTPUT_EXCEL_PREFIX
118-
output_file = output_prefix + _start_time
113+
output_file = OUTPUT_REPORT_PREFIX + _start_time
119114

120115
if output_extension == "":
121116
output_extension = ".xlsx"
@@ -126,11 +121,11 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
126121
abs_path = os.path.abspath(src_path)
127122

128123
if success:
129-
output_files = {"SRC": f"FL_Source{output_extension}",
130-
"BIN": f"FL_Binary{output_extension}",
131-
"BIN_TXT": "FL_Binary.txt",
132-
"DEP": f"FL_Dependency{output_extension}",
133-
"PRECHECKER": "FL_Prechecker.yaml"}
124+
output_files = {"SRC": f"fosslight_src_{_start_time}{output_extension}",
125+
"BIN": f"fosslight_bin_{_start_time}{output_extension}",
126+
"BIN_TXT": f"fosslight_binary_{_start_time}.txt",
127+
"DEP": f"fosslight_dep_{_start_time}{output_extension}",
128+
"PRECHECKER": f"fosslight_lint_{_start_time}.yaml"}
134129
if run_prechecker:
135130
output_prechecker = os.path.join(_output_dir, output_files["PRECHECKER"])
136131
success, result = call_analysis_api(src_path, "Prechecker Lint",
@@ -210,9 +205,6 @@ def run_scanner(src_path, dep_arguments, output_path, keep_raw_data=False,
210205
logger.warning(f"Error to write final report: {ex}")
211206

212207
try:
213-
if not keep_raw_data:
214-
logger.debug(f"Remove temporary files: {_output_dir}")
215-
rmdir(_output_dir)
216208
if remove_src_data:
217209
logger.debug(f"Remove temporary source: {src_path}")
218210
rmdir(src_path)
@@ -250,9 +242,8 @@ def init(output_path="", make_outdir=True):
250242

251243
result_log = {}
252244
output_root_dir = ""
253-
_start_time = datetime.now().strftime('%Y%m%d_%H%M%S')
245+
_start_time = datetime.now().strftime('%y%m%d_%H%M')
254246

255-
_output_dir = _output_dir + _start_time
256247
if output_path != "":
257248
_output_dir = os.path.join(output_path, _output_dir)
258249
output_root_dir = output_path
@@ -297,6 +288,9 @@ def run_main(mode, path_arg, dep_arguments, output_file_or_dir, file_format, url
297288

298289
success, msg, output_path, output_file, output_extension = check_output_format(output_file_or_dir, file_format,
299290
CUSTOMIZED_FORMAT)
291+
if output_path == "":
292+
output_path = _executed_path
293+
300294
if not success:
301295
logger.error(msg)
302296
sys.exit(1)
@@ -311,22 +305,16 @@ def run_main(mode, path_arg, dep_arguments, output_file_or_dir, file_format, url
311305
if not os.path.exists(os.path.join(_executed_path, after_comp_f)):
312306
logger.error("Cannot find after FOSSLight report file (2nd param with -y option).")
313307
return False
314-
ret, final_excel_dir, result_log = init(output_path, False)
315-
if output_path == "":
316-
output_path = _executed_path
317-
else:
318-
output_path = os.path.abspath(output_path)
308+
ret, final_excel_dir, result_log = init(output_path)
319309

320310
run_compare(os.path.join(_executed_path, before_comp_f), os.path.join(_executed_path, after_comp_f),
321-
output_path, output_file, output_extension, _start_time)
311+
final_excel_dir, output_file, output_extension, _start_time, _output_dir)
322312
else:
323313
run_src = False
324314
run_bin = False
325315
run_dep = False
326316
run_prechecker = False
327317
remove_downloaded_source = False
328-
if output_path == "":
329-
output_path = _executed_path
330318

331319
if mode == "prechecker" or mode == "reuse":
332320
run_prechecker = True
@@ -361,7 +349,12 @@ def run_main(mode, path_arg, dep_arguments, output_file_or_dir, file_format, url
361349
remove_downloaded_source, {}, output_file,
362350
output_extension, num_cores, db_url,
363351
default_oss_name, url_to_analyze)
364-
352+
try:
353+
if not keep_raw_data:
354+
logger.debug(f"Remove temporary files: {_output_dir}")
355+
rmdir(_output_dir)
356+
except Exception as ex:
357+
logger.debug(f"Error to remove temp files:{ex}")
365358
except Exception as ex:
366359
logger.warning(str(ex))
367360
return False

0 commit comments

Comments
 (0)