Skip to content

Commit e3933c4

Browse files
committed
Fixed #94.
Using the 'dje_license_key' as the generated license's filename and the value of the 'license_text_file' while using the 'dje_license_name' as the license name in the attribution.
1 parent 4c2db1c commit e3933c4

File tree

2 files changed

+41
-22
lines changed

2 files changed

+41
-22
lines changed

about_code_tool/genabout.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,10 @@ def get_license_details_from_api(self, url, username, api_key, license_key):
298298
data = self.request_license_data(url, username, api_key, license_key)
299299
license_name = data.get('name', '')
300300
license_text = data.get('full_text', '')
301-
return [license_name, license_text]
301+
license_key = data.get('key', '')
302+
return [license_name, license_key, license_text]
302303

303-
def get_dje_license_list(self, gen_location, input_list, gen_license):
304+
def get_dje_license_list(self, gen_location, input_list, gen_license, dje_license_dict):
304305
license_output_list = []
305306
for line in input_list:
306307
try:
@@ -318,6 +319,8 @@ def get_dje_license_list(self, gen_location, input_list, gen_license):
318319
if gen_license:
319320
if line['dje_license']:
320321
license_output_list.append(self.gen_license_list(line))
322+
line['license_text_file'] = dje_license_dict[line['dje_license_name']][0]\
323+
+ '.LICENSE'
321324
else:
322325
self.warnings.append(Warn('dje_license', '',
323326
"Missing 'dje_license' for " + line['about_file']))
@@ -327,6 +330,8 @@ def get_dje_license_list(self, gen_location, input_list, gen_license):
327330
if gen_license:
328331
if line['dje_license']:
329332
license_output_list.append(self.gen_license_list(line))
333+
line['license_text_file'] = dje_license_dict[line['dje_license_name']][0]\
334+
+ '.LICENSE'
330335
else:
331336
self.warnings.append(Warn('dje_license', '',
332337
"Missing 'dje_license' for " + line['about_file']))
@@ -337,21 +342,28 @@ def pre_process_and_dje_license_dict(self, input_list, api_url, api_username, ap
337342
for line in input_list:
338343
try:
339344
if line['dje_license']:
345+
detail_list = []
340346
detail = self.get_license_details_from_api(api_url, api_username, api_key, line['dje_license'])
341-
line['dje_license_name'], key_text_dict[line['dje_license_name']] = detail
347+
line['dje_license_name'] = detail[0]
348+
dje_key = detail[1]
349+
license_context = detail [2]
350+
detail_list.append(dje_key)
351+
detail_list.append(license_context)
352+
key_text_dict[line['dje_license_name']] = detail_list
342353
except Exception as e:
343354
self.warnings.append(Warn('dje_license', '',
344355
"Missing 'dje_license' for " + line['about_file']))
345356
return key_text_dict
346357

347358
def process_dje_licenses(self, dje_license_list, dje_license_dict, output_path):
348359
license_list_context = []
349-
for gen_path, license_key in dje_license_list:
360+
for gen_path, license_name in dje_license_list:
350361
if gen_path.startswith('/'):
351362
gen_path = gen_path.partition('/')[2]
363+
license_key = dje_license_dict[license_name][0]
352364
gen_license_path = join(output_path, gen_path, license_key) + '.LICENSE'
353365
if not _exists(gen_license_path) and not self.extract_dje_license_error:
354-
context = dje_license_dict[license_key]
366+
context = dje_license_dict[license_name][1]
355367
if context:
356368
gen_path_context = []
357369
gen_path_context.append(gen_license_path)
@@ -409,7 +421,6 @@ def gen_license_list(line):
409421
if file_location.endswith('/'):
410422
file_location = file_location.rpartition('/')[0]
411423
about_parent_dir = dirname(file_location)
412-
line['license_text_file'] = dje_license_name +'.LICENSE'
413424
return (about_parent_dir, dje_license_name)
414425

415426
@staticmethod
@@ -534,6 +545,7 @@ def main(parser, options, args):
534545
api_username = ''
535546
api_key = ''
536547
gen_license = False
548+
dje_license_dict = {}
537549

538550
if options.version:
539551
print('ABOUT tool {0}\n{1}'.format(__version__, __copyright__))
@@ -681,8 +693,7 @@ def main(parser, options, args):
681693
api_username,
682694
api_key)
683695

684-
dje_license_list = gen.get_dje_license_list(output_path, input_list, gen_license)
685-
696+
dje_license_list = gen.get_dje_license_list(output_path, input_list, gen_license, dje_license_dict)
686697
components_list = gen.pre_generation(output_path, input_list, action_num, all_in_one)
687698
formatted_output = gen.format_output(components_list)
688699
gen.write_output(formatted_output)

about_code_tool/tests/test_genabout.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ def test_get_dje_license_list_no_gen_license_with_no_license_text_file_key(self)
169169
'about_resource': '.', 'name': 'ABOUT tool'}]
170170
expected_output_list = []
171171
gen_license = False
172-
lic_output_list = gen.get_dje_license_list(gen_location, input_list, gen_license)
172+
dje_license_dict = {}
173+
lic_output_list = gen.get_dje_license_list(gen_location, input_list, gen_license, dje_license_dict)
173174
self.assertTrue(expected_output_list == lic_output_list)
174175
self.assertFalse(gen.warnings, "No warnings should be returned.")
175176
self.assertFalse(gen.errors, "No errors should be returned.")
@@ -182,7 +183,8 @@ def test_get_dje_license_list_no_gen_license_with_license_text_file_key_not_exis
182183
'license_text_file': 'not_exist.txt'}]
183184
expected_output_list = []
184185
gen_license = False
185-
lic_output_list = gen.get_dje_license_list(gen_location, input_list, gen_license)
186+
dje_license_dict = {}
187+
lic_output_list = gen.get_dje_license_list(gen_location, input_list, gen_license, dje_license_dict)
186188
self.assertTrue(expected_output_list == lic_output_list)
187189
self.assertFalse(gen.warnings, "No warnings should be returned.")
188190
self.assertTrue(len(gen.errors) == 1, "Should return 1 error.")
@@ -195,7 +197,8 @@ def test_get_dje_license_list_file_no_gen_license_with_license_text_file_key_exi
195197
'license_text_file': '../../../../apache2.LICENSE'}]
196198
expected_output_list = []
197199
gen_license = False
198-
lic_output_list = gen.get_dje_license_list(gen_location, input_list, gen_license)
200+
dje_license_dict = {}
201+
lic_output_list = gen.get_dje_license_list(gen_location, input_list, gen_license, dje_license_dict)
199202
self.assertTrue(expected_output_list == lic_output_list)
200203
self.assertFalse(gen.warnings, "No warnings should be returned.")
201204
self.assertFalse(gen.errors, "No errors should be returned.")
@@ -208,7 +211,8 @@ def test_get_dje_license_list_dir_no_gen_license_with_license_text_file_key_exis
208211
'license_text_file': '../../../../apache2.LICENSE'}]
209212
expected_output_list = []
210213
gen_license = False
211-
lic_output_list = gen.get_dje_license_list(gen_location, input_list, gen_license)
214+
dje_license_dict = {}
215+
lic_output_list = gen.get_dje_license_list(gen_location, input_list, gen_license, dje_license_dict)
212216
self.assertTrue(expected_output_list == lic_output_list)
213217
self.assertFalse(gen.warnings, "No warnings should be returned.")
214218
self.assertFalse(gen.errors, "No errors should be returned.")
@@ -218,10 +222,12 @@ def test_get_dje_license_list_file_gen_license_with_license_text_file_key_exist(
218222
gen_location = join(TESTDATA_PATH, "test_files_for_genabout/")
219223
input_list = [{'about_file': '/about.py.ABOUT', 'version': '0.8.1',
220224
'about_resource': '.', 'name': 'ABOUT tool',
225+
'dje_license': 'Apache License 2.0',
221226
'license_text_file': '../../../../apache2.LICENSE'}]
222227
expected_output_list = []
223228
gen_license = True
224-
lic_output_list = gen.get_dje_license_list(gen_location, input_list, gen_license)
229+
dje_license_dict = {'Apache License 2.0': [u'apache-2.0', 'test context']}
230+
lic_output_list = gen.get_dje_license_list(gen_location, input_list, gen_license, dje_license_dict)
225231
self.assertTrue(expected_output_list == lic_output_list)
226232
self.assertFalse(gen.warnings, "No warnings should be returned.")
227233
self.assertFalse(gen.errors, "No errors should be returned.")
@@ -231,11 +237,13 @@ def test_get_dje_license_list_gen_license_with_dje_license_key_empty_license_tex
231237
gen_location = join(TESTDATA_PATH, "test_files_for_genabout/")
232238
input_list = [{'about_file': '/about.py.ABOUT', 'version': '0.8.1',
233239
'about_resource': '.', 'name': 'ABOUT tool',
240+
'dje_license': 'apache-2.0',
234241
'dje_license_name': 'Apache License 2.0',
235-
'license_text_file': '', 'dje_license': 'apache-2.0'}]
242+
'license_text_file': ''}]
236243
expected_output_list = [('/', 'Apache License 2.0')]
237244
gen_license = True
238-
lic_output_list = gen.get_dje_license_list(gen_location, input_list, gen_license)
245+
dje_license_dict = {'Apache License 2.0': [u'apache-2.0', 'test context']}
246+
lic_output_list = gen.get_dje_license_list(gen_location, input_list, gen_license, dje_license_dict)
239247
self.assertTrue(expected_output_list == lic_output_list)
240248
self.assertFalse(gen.warnings, "No warnings should be returned.")
241249
self.assertFalse(gen.errors, "No errors should be returned.")
@@ -248,7 +256,8 @@ def test_get_dje_license_list_gen_license_with_empty_dje_license_key_empty_licen
248256
'license_text_file': '', 'dje_license': ''}]
249257
expected_output_list = []
250258
gen_license = True
251-
lic_output_list = gen.get_dje_license_list(gen_location, input_list, gen_license)
259+
dje_license_dict = {'Apache License 2.0': [u'apache-2.0', 'test context']}
260+
lic_output_list = gen.get_dje_license_list(gen_location, input_list, gen_license, dje_license_dict)
252261
self.assertTrue(expected_output_list == lic_output_list)
253262
self.assertTrue(len(gen.warnings) == 1, "Should return 1 warning.")
254263
self.assertFalse(gen.errors, "No errors should be returned.")
@@ -259,10 +268,11 @@ def test_get_dje_license_list_gen_license_with_dje_license_key_no_license_text_f
259268
input_list = [{'about_file': '/about.py.ABOUT', 'version': '0.8.1',
260269
'about_resource': '.', 'name': 'ABOUT tool',
261270
'dje_license_name': 'Apache License 2.0',
262-
'dje_license': 'apache-2.0'}]
271+
'dje_license': 'Apache License 2.0'}]
263272
expected_output_list = [('/', 'Apache License 2.0')]
264273
gen_license = True
265-
lic_output_list = gen.get_dje_license_list(gen_location, input_list, gen_license)
274+
dje_license_dict = {'Apache License 2.0': [u'apache-2.0', 'test context']}
275+
lic_output_list = gen.get_dje_license_list(gen_location, input_list, gen_license, dje_license_dict)
266276
self.assertTrue(expected_output_list == lic_output_list)
267277
self.assertFalse(gen.warnings, "No warnings should be returned.")
268278
self.assertFalse(gen.errors, "No errors should be returned.")
@@ -441,7 +451,6 @@ def test_gen_license_list_license_text_file_no_value(self):
441451
expected_list = ('/tmp/3pp', 'Apache License 2.0')
442452
output = gen.gen_license_list(input_list)
443453
self.assertTrue(expected_list == output)
444-
self.assertTrue(input_list['license_text_file'] == 'Apache License 2.0.LICENSE')
445454

446455
def test_gen_license_list_no_license_text_file_key(self):
447456
gen = genabout.GenAbout()
@@ -452,7 +461,6 @@ def test_gen_license_list_no_license_text_file_key(self):
452461
expected_list = ('/tmp/3pp', 'Apache License 2.0')
453462
output = gen.gen_license_list(input_list)
454463
self.assertTrue(expected_list == output)
455-
self.assertTrue(input_list['license_text_file'] == 'Apache License 2.0.LICENSE')
456464

457465
def test_copy_license_files_test_path_not_endswith_slash(self):
458466
gen = genabout.GenAbout()
@@ -494,8 +502,8 @@ def test_write_licenses(self):
494502
def test_process_dje_licenses(self):
495503
gen = genabout.GenAbout()
496504
test_license_list = [('/', 'test')]
497-
test_license_dict = {'test': u'This is a test license.'}
505+
test_license_dict = {'test': [u'test_key', u'This is a test license.']}
498506
test_path = '/test'
499-
expected_output = [['/test/test.LICENSE', 'This is a test license.']]
507+
expected_output = [['/test/test_key.LICENSE', 'This is a test license.']]
500508
output = gen.process_dje_licenses(test_license_list, test_license_dict, test_path)
501509
self.assertTrue(output == expected_output)

0 commit comments

Comments
 (0)