Skip to content

Commit d587c51

Browse files
authored
Remove the -m option and request the input from the user if -c or -l is null in add mode.
2 parents 2b5228d + d47110b commit d587c51

File tree

8 files changed

+107
-57
lines changed

8 files changed

+107
-57
lines changed

src/fosslight_reuse/_add.py

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from reuse._main import parser as reuse_arg_parser
1616

1717
_PKG_NAME = "fosslight_reuse"
18-
_auto_add_mode = False
1918
_result_log = {}
2019
logger = logging.getLogger(constant.LOGGER_NAME)
2120

@@ -68,12 +67,39 @@ def check_input_format(input_copyright):
6867
check_ok = True
6968

7069
if regex.match(input_copyright) is None:
71-
logger.warning(" You have to input with following format - 'Copyright <year> <name>'")
70+
logger.warning(" You have to input with following format - Copyright <year> <name>")
7271
check_ok = False
7372

7473
return check_ok
7574

7675

76+
def input_license_while_running():
77+
input_license = ""
78+
79+
logger.info("# Select a license to write in the license missing files ")
80+
select = input(" 1.MIT, 2.Apache-2.0, 3.LGE-Proprietary, 4.Manaully Input, 5.Not select now : ")
81+
if select == '1' or select == 'MIT':
82+
input_license = 'MIT'
83+
elif select == '2' or select == 'Apache-2.0':
84+
input_license = 'Apache-2.0'
85+
elif select == '3' or select == 'LGE Proprietary License':
86+
input_license = 'LicenseRef-LGE-Proprietary'
87+
elif select == '4' or select == 'Manually Input':
88+
input_license = input(" ## Input your License : ")
89+
elif select == '5' or select == 'Quit' or select == 'quit':
90+
logger.info(" Not selected any license to write ")
91+
return input_license
92+
93+
94+
def input_copyright_while_running():
95+
input_copyright = ""
96+
input_copyright = input("# Input Copyright to write in the copyright missing files (ex, Copyright <year> <name>) : ")
97+
if input_copyright == 'Quit' or input_copyright == 'quit' or input_copyright == 'Q':
98+
return
99+
100+
return input_copyright
101+
102+
77103
def set_missing_license_copyright(missing_license_filtered, missing_copyright_filtered, project, path_to_find, license, copyright):
78104
input_license = None
79105
input_copyright = None
@@ -85,33 +111,17 @@ def set_missing_license_copyright(missing_license_filtered, missing_copyright_fi
85111

86112
# Print missing license
87113
if missing_license_filtered is not None and len(missing_license_filtered) > 0:
88-
input_str = ""
89114
missing_license_list = []
90115

91116
logger.info("# Missing license File(s) ")
92117
for lic_file in sorted(missing_license_filtered):
93118
logger.info(f" * {lic_file}")
94119
missing_license_list.append(path_to_find + '/' + lic_file)
95120

96-
if _auto_add_mode:
97-
# Automatic add mode
98-
input_license = license
121+
if license == "" and copyright == "":
122+
input_license = input_license_while_running()
99123
else:
100-
# Manual add Mode
101-
logger.info("# Select a license to write in the license missing files ")
102-
select = input(" 1.MIT, 2.Apache-2.0, 3.LGE-Proprietary, 4.Manaully Input, 5.Not select now : ")
103-
if select == '1' or select == 'MIT':
104-
input_license = 'MIT'
105-
elif select == '2' or select == 'Apache-2.0':
106-
input_license = 'Apache-2.0'
107-
elif select == '3' or select == 'LGE Proprietary License':
108-
input_license = 'LicenseRef-LGE-Proprietary'
109-
elif select == '4' or select == 'Manually Input':
110-
input_str = input(" ## Input your License : ")
111-
input_license = input_str
112-
elif select == '5' or select == 'Quit' or select == 'quit':
113-
logger.info(" Not selected any license to write ")
114-
return
124+
input_license = license
115125

116126
if input_license != "":
117127
logger.warning(f" * Your input license : {input_license}")
@@ -130,18 +140,14 @@ def set_missing_license_copyright(missing_license_filtered, missing_copyright_fi
130140
logger.info(f" * {cop_file}")
131141
missing_copyright_list.append(os.getcwd() + '/' + path_to_find + '/' + cop_file)
132142

133-
if _auto_add_mode:
134-
# Automatic add mode
135-
input_copyright = copyright
136-
else:
137-
# Manual add Mode
138-
input_copyright = input("# Input Copyright to write in the copyright missing files (ex, 'Copyright <year> <name>'') : ")
139-
if input_copyright == 'Quit' or input_copyright == 'quit' or input_copyright == 'Q':
140-
return
143+
if license == "" and copyright == "":
144+
input_copyright = input_copyright_while_running()
141145

142146
input_ok = check_input_format(input_copyright)
143147
if input_ok is False:
144148
return
149+
else:
150+
input_copyright = copyright
145151

146152
if input_copyright != "":
147153
logger.warning(f" * Your input Copyright : {input_copyright}")
@@ -178,10 +184,9 @@ def save_result_log():
178184
logger.warning("Failed to print add result log. " + str(ex))
179185

180186

181-
def add_content(path_to_find, file, manual_mode, input_license="", input_copyright=""):
182-
global _auto_add_mode, _result_log
187+
def add_content(path_to_find, file, input_license="", input_copyright=""):
188+
global _result_log
183189
file_to_check_list = []
184-
_auto_add_mode = False
185190
_check_only_file_mode = False
186191

187192
if path_to_find == "":
@@ -192,7 +197,7 @@ def add_content(path_to_find, file, manual_mode, input_license="", input_copyrig
192197
logger, _result_log = init_log(os.path.join(output_dir, "fosslight_reuse_add_log_"+now+".txt"),
193198
True, logging.INFO, logging.DEBUG, _PKG_NAME, path_to_find)
194199

195-
if input_copyright != "" and manual_mode is False:
200+
if input_copyright != "":
196201
input_ok = check_input_format(input_copyright)
197202
if input_ok is False:
198203
return
@@ -201,30 +206,31 @@ def add_content(path_to_find, file, manual_mode, input_license="", input_copyrig
201206
file_to_check_list = file.split(',')
202207
_check_only_file_mode = True
203208

204-
if not manual_mode and _check_only_file_mode is False:
205-
if input_license == "" and input_copyright == "":
206-
logger.info(" You have to input license and copyright to add with -l and -c option")
207-
return
208-
_auto_add_mode = True
209-
210209
if _check_only_file_mode:
211210
main_parser = reuse_arg_parser()
212-
213211
missing_license_list, missing_copyright_list, error_occurred, project = reuse_for_files(path_to_find, file_to_check_list)
214212

215213
if missing_license_list is not None and len(missing_license_list) > 0:
216-
logger.warning(f" * Your input license : {input_license}")
217-
parsed_args = main_parser.parse_args(['addheader', '--license', str(input_license)] + missing_license_list)
218-
try:
219-
run(parsed_args, project)
220-
except Exception as ex:
221-
print_error('Error_call_run_in_license_file_only :' + str(ex))
214+
if input_license == "" and input_copyright == "":
215+
input_license = input_license_while_running()
216+
217+
if input_license != "":
218+
logger.warning(f" * Your input license : {input_license}")
219+
parsed_args = main_parser.parse_args(['addheader', '--license', str(input_license)] + missing_license_list)
220+
try:
221+
run(parsed_args, project)
222+
except Exception as ex:
223+
print_error('Error_call_run_in_license_file_only :' + str(ex))
222224

223225
if missing_copyright_list is not None and len(missing_copyright_list) > 0:
224-
logger.warning(f" * Your input Copyright : {input_copyright}")
225-
parsed_args = main_parser.parse_args(['addheader', '--copyright',
226-
'SPDX-FileCopyrightText: ' + str(input_copyright),
227-
'--exclude-year'] + missing_copyright_list)
226+
if input_license == "" and input_copyright == "":
227+
input_copyright = input_copyright_while_running()
228+
229+
if input_copyright != "":
230+
logger.warning(f" * Your input Copyright : {input_copyright}")
231+
parsed_args = main_parser.parse_args(['addheader', '--copyright',
232+
'SPDX-FileCopyrightText: ' + str(input_copyright),
233+
'--exclude-year'] + missing_copyright_list)
228234
try:
229235
run(parsed_args, project)
230236
except Exception as ex:

src/fosslight_reuse/_help.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
_HELP_MESSAGE_REUSE = """
88
Usage: fosslight_reuse [Mode] [option1] <arg1> [option2] <arg2>...
99
ex) fosslight_reuse lint -p /home/test/ -f "notice/sample.py,src/init.py"
10-
fosslight_reuse add -c "Copyright 2019-2021 LG Electronics Inc." -l "GPL-3.0"
10+
fosslight_reuse add -p /home/test/ -c "Copyright 2019-2021 LG Electronics Inc." -l "GPL-3.0-only"
1111
1212
FOSSLight Reuse is a Tool to check REUSE compliance in source code.
1313
@@ -25,8 +25,7 @@
2525
-n\t\t\t Don't exclude venv*, node_modules, and .*/ from the analysis
2626
Options for only 'add' mode
2727
-l <license>\t License name(SPDX format) to add
28-
-c <copyright>\t Copyright to add(ex, "Copyright 2015-2021 LGE Electronics")
29-
-m\t\t\t Add manually your input license and copyright (using without -l or -c option) """
28+
-c <copyright>\t Copyright to add(ex, Copyright 2015-2021 LGE Electronics Inc.)"""
3029

3130

3231
def print_help_msg(exitOpt=True):

src/fosslight_reuse/cli.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ def main():
1616
parser.add_argument('--file', '-f', help='Files to check', type=str, dest='file', default="")
1717
parser.add_argument('--output', '-o', help='Output file name', type=str, dest='output', default="")
1818
parser.add_argument('--no', '-n', help='Disable automatic exclude mode', action='store_true', dest='disable')
19-
parser.add_argument('--manual', '-m', help='Manual input mode', action='store_true', dest='manual')
2019
parser.add_argument('--license', '-l', help='License name to add', type=str, dest='license', default="")
2120
parser.add_argument('--copyright', '-c', help='Copyright to add', type=str, dest='copyright', default="")
2221
args = parser.parse_args()
@@ -26,7 +25,7 @@ def main():
2625
elif args.mode == "report":
2726
convert_report(args.path, args.file, args.output)
2827
elif args.mode == "add":
29-
add_content(args.path, args.file, args.manual, args.license, args.copyright)
28+
add_content(args.path, args.file, args.license, args.copyright)
3029
else:
3130
pass
3231

tests/add/test_both_have_1.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SPDX-FileCopyrightText: Copyright 2019-2021 LG Electronics Inc.
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-only
4+
5+
import os
6+
from fosslight_util.set_log import init_log
7+
8+
9+
def main():
10+
output_dir = "tests"
11+
logger, _result_log = init_log(os.path.join(output_dir, "test_add_log.txt"))
12+
logger.warning("TESTING - add mode")
13+
14+
15+
if __name__ == '__main__':
16+
main()

tests/add/test_both_have_2.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2011 LG Electronics Inc.
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-only
4+
5+
import os
6+
from fosslight_util.set_log import init_log
7+
8+
9+
def main():
10+
output_dir = "tests"
11+
logger, _result_log = init_log(os.path.join(output_dir, "test_add_log.txt"))
12+
logger.warning("TESTING - add mode")
13+
14+
15+
if __name__ == '__main__':
16+
main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# SPDX-License-Identifier: GPL-3.0-only
12

23
import os
34
from fosslight_util.set_log import init_log

tests/add/test_no_license.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SPDX-FileCopyrightText: Copyright 2019-2021 LG Electronics Inc.
2+
import os
3+
from fosslight_util.set_log import init_log
4+
5+
6+
def main():
7+
output_dir = "tests"
8+
logger, _result_log = init_log(os.path.join(output_dir, "test_add_log.txt"))
9+
logger.warning("TESTING - add mode")
10+
11+
12+
if __name__ == '__main__':
13+
main()

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ commands =
2929
cat test_report/output.yaml
3030
rm -rf tests/add_result
3131
cp -r tests/add tests/add_result
32-
fosslight_reuse add -p tests/add_result -c "Copyright 2019-2021 LG Electronics Inc." -l "GPL-3.0"
32+
fosslight_reuse add -p tests/add_result -c "Copyright 2019-2021 LG Electronics Inc." -l "GPL-3.0-only"
3333
[testenv:release]
3434
deps =
3535
-r{toxinidir}/requirements-dev.txt
@@ -41,5 +41,5 @@ commands =
4141
fosslight_reuse report -p tests/report
4242
fosslight_reuse report -f tests/report/OSS-Report-Sample_1_BOM.xlsx -o test_report/output
4343
cp -r tests/add tests/add_result
44-
fosslight_reuse add -p tests/add_result -c "Copyright 2019-2021 LG Electronics Inc." -l "GPL-3.0"
44+
fosslight_reuse add -p tests/add_result -c "Copyright 2019-2021 LG Electronics Inc." -l "GPL-3.0-only"
4545
pytest -v --flake8

0 commit comments

Comments
 (0)