Skip to content

Commit

Permalink
Fixed #93
Browse files Browse the repository at this point in the history
Use 'dje_license_name' as the value of the 'licesen_text_file'
  • Loading branch information
chinyeungli committed May 20, 2014
1 parent 92d3d84 commit 4c2db1c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
23 changes: 12 additions & 11 deletions about_code_tool/genabout.py
Expand Up @@ -338,7 +338,7 @@ def pre_process_and_dje_license_dict(self, input_list, api_url, api_username, ap
try:
if line['dje_license']:
detail = self.get_license_details_from_api(api_url, api_username, api_key, line['dje_license'])
line['dje_license_name'], key_text_dict[line['dje_license']] = detail
line['dje_license_name'], key_text_dict[line['dje_license_name']] = detail
except Exception as e:
self.warnings.append(Warn('dje_license', '',
"Missing 'dje_license' for " + line['about_file']))
Expand Down Expand Up @@ -404,13 +404,13 @@ def pre_generation(self, gen_location, input_list, action_num, all_in_one):

@staticmethod
def gen_license_list(line):
dje_key = line['dje_license']
dje_license_name = line['dje_license_name']
file_location = line['about_file']
if file_location.endswith('/'):
file_location = file_location.rpartition('/')[0]
about_parent_dir = dirname(file_location)
line['license_text_file'] = dje_key +'.LICENSE'
return (about_parent_dir, dje_key)
line['license_text_file'] = dje_license_name +'.LICENSE'
return (about_parent_dir, dje_license_name)

@staticmethod
def format_output(input_list):
Expand Down Expand Up @@ -675,23 +675,24 @@ def main(parser, options, args):
print("The input does not have the 'dje_license' key which is required.")
sys.exit(errno.EINVAL)

dje_license_list = gen.get_dje_license_list(output_path, input_list, gen_license)

# The dje_license_list is an empty list if gen_license is 'False'
if gen_license:
dje_license_dict = gen.pre_process_and_dje_license_dict(input_list,
api_url,
api_username,
api_key)
license_list_context = gen.process_dje_licenses(dje_license_list,
dje_license_dict,
output_path)
gen.write_licenses(license_list_context)

dje_license_list = gen.get_dje_license_list(output_path, input_list, gen_license)

components_list = gen.pre_generation(output_path, input_list, action_num, all_in_one)
formatted_output = gen.format_output(components_list)
gen.write_output(formatted_output)

if dje_license_list:
license_list_context = gen.process_dje_licenses(dje_license_list,
dje_license_dict,
output_path)
gen.write_licenses(license_list_context)

gen.warnings_errors_summary()
print('Warnings: %s' % len(gen.warnings))
print('Errors: %s' % len(gen.errors))
Expand Down
16 changes: 10 additions & 6 deletions about_code_tool/tests/test_genabout.py
Expand Up @@ -231,8 +231,9 @@ def test_get_dje_license_list_gen_license_with_dje_license_key_empty_license_tex
gen_location = join(TESTDATA_PATH, "test_files_for_genabout/")
input_list = [{'about_file': '/about.py.ABOUT', 'version': '0.8.1',
'about_resource': '.', 'name': 'ABOUT tool',
'dje_license_name': 'Apache License 2.0',
'license_text_file': '', 'dje_license': 'apache-2.0'}]
expected_output_list = [('/', 'apache-2.0')]
expected_output_list = [('/', 'Apache License 2.0')]
gen_license = True
lic_output_list = gen.get_dje_license_list(gen_location, input_list, gen_license)
self.assertTrue(expected_output_list == lic_output_list)
Expand All @@ -257,8 +258,9 @@ def test_get_dje_license_list_gen_license_with_dje_license_key_no_license_text_f
gen_location = join(TESTDATA_PATH, "test_files_for_genabout/")
input_list = [{'about_file': '/about.py.ABOUT', 'version': '0.8.1',
'about_resource': '.', 'name': 'ABOUT tool',
'dje_license_name': 'Apache License 2.0',
'dje_license': 'apache-2.0'}]
expected_output_list = [('/', 'apache-2.0')]
expected_output_list = [('/', 'Apache License 2.0')]
gen_license = True
lic_output_list = gen.get_dje_license_list(gen_location, input_list, gen_license)
self.assertTrue(expected_output_list == lic_output_list)
Expand Down Expand Up @@ -434,21 +436,23 @@ def test_gen_license_list_license_text_file_no_value(self):
gen = genabout.GenAbout()
input_list = {'about_file': '/tmp/3pp/opensans/', 'name': 'OpenSans Fonts',
'version': '1', 'dje_license': 'apache-2.0',
'dje_license_name': 'Apache License 2.0',
'license_text_file': '', 'about_resource': 'opensans'}
expected_list = ('/tmp/3pp', 'apache-2.0')
expected_list = ('/tmp/3pp', 'Apache License 2.0')
output = gen.gen_license_list(input_list)
self.assertTrue(expected_list == output)
self.assertTrue(input_list['license_text_file'] == 'apache-2.0.LICENSE')
self.assertTrue(input_list['license_text_file'] == 'Apache License 2.0.LICENSE')

def test_gen_license_list_no_license_text_file_key(self):
gen = genabout.GenAbout()
input_list = {'about_file': '/tmp/3pp/opensans/', 'name': 'OpenSans Fonts',
'version': '1', 'dje_license': 'apache-2.0',
'dje_license_name': 'Apache License 2.0',
'about_resource': 'opensans'}
expected_list = ('/tmp/3pp', 'apache-2.0')
expected_list = ('/tmp/3pp', 'Apache License 2.0')
output = gen.gen_license_list(input_list)
self.assertTrue(expected_list == output)
self.assertTrue(input_list['license_text_file'] == 'apache-2.0.LICENSE')
self.assertTrue(input_list['license_text_file'] == 'Apache License 2.0.LICENSE')

def test_copy_license_files_test_path_not_endswith_slash(self):
gen = genabout.GenAbout()
Expand Down

0 comments on commit 4c2db1c

Please sign in to comment.