Skip to content

Commit 4bb45b5

Browse files
committed
Add number of cores to analyze as param
1 parent dd7c72b commit 4bb45b5

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/fosslight_scanner/_help.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-w <link>\t\t\t\t Link to be analyzaed can be downloaded by wget or git clone
2020
-o <output>\t\t\t\t Output directory or file
2121
-f <format>\t\t\t\t Output file format (excel, csv, opossum)
22+
-c <cores>\t\t\t\t Number of processes to analyze source
2223
-d <dependency_argument> \t\t Additional arguments for running dependency analysis"""
2324

2425

src/fosslight_scanner/fosslight_scanner.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def run_dependency(path_to_analyze, output_file_with_path, params=""):
136136

137137

138138
def run(src_path, dep_path, dep_arguments, output_path, remove_raw_data=True,
139-
remove_src_data=True, need_init=True, result_log={}, output_file="", output_extension=""):
139+
remove_src_data=True, need_init=True, result_log={}, output_file="", output_extension="", num_cores=-1):
140140
try:
141141
success = True
142142
sheet_list = {}
@@ -160,7 +160,7 @@ def run(src_path, dep_path, dep_arguments, output_path, remove_raw_data=True,
160160
2, run_scancode.run_scan,
161161
os.path.abspath(src_path),
162162
os.path.join(_output_dir, output_files["SRC"]),
163-
False, -1, True)
163+
False, num_cores, True)
164164
if success:
165165
sheet_list["SRC_FL_Source"] = [scan_item.get_row_to_print() for scan_item in result]
166166

@@ -195,7 +195,7 @@ def run(src_path, dep_path, dep_arguments, output_path, remove_raw_data=True,
195195
logger.debug("Error to remove temp files:"+str(ex))
196196

197197

198-
def run_after_download_source(link, out_dir, remove_raw_data, output_file="", output_extension=""):
198+
def run_after_download_source(link, out_dir, remove_raw_data, output_file="", output_extension="", num_cores=-1):
199199
start_time = datetime.now().strftime('%Y%m%d_%H%M%S')
200200
try:
201201
success, final_excel_dir, result_log = init(out_dir)
@@ -210,7 +210,7 @@ def run_after_download_source(link, out_dir, remove_raw_data, output_file="", ou
210210
logger.info("Downloaded Dir:"+temp_src_dir)
211211
run(temp_src_dir, temp_src_dir,
212212
"", final_excel_dir, remove_raw_data, remove_raw_data, False,
213-
result_log, output_file, output_extension)
213+
result_log, output_file, output_extension, num_cores)
214214
else:
215215
logger.error("Download failed:" + msg)
216216
except Exception as ex:
@@ -259,10 +259,11 @@ def main():
259259
output_file_or_dir = ""
260260
show_progressbar = True
261261
file_format = ""
262+
num_cores = -1
262263

263264
try:
264265
argv = sys.argv[1:]
265-
opts, args = getopt.getopt(argv, 'htrs:d:a:o:w:f:p:')
266+
opts, args = getopt.getopt(argv, 'htrs:d:a:o:w:f:p:c:')
266267
except getopt.GetoptError:
267268
print_help_msg()
268269

@@ -286,6 +287,8 @@ def main():
286287
show_progressbar = False
287288
elif opt == "-f":
288289
file_format = arg
290+
elif opt == "-c":
291+
num_cores = arg
289292

290293
try:
291294
success, msg, output_path, output_file, output_extension = check_output_format(output_file_or_dir, file_format)
@@ -301,10 +304,10 @@ def main():
301304
timer.start()
302305

303306
if url_to_analyze != "":
304-
run_after_download_source(url_to_analyze, output_path, remove_raw_data, output_file, output_extension)
307+
run_after_download_source(url_to_analyze, output_path, remove_raw_data, output_file, output_extension, num_cores)
305308
elif src_path != "" or dep_path != "":
306309
run(src_path, dep_path,
307-
dep_arguments, output_path, remove_raw_data, False, True, {}, output_file, output_extension)
310+
dep_arguments, output_path, remove_raw_data, False, True, {}, output_file, output_extension, num_cores)
308311
except Exception as ex:
309312
logger.warning(str(ex))
310313

0 commit comments

Comments
 (0)