Skip to content

Commit 305dbca

Browse files
committed
Fixed #101 - Add 'about_resource_path' in the ABOUT file
Fixed #129 - Use the 'license_text_file' as the license input for attribution.
1 parent 3be28a1 commit 305dbca

File tree

5 files changed

+49
-59
lines changed

5 files changed

+49
-59
lines changed

about_code_tool/about.py

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -951,16 +951,6 @@ def notice_text(self):
951951

952952
return "" # Returns empty string if the notice file does not exist
953953

954-
def get_dje_license_name(self):
955-
"""
956-
Return the dje_license value if the dje_license field exists
957-
"""
958-
try:
959-
return self.parsed['dje_license_name']
960-
except Exception as e:
961-
pass
962-
return ""
963-
964954
def get_license_text_file_name(self):
965955
"""
966956
Return the license_text_file name if the license_text_file field exists
@@ -991,6 +981,16 @@ def get_about_name(self):
991981
pass
992982
return ""
993983

984+
def get_about_resource_path(self):
985+
"""
986+
Return the about object's name
987+
"""
988+
try:
989+
return self.parsed['about_resource_path']
990+
except Exception as e:
991+
pass
992+
return ""
993+
994994
class AboutCollector(object):
995995
"""
996996
A collection of AboutFile instances.
@@ -1140,6 +1140,7 @@ def generate_attribution(self, template_path=None, limit_to=None):
11401140
license_key = []
11411141
license_text_list = []
11421142
license_dict = {}
1143+
common_license_dict = {}
11431144
not_exist_components = list(limit_to)
11441145

11451146
for about_object in self:
@@ -1155,16 +1156,24 @@ def generate_attribution(self, template_path=None, limit_to=None):
11551156
if not limit_to or about_relative_path in limit_to:
11561157
validated_fields.append(about_object.validated_fields)
11571158
notice_text.append(about_object.notice_text())
1158-
dje_license_name = about_object.get_dje_license_name()
11591159
license_text_file = about_object.get_license_text_file_name()
1160-
license_text = about_object.get_license_text()
1160+
about_resource_path = about_object.get_about_resource_path()
1161+
if not about_resource_path:
1162+
msg = 'About File: %s - The required field, about_resource_path, not found'\
1163+
' License generation is skipped.'\
1164+
% about_object.location
1165+
self.genattrib_errors.append(Error(GENATTRIB,\
1166+
'about_resource',\
1167+
about_object.location, msg))
11611168
if license_text_file:
1162-
# Check if the license key, license_text_file, already
1163-
# exist in the license dictionary
1164-
if license_text_file in license_dict:
1169+
# Use the about_file_path as the key
1170+
# Check if the key already existed in the dictionary
1171+
# This shouldn't be reached as the 'about_resource_path'
1172+
# should be unique.
1173+
if about_resource_path in license_dict:
11651174
# Raise error if key name are the same but the content
11661175
# are different
1167-
license_text_check = license_dict[license_text_file]
1176+
license_text_check = license_dict[about_resource_path]
11681177
if not unicode(license_text_check) == unicode(about_object.license_text()):
11691178
msg = 'License Name: %s - Same license name with different content.'\
11701179
' License generation is skipped.'\
@@ -1173,18 +1182,12 @@ def generate_attribution(self, template_path=None, limit_to=None):
11731182
'license_text',\
11741183
license_text_file, msg))
11751184
else:
1176-
if license_text_file.endswith('.LICENSE'):
1177-
license_dict[license_text_file] = unicode(about_object.license_text(), errors='replace')
1178-
else:
1179-
# If the 'license_text_file' doesn't end with '.LICENSE',
1180-
# such as COPYING, COPYRIGHT, we will use the name
1181-
# of the About file combine with the 'license_text_file'
1182-
# as the key of the license dictionary.
1183-
license_name = about_object.get_about_name() + '_' + license_text_file
1184-
license_dict[license_name] = unicode(about_object.license_text(), errors='replace')
1185-
elif license_text:
1185+
license_dict[about_resource_path] = unicode(about_object.license_text(), errors='replace')
1186+
if license_text_file in COMMON_LICENSES:
1187+
common_license_dict[license_text_file] = unicode(about_object.license_text(), errors='replace')
1188+
elif about_object.get_license_text():
11861189
# We don't need to do anything here as the license_text
1187-
# will be capture directly in the about object.
1190+
# will be captured directly in the about object.
11881191
pass
11891192
else:
11901193
msg = 'No license_text is found. License generation is skipped.'
@@ -1200,16 +1203,14 @@ def generate_attribution(self, template_path=None, limit_to=None):
12001203
self.genattrib_errors.append(Error(GENATTRIB, 'about_file',\
12011204
component, msg))
12021205

1203-
# We want the license generation in alphabetical order
1204-
for key in sorted(license_dict.keys()):
1206+
# We want to display common_licenses in alphabetical order
1207+
for key in sorted(common_license_dict.keys()):
12051208
license_key.append(key)
1206-
license_text_list.append(license_dict[key])
1209+
license_text_list.append(common_license_dict[key])
12071210

12081211
return template.render(about_objects=validated_fields,
12091212
license_keys=license_key,
12101213
license_texts = license_text_list,
1211-
#license_keys=license_text_file_name,
1212-
#license_texts = license_text_file_content,
12131214
notice_texts=notice_text,
12141215
license_dicts=license_dict,
12151216
common_licenses=COMMON_LICENSES)

about_code_tool/genabout.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,9 @@ def pre_generation(self, gen_location, input_list, action_num, all_in_one):
467467
# This is to get the filename instead of the file path
468468
file_location = file_location.rpartition('/')[2]
469469
about_file_location = join(gen_location, file_location)
470+
if not file_location.startswith('/'):
471+
line['about_resource_path'] = '/'
472+
line['about_resource_path'] += file_location
470473
dir = dirname(about_file_location)
471474
if not _exists(dir):
472475
makedirs(dir)

about_code_tool/templates/default.html

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ <h1>OPEN SOURCE SOFTWARE INFORMATION</h1>
5656
<h3 class="component-name">{{ about_object.name }}
5757
{% if about_object.version %}{{ about_object.version }}{% endif %}
5858
</h3>
59-
{% if about_object.license_text_file in license_dicts.keys() %}
59+
{% if about_object.about_resource_path in license_dicts.keys() %}
6060
{% if about_object.dje_license_name %}
6161
<p>This component is licensed under {{about_object.dje_license_name }}.
6262
{% endif %}
@@ -70,18 +70,20 @@ <h3 class="component-name">{{ about_object.name }}
7070
<pre class="component-notice">{{ notice_texts[loop.index0] }}</pre>
7171
{% endif %}
7272
{% if about_object.license_text_file %}
73+
<!-- 'license_text_file' is not a common license if it
74+
doesn't end with '.LICENSE'
75+
-->
7376
{% if not about_object.license_text_file.endswith('.LICENSE') %}
74-
<pre>{{ license_dicts[about_object.name + '_' + about_object.license_text_file]|e }}</pre>
75-
{% endif %}
76-
{% if about_object.license_text_file in license_dicts.keys() %}
77+
<pre>{{ license_dicts[about_object.about_resource_path]|e }}</pre>
78+
{% elif about_object.about_resource_path in license_dicts.keys() %}
7779
{% if about_object.license_text_file in common_licenses %}
7880
<p>Full text of
7981
<a class="{{ about_object.license_text_file }}" href="#component-license-{{ about_object.license_text_file }}">
8082
{{ about_object.license_text_file }}
8183
</a>
8284
is available at the end of this document.</p>
8385
{% else %}
84-
<pre>{{ license_dicts[about_object.license_text_file]|e }}</pre>
86+
<pre>{{ license_dicts[about_object.about_resource_path]|e }}</pre>
8587
{% endif %}
8688
{% endif %}
8789
{% elif about_object.license_text %}

about_code_tool/tests/test_about.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -578,36 +578,18 @@ def test_notice_text_returns_empty_string_when_ref_file_doesnt_exist(self):
578578
notice_text = about_file.notice_text()
579579
self.assertEqual(notice_text, expected)
580580

581-
def test_get_dje_license_name(self):
582-
expected = 'Apache License 2.0'
583-
about_file = about.AboutFile(join(TESTDATA_PATH, 'parser_tests/about_resource_field_present.ABOUT'))
584-
output = about_file.get_dje_license_name()
585-
self.assertTrue(output == expected)
586-
587581
def test_get_license_text_file_name(self):
588582
expected = 'httpd.LICENSE'
589583
about_file = about.AboutFile(join(TESTDATA_PATH, 'parser_tests/about_resource_field_present.ABOUT'))
590584
output = about_file.get_license_text_file_name()
591585
self.assertTrue(output == expected)
592586

593-
def test_get_dje_license_name_no_value(self):
594-
expected = ''
595-
about_file = about.AboutFile(join(TESTDATA_PATH, 'parser_tests/about_file_empty_value_for_dje_license_license_text_file.ABOUT'))
596-
output = about_file.get_dje_license_name()
597-
self.assertTrue(output == expected)
598-
599587
def test_get_license_text_file_name_no_value(self):
600588
expected = ''
601589
about_file = about.AboutFile(join(TESTDATA_PATH, 'parser_tests/about_file_empty_value_for_dje_license_license_text_file.ABOUT'))
602590
output = about_file.get_license_text_file_name()
603591
self.assertTrue(output == expected)
604592

605-
def test_get_dje_license_name_no_key(self):
606-
expected = None
607-
about_file = about.AboutFile(join(TESTDATA_PATH, 'parser_tests/about_file_no_dje_license_no_license_text_file_keys.ABOUT'))
608-
output = about_file.get_dje_license_name()
609-
self.assertTrue(output == expected)
610-
611593
def test_get_license_text_file_name_no_key(self):
612594
expected = None
613595
about_file = about.AboutFile(join(TESTDATA_PATH, 'parser_tests/about_file_no_dje_license_no_license_text_file_keys.ABOUT'))

about_code_tool/tests/test_genabout.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ def test_pre_generation_about_is_dir_exists_action_0(self):
299299
'about_resource': '.', 'name': 'ABOUT tool'}]
300300
expected_output_list = [[join(TESTDATA_PATH, 'test_files_for_genabout/TESTCASE', 'TESTCASE.ABOUT'),
301301
{'about_file': '/TESTCASE/', 'version': '0.8.1',
302+
'about_resource_path' : '/TESTCASE/TESTCASE.ABOUT',
302303
'about_resource': '.', 'name': 'ABOUT tool'}]]
303304
output_list = gen.pre_generation(gen_location, input_list, action_num, False)
304305
self.assertTrue(expected_output_list == output_list)
@@ -336,9 +337,9 @@ def test_pre_generation_about_exists_action_2(self):
336337
input_list = [{'about_file': '/about.py.ABOUT', 'version': '0.8.2',
337338
'about_resource': '.', 'name': '', 'test': 'test sample'}]
338339
expected_output_list = [[join(TESTDATA_PATH, 'test_files_for_genabout', 'about.py.ABOUT'),
339-
{'test': 'test sample', 'about_file': 'about.py.ABOUT',
340-
'version': '0.8.1', 'about_resource': '.',
341-
'name': 'ABOUT tool'}]]
340+
{'about_file': 'about.py.ABOUT', 'name': 'ABOUT tool',
341+
'about_resource_path': '/about.py.ABOUT',
342+
'version': '0.8.1', 'test': 'test sample', 'about_resource': '.'}]]
342343
output_list = gen.pre_generation(GEN_LOCATION, input_list, action_num, False)
343344
self.assertTrue(expected_output_list == output_list)
344345
self.assertFalse(gen.warnings, "No warnings should be returned.")
@@ -351,7 +352,8 @@ def test_pre_generation_about_exists_action_3(self):
351352
'about_resource': '.', 'name': '', 'test': 'test sample'}]
352353
expected_output_list = [[join(TESTDATA_PATH, 'test_files_for_genabout', 'about.py.ABOUT'),
353354
{'about_file': '/about.py.ABOUT', 'version': '0.8.2',
354-
'about_resource': '.', 'name': '', 'test': 'test sample'}]]
355+
'about_resource_path': '/about.py.ABOUT',
356+
'about_resource': '.', 'name': '', 'test': 'test sample'}]]
355357
output_list = gen.pre_generation(GEN_LOCATION, input_list, action_num, False)
356358
self.assertTrue(expected_output_list == output_list)
357359
self.assertFalse(gen.warnings, "No warnings should be returned.")

0 commit comments

Comments
 (0)