Skip to content

Commit a0915ce

Browse files
committed
Create a temp function to handle multiple 'license_text_file'
1 parent b28a1fe commit a0915ce

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

about_code_tool/about.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import csv
2121
from datetime import datetime
2222
from email.parser import HeaderParser
23+
from os.path import dirname, join
2324
import errno
2425
import httplib
2526
import logging
@@ -749,7 +750,6 @@ def validate_about_resource_exist(self):
749750
self.errors.append(Error(FILE, about_resource,
750751
self.about_resource,
751752
'File does not exist.'))
752-
753753
self._save_location(about_resource, self.about_resource)
754754

755755
def validate_file_field_exists(self, field_name, file_path):
@@ -974,6 +974,20 @@ def duplicate_file_names_when_lowercased(file_location):
974974
names.append(name)
975975
return names
976976

977+
def tmp_get_license_text(self):
978+
# TODO: This is a temp fix for handling multiple 'license_text_file'
979+
# The code should get the license text from the def license_text(self),
980+
# not this function.
981+
license_text = ""
982+
licenses = self.parsed.get('license_text_file', '')
983+
license_list = licenses.split('\n ')
984+
for lic in license_list:
985+
location = join(dirname(self.location), lic)
986+
with open(location, 'rU') as f:
987+
license_text += f.read()
988+
license_text += '\n\n\n\n\n\n'
989+
return license_text
990+
977991
def license_text(self):
978992
"""
979993
Return the license text if the license_text_file field exists and the
@@ -1175,12 +1189,19 @@ def generate_attribution(self, template_path=None, limit_to=None):
11751189
about_content_dict = about_object.validated_fields
11761190
# Add information in the dictionary where it does not
11771191
# present in the ABOUT file
1178-
about_content_dict['license_text_content'] = unicode(about_object.license_text(),
1192+
about_content_dict['license_text'] = unicode(about_object.license_text(),
1193+
errors='replace')
1194+
about_content_dict['notice_text'] = about_object.notice_text()
1195+
1196+
# FIXME: The following is a tmp code to handle multiple
1197+
# 'license_text_file' in the input
1198+
for k in about_content_dict:
1199+
if '\n' in about_content_dict[k] and k == 'license_text_file':
1200+
about_content_dict['license_text'] = unicode(about_object.tmp_get_license_text(),
11791201
errors='replace')
1180-
about_content_dict['notice_text_content'] = about_object.notice_text()
11811202

11821203
# Raise error if no license_text is found
1183-
if not about_content_dict['license_text_content']:
1204+
if not about_content_dict['license_text']:
11841205
msg = ('No license_text is found. '
11851206
'License generation is skipped.')
11861207
err = Error(GENATTRIB, 'name',

about_code_tool/templates/default.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ <h3 class="component-name">{{ about_object.name }}
6565
{% if about_object.notice %}
6666
<pre>{{ about_object.notice }}</pre>
6767
{% elif about_object.notice_file %}
68-
<pre class="component-notice">{{ about_object.notice_text_content }}</pre>
68+
<pre class="component-notice">{{ about_object.notice_text }}</pre>
6969
{% endif %}
70-
{% if about_object.license_text_content %}
71-
<pre>{{about_object.license_text_content | e}}</pre>
70+
{% if about_object.license_text %}
71+
<pre>{{about_object.license_text | e}}</pre>
7272
{% endif %}
7373
</div>
7474
{% endfor %}

about_code_tool/tests/test_about.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +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'notice_text_content:version:2.4.3about_resource:httpd-2.4.3.tar.gz'\
536-
'name:Apache HTTP Serverlicense_text_content:'
535+
expected = u'notice_text:version:2.4.3about_resource:httpd-2.4.3.tar.gz'\
536+
'name:Apache HTTP Serverlicense_text:'
537537
about_collector = about.AboutCollector(join(TESTDATA_PATH, 'attrib/attrib.ABOUT'))
538538
result = about_collector.generate_attribution(join(TESTDATA_PATH, 'attrib/test.template'))
539539
self.assertEqual(result, expected)

0 commit comments

Comments
 (0)