Skip to content

Commit c6ee9ad

Browse files
authored
Merge pull request #5 from fosslight/develop
Change the output path of log, source
2 parents 3f02862 + 075bd9b commit c6ee9ad

File tree

4 files changed

+47
-31
lines changed

4 files changed

+47
-31
lines changed

README.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,17 @@ $ pip3 install fosslight_scanner
5151

5252
FOSSLight Scanner is run with the **fosslight** command.
5353

54-
### Parameters
55-
| Parameter | Argument | Description |
56-
| ------------- | ------------- | ------------- |
57-
| h | None | Print help message. |
58-
| s | String | Path to analyze source. |
59-
| d | String | Path to analyze dependencies. |
60-
| a | String | Additional arguments for running dependency analysis. See the [FOSSLight Dependency Guide][fd_guide] for instructions. |
61-
| w | String | Link to be analyzed can be downloaded by wget or git clone. |
62-
| o | String | Output Directory. |
54+
### Parameters
55+
```
56+
-h Print help message
57+
-r Keep raw data
58+
-s <source_path> Path to analyze source
59+
-w <link> Link to be analyzaed can be downloaded by wget or git clone
60+
-o <dir_name> Output Directory
61+
-d <dependency_path> Path to analyze dependencies
62+
-d <dependency_path> -a <additional_arg> (Using with -d option) Additional arguments for running dependency analysis
63+
```
64+
- Ref. Additional arguments for running dependency analysis. See the [FOSSLight Dependency Guide][fd_guide] for instructions.
6365

6466
[fd_guide]: https://fosslight.org/fosslight-guide-en/scanner/2_dependency.html
6567

@@ -78,12 +80,8 @@ $ fosslight -o test_result_wget -w "https://github.com/LGE-OSS/example.git"
7880
```
7981
$ tree
8082
.
81-
├── fosslight_raw_data_20210924_022422
83+
├── fosslight_log
8284
│   ├── fosslight_log_20210924_022422.txt
83-
│   ├── FOSSLight-Report_SRC_SRC.csv
84-
│   ├── FOSSLight-Report_SRC.xlsx
85-
│   ├── pip_dependency_output_SRC.csv
86-
│   └── pip_dependency_output.xlsx
8785
└── FOSSLight-Report_20210924_022422.xlsx
8886
```
8987

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ openpyxl
66
progress
77
pyyaml
88
fosslight_util>=1.3.1
9-
fosslight_dependency
9+
fosslight_dependency>=3.7.2

src/fosslight_scanner/_help.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
1414
Options:
1515
-h\t\t\t\t\t Print help message
16+
-r\t\t\t\t\t Keep raw data
1617
-s <source_path>\t\t\t Path to analyze source
1718
-w <link>\t\t\t\t Link to be analyzaed can be downloaded by wget or git clone
1819
-o <dir_name>\t\t\t\t Output Directory

src/fosslight_scanner/fosslight_scanner.py

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
import re
1111
import getopt
1212
import yaml
13+
from pathlib import Path
14+
from shutil import rmtree as rmdir
1315
from datetime import datetime
1416
from fosslight_source import run_scancode
15-
from fosslight_dependency import analyze_dependency
17+
from fosslight_dependency.run_dependency_scanner import main as dep_main
1618
from fosslight_util.download import cli_download_and_extract
1719
from ._get_input import get_input_mode
1820
from ._help import print_help_msg
@@ -80,7 +82,8 @@ def set_sub_parameter(default_params, params): # For dependency
8082
return default_params
8183

8284

83-
def run(src_path, dep_path, dep_arguments, output_path, need_init=True, result_log={}):
85+
def run(src_path, dep_path, dep_arguments, output_path, remove_raw_data=True,
86+
remove_src_data=True, need_init=True, result_log={}):
8487
try:
8588
success = True
8689
if need_init:
@@ -89,9 +92,9 @@ def run(src_path, dep_path, dep_arguments, output_path, need_init=True, result_l
8992
final_excel_dir = output_path
9093

9194
if success:
92-
output_files = {"SRC": _OUTPUT_FILE_PREFIX + "SRC",
93-
"BIN": _OUTPUT_FILE_PREFIX + "BIN",
94-
"DEP": _OUTPUT_FILE_PREFIX + "DEP",
95+
output_files = {"SRC": "FL_Source",
96+
"BIN": "FL_Binary.xlsx",
97+
"DEP": "FL_Dependency",
9598
"REUSE": "reuse.xml",
9699
"FINAL": _OUTPUT_FILE_PREFIX + _start_time + '.xlsx'}
97100

@@ -105,7 +108,7 @@ def run(src_path, dep_path, dep_arguments, output_path, need_init=True, result_l
105108
set_sub_parameter(["DEP",
106109
"-p", os.path.abspath(dep_path),
107110
"-o", _output_dir], dep_arguments),
108-
analyze_dependency.main, "Dependency Analysis")
111+
dep_main, "Dependency Analysis")
109112

110113
ouput_file = os.path.join(final_excel_dir, output_files["FINAL"])
111114
success, error_msg = merge_excels(_output_dir, ouput_file)
@@ -123,13 +126,23 @@ def run(src_path, dep_path, dep_arguments, output_path, need_init=True, result_l
123126
except Exception as ex:
124127
logger.warn("Error to print final log:"+str(ex))
125128

129+
try:
130+
if remove_raw_data:
131+
logger.debug("Remove temporary files: " + _output_dir)
132+
rmdir(_output_dir)
133+
if remove_src_data:
134+
logger.debug("Remove Source: " + src_path)
135+
rmdir(src_path)
136+
except Exception as ex:
137+
logger.debug("Error to remove temp files:"+str(ex))
126138

127-
def run_after_download_source(link, out_dir):
139+
140+
def run_after_download_source(link, out_dir, remove_raw_data):
128141
start_time = datetime.now().strftime('%Y%m%d_%H%M%S')
129142
try:
130143
success, final_excel_dir, result_log = init(out_dir)
131144
temp_src_dir = os.path.join(
132-
final_excel_dir, _SRC_DIR_FROM_LINK_PREFIX+start_time)
145+
_output_dir, _SRC_DIR_FROM_LINK_PREFIX+start_time)
133146

134147
logger.info("Link to download :"+link)
135148
success, msg = cli_download_and_extract(
@@ -138,7 +151,7 @@ def run_after_download_source(link, out_dir):
138151
if success:
139152
logger.info("Downloaded Dir:"+temp_src_dir)
140153
run(temp_src_dir, temp_src_dir,
141-
"", final_excel_dir, False, result_log)
154+
"", final_excel_dir, remove_raw_data, remove_raw_data, False, result_log)
142155
else:
143156
logger.error("Download failed:" + msg)
144157
except Exception as ex:
@@ -161,12 +174,13 @@ def init(output_path=""):
161174
else:
162175
output_root_dir = _executed_path
163176

164-
if not os.path.isdir(_output_dir):
165-
os.makedirs(_output_dir)
177+
Path(_output_dir).mkdir(parents=True, exist_ok=True)
166178
_output_dir = os.path.abspath(_output_dir)
167179

168-
logger, result_log = init_log(os.path.join(_output_dir, _log_file + _start_time + ".txt"),
180+
log_dir = os.path.join(output_root_dir, "fosslight_log")
181+
logger, result_log = init_log(os.path.join(log_dir, _log_file + _start_time + ".txt"),
169182
True, logging.INFO, logging.DEBUG, _PKG_NAME)
183+
170184
return os.path.isdir(_output_dir), output_root_dir, result_log
171185

172186

@@ -181,10 +195,11 @@ def main():
181195
url_to_analyze = ""
182196
_executed_path = os.getcwd()
183197
output_dir = _executed_path
198+
remove_raw_data = True
184199

185200
try:
186201
argv = sys.argv[1:]
187-
opts, args = getopt.getopt(argv, 'hs:d:a:o:w:')
202+
opts, args = getopt.getopt(argv, 'hrs:d:a:o:w:')
188203
except getopt.GetoptError:
189204
print_help_msg()
190205

@@ -204,6 +219,8 @@ def main():
204219
url_to_analyze = arg
205220
elif opt == "-o":
206221
output_dir = os.path.abspath(arg)
222+
elif opt == "-r":
223+
remove_raw_data = False
207224

208225
try:
209226
if not _cli_mode:
@@ -212,14 +229,14 @@ def main():
212229
timer.setDaemon(True)
213230
timer.start()
214231
if url_to_analyze != "":
215-
run_after_download_source(url_to_analyze, output_dir)
232+
run_after_download_source(url_to_analyze, output_dir, remove_raw_data)
216233

217234
if src_path != "" or dep_path != "":
218235
run(src_path, dep_path,
219-
dep_arguments, output_dir)
236+
dep_arguments, output_dir, remove_raw_data, False)
220237

221238
except Exception as ex:
222-
print(str(ex))
239+
logger.warning(str(ex))
223240

224241

225242
if __name__ == '__main__':

0 commit comments

Comments
 (0)