Skip to content

Commit b28a1fe

Browse files
committed
Fixed #136 - It's passing a list of about object ONLY to the template instead of couple of lists and dictionary
Remove the following functions: def get_license_text_file_name(self): def get_license_text(self): def get_about_resource_path(self):
1 parent f77596c commit b28a1fe

File tree

3 files changed

+24
-131
lines changed

3 files changed

+24
-131
lines changed

about_code_tool/about.py

Lines changed: 17 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,33 +1002,12 @@ def notice_text(self):
10021002
pass
10031003
return ''
10041004

1005-
1006-
def get_license_text_file_name(self):
1007-
"""
1008-
Return the license_text_file name if the license_text_file field
1009-
exists
1010-
"""
1011-
return self.parsed.get('license_text_file', '')
1012-
1013-
def get_license_text(self):
1014-
"""
1015-
Return the license_text if the license_text field exists.
1016-
"""
1017-
return self.parsed.get('license_text', '')
1018-
10191005
def get_about_name(self):
10201006
"""
10211007
Return the about object's name.
10221008
"""
10231009
return self.parsed.get('name', '')
10241010

1025-
def get_about_resource_path(self):
1026-
"""
1027-
Return the about object's name
1028-
"""
1029-
return self.parsed.get('about_resource_path', '')
1030-
1031-
10321011
class AboutCollector(object):
10331012
"""
10341013
A collection of AboutFile instances.
@@ -1174,13 +1153,8 @@ def generate_attribution(self, template_path=None, limit_to=None):
11741153
print('Template: %(template_name)s not found' % locals())
11751154
return
11761155

1177-
# We only need the fields names and values to render the template
1178-
validated_fields = []
1179-
notice_text = []
1180-
license_key = []
1181-
license_text_list = []
1182-
license_dict = {}
1183-
common_license_dict = {}
1156+
about_object_fields = []
1157+
about_content_dict = {}
11841158
not_exist_components = list(limit_to)
11851159

11861160
# FIXME: this loop and conditional is too complex.
@@ -1198,59 +1172,23 @@ def generate_attribution(self, template_path=None, limit_to=None):
11981172
continue
11991173

12001174
if not limit_to or about_relative_path in limit_to:
1201-
validated_fields.append(about_object.validated_fields)
1202-
notice_text.append(about_object.notice_text())
1203-
license_text_file = about_object.get_license_text_file_name()
1204-
about_resource_path = about_object.get_about_resource_path()
1205-
1206-
if not about_resource_path:
1207-
msg = ('About File: %s - The required field '
1208-
'about_resource_path was not found. '
1209-
'License generation is skipped.'
1210-
% about_object.location)
1211-
err = Error(GENATTRIB, 'about_resource',
1212-
about_object.location, msg)
1213-
self.genattrib_errors.append(err)
1214-
1215-
if license_text_file:
1216-
# Use the about_file_path as the key
1217-
# Check if the key already existed in the dictionary
1218-
# This shouldn't be reached as the 'about_resource_path'
1219-
# should be unique.
1220-
if about_resource_path in license_dict:
1221-
# Raise error if key name are the same but the content
1222-
# are different
1223-
license_text_check = license_dict[about_resource_path]
1224-
1225-
if (unicode(license_text_check)
1226-
!= unicode(about_object.license_text())):
1227-
msg = ('License Name: %s - Same license name '
1228-
'with different content. License '
1229-
'generation is skipped.'
1230-
% license_text_file)
1231-
err = Error(GENATTRIB, 'license_text',
1232-
license_text_file, msg)
1233-
self.genattrib_errors.append(err)
1234-
else:
1235-
lft = unicode(about_object.license_text(),
1175+
about_content_dict = about_object.validated_fields
1176+
# Add information in the dictionary where it does not
1177+
# present in the ABOUT file
1178+
about_content_dict['license_text_content'] = unicode(about_object.license_text(),
12361179
errors='replace')
1237-
license_dict[about_resource_path] = lft
1238-
1239-
if license_text_file in COMMON_LICENSES:
1240-
ltf = unicode(about_object.license_text(),
1241-
errors='replace')
1242-
common_license_dict[license_text_file] = ltf
1243-
elif about_object.get_license_text():
1244-
# We do not need to do anything here as the license_text
1245-
# will be captured directly in the about object.
1246-
pass
1247-
else:
1180+
about_content_dict['notice_text_content'] = about_object.notice_text()
1181+
1182+
# Raise error if no license_text is found
1183+
if not about_content_dict['license_text_content']:
12481184
msg = ('No license_text is found. '
12491185
'License generation is skipped.')
12501186
err = Error(GENATTRIB, 'name',
12511187
about_object.get_about_name(), msg)
12521188
self.genattrib_errors.append(err)
12531189

1190+
about_object_fields.append(about_content_dict)
1191+
12541192
if not_exist_components:
12551193
for component in not_exist_components:
12561194
afp = self.user_provided_path + component.replace('//', '/')
@@ -1260,17 +1198,13 @@ def generate_attribution(self, template_path=None, limit_to=None):
12601198
err = Error(GENATTRIB, 'about_file', component, msg)
12611199
self.genattrib_errors.append(err)
12621200

1263-
# We want to display common_licenses in alphabetical order
1201+
# TODO: Handle the grouping and ordering later
1202+
"""# We want to display common_licenses in alphabetical order
12641203
for key in sorted(common_license_dict.keys()):
12651204
license_key.append(key)
1266-
license_text_list.append(common_license_dict[key])
1267-
1268-
return template.render(about_objects=validated_fields,
1269-
license_keys=license_key,
1270-
license_texts=license_text_list,
1271-
notice_texts=notice_text,
1272-
license_dicts=license_dict,
1273-
common_licenses=COMMON_LICENSES)
1205+
license_text_list.append(common_license_dict[key])"""
1206+
1207+
return template.render(about_objects=about_object_fields)
12741208

12751209
def get_genattrib_errors(self):
12761210
return self.genattrib_errors

about_code_tool/templates/default.html

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -56,50 +56,24 @@ <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.about_resource_path in license_dicts.keys() %}
60-
{% if about_object.dje_license_name %}
61-
<p>This component is licensed under {{about_object.dje_license_name }}.
62-
{% endif %}
59+
{% if about_object.dje_license_name %}
60+
<p>This component is licensed under {{about_object.dje_license_name }}.
6361
{% endif %}
6462
{% if about_object.copyright %}
6563
<pre>{{about_object.copyright}}</pre>
6664
{% endif %}
6765
{% if about_object.notice %}
6866
<pre>{{ about_object.notice }}</pre>
6967
{% elif about_object.notice_file %}
70-
<pre class="component-notice">{{ notice_texts[loop.index0] }}</pre>
68+
<pre class="component-notice">{{ about_object.notice_text_content }}</pre>
7169
{% endif %}
72-
{% if about_object.license_text_file %}
73-
<!-- 'license_text_file' is not a common license if it
74-
doesn't end with '.LICENSE'
75-
-->
76-
{% if not about_object.license_text_file.endswith('.LICENSE') %}
77-
<pre>{{ license_dicts[about_object.about_resource_path]|e }}</pre>
78-
{% elif about_object.about_resource_path in license_dicts.keys() %}
79-
{% if about_object.license_text_file in common_licenses %}
80-
<p>Full text of
81-
<a class="{{ about_object.license_text_file }}" href="#component-license-{{ about_object.license_text_file }}">
82-
{{ about_object.license_text_file }}
83-
</a>
84-
is available at the end of this document.</p>
85-
{% else %}
86-
<pre>{{ license_dicts[about_object.about_resource_path]|e }}</pre>
87-
{% endif %}
88-
{% endif %}
89-
{% elif about_object.license_text %}
90-
<p>{{about_object.license_text | e}}</p>
70+
{% if about_object.license_text_content %}
71+
<pre>{{about_object.license_text_content | e}}</pre>
9172
{% endif %}
9273
</div>
9374
{% endfor %}
9475
<hr>
9576

96-
<h3>Common Licenses Used in This Product</h3>
97-
{% for index in range(license_keys | count) %}
98-
{% if license_keys[index] in common_licenses %}
99-
<h3 id="component-license-{{ license_keys[index] }}">{{ license_keys[index] }}</h3>
100-
<pre>{{ license_texts[index]|e }}</pre>
101-
{% endif %}
102-
{% endfor %}
10377
<h3><a id="End">End</a></h3>
10478
</body>
10579
</html>

about_code_tool/tests/test_about.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,8 @@ def test_remove_blank_lines_and_no_colon_fields(self):
532532
self.assertEqual(expected_warnings[i][1], w.field_value)
533533

534534
def test_generate_attribution(self):
535-
expected = u'version:2.4.3about_resource:httpd-2.4.3.tar.gzname:Apache HTTP Server'
535+
expected = u'notice_text_content:version:2.4.3about_resource:httpd-2.4.3.tar.gz'\
536+
'name:Apache HTTP Serverlicense_text_content:'
536537
about_collector = about.AboutCollector(join(TESTDATA_PATH, 'attrib/attrib.ABOUT'))
537538
result = about_collector.generate_attribution(join(TESTDATA_PATH, 'attrib/test.template'))
538539
self.assertEqual(result, expected)
@@ -577,20 +578,4 @@ def test_notice_text_returns_empty_string_when_ref_file_doesnt_exist(self):
577578
notice_text = about_file.notice_text()
578579
self.assertEqual(notice_text, expected)
579580

580-
def test_get_license_text_file_name(self):
581-
expected = 'httpd.LICENSE'
582-
about_file = about.AboutFile(join(TESTDATA_PATH, 'parser_tests/about_resource_field_present.ABOUT'))
583-
output = about_file.get_license_text_file_name()
584-
self.assertEquals(expected, output)
585-
586-
def test_get_license_text_file_name_no_value(self):
587-
expected = ''
588-
about_file = about.AboutFile(join(TESTDATA_PATH, 'parser_tests/about_file_empty_value_for_dje_license_license_text_file.ABOUT'))
589-
output = about_file.get_license_text_file_name()
590-
self.assertEquals(expected, output)
591581

592-
def test_get_license_text_file_name_no_key(self):
593-
expected = ''
594-
about_file = about.AboutFile(join(TESTDATA_PATH, 'parser_tests/about_file_no_dje_license_no_license_text_file_keys.ABOUT'))
595-
output = about_file.get_license_text_file_name()
596-
self.assertEquals(expected, output)

0 commit comments

Comments
 (0)