Skip to content

Commit 4b2d06b

Browse files
committed
Temp commit. Still full of bugs.
1 parent 7ee71ac commit 4b2d06b

File tree

2 files changed

+104
-54
lines changed

2 files changed

+104
-54
lines changed

about_code_tool/about.py

Lines changed: 82 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -402,16 +402,16 @@ def repr_problem(obj):
402402

403403
# Use DJE License Name
404404
COMMON_LICENSES = (
405-
'Apache License 2.0',
406-
'BSD-Modified',
407-
'BSD-Original',
408-
'BSD-Original-UC',
409-
'GNU General Public License 2.0',
410-
'GNU General Public License 3.0',
411-
'GNU Lesser General Public License 2.1',
412-
'Net SNMP License',
413-
'OpenSSL/SSLeay License',
414-
'ZLIB License',
405+
'apache-2.0.LICENSE',
406+
'bsd-new.LICENSE',
407+
'bsd-original.LICENSE',
408+
'bsd-original-uc.LICENSE',
409+
'gpl-2.0.LICENSE',
410+
'gpl-3.0.LICENSE',
411+
'lgpl-2.1.LICENSE',
412+
'net-snmp.LICENSE',
413+
'openssl-ssleay.LICENSE',
414+
'zlib.LICENSE',
415415
)
416416

417417
# Maps lowercase id to standard ids with official case
@@ -1130,6 +1130,8 @@ def generate_attribution(self, template_path=None, limit_to=None):
11301130
license_key = []
11311131
license_text = []
11321132
license_dict = {}
1133+
license_text_file_name = []
1134+
license_text_file_content = []
11331135
not_exist_components = list(limit_to)
11341136

11351137
for about_object in self:
@@ -1146,31 +1148,79 @@ def generate_attribution(self, template_path=None, limit_to=None):
11461148
validated_fields.append(about_object.validated_fields)
11471149
notice_text.append(about_object.notice_text())
11481150
dje_license_name = about_object.get_dje_license_name()
1149-
if dje_license_name:
1150-
if not dje_license_name in license_dict \
1151-
and not dje_license_name == None:
1152-
if about_object.license_text():
1153-
license_dict[about_object.get_dje_license_name()] = unicode(about_object.license_text(), errors='replace')
1154-
else:
1155-
msg = 'Name: %s - license_text does not exist.'\
1151+
license_text_file = about_object.get_license_text_file_name()
1152+
if license_text_file:
1153+
# Check if the 'license_text_file' was generated from the
1154+
# extract_license option. If the 'license_text_file' is
1155+
# not extracted from DJE and is in the original codebase,
1156+
# then, the dict key's name should me 'name' + 'license_text_file'
1157+
# We can check if the 'license_text_file' was generated from
1158+
# extract_license option by checking if it ends with '.LICENSE'
1159+
1160+
# UPDATE: There may be cases that components have the same
1161+
# about name and 'license_text_file' name but different
1162+
# content in the 'license_text_file'.
1163+
# As a result, we need to raise error if this is the case
1164+
if license_text_file in license_dict:
1165+
# Check if the content are the same
1166+
if license_dict[license_text_file] == unicode(about_object.license_text(), errors='replace'):
1167+
msg = 'License Name: %s - Same license name with different content.'\
11561168
' License generation is skipped.'\
1157-
% about_object.get_about_name()
1169+
% license_text_file
11581170
self.genattrib_errors.append(Error(GENATTRIB,\
1159-
'dje_license',\
1160-
dje_license_name, msg))
1161-
elif about_object.get_license_text_file_name():
1162-
if not about_object.get_license_text_file_name() in license_dict:
1163-
if about_object.license_text():
1164-
license_dict[about_object.get_license_text_file_name()] = unicode(about_object.license_text(), errors='replace')
1165-
else:
1166-
msg = 'Name: %s - license_text does not exist.'\
1171+
'license_text',\
1172+
license_text_file, msg))
1173+
break
1174+
1175+
if license_text_file.endswith('.LICENSE'):
1176+
license_dict[license_text_file] = unicode(about_object.license_text(), errors='replace')
1177+
else:
1178+
license_name = about_object.get_about_name() + '_' + license_text_file
1179+
license_dict[license_name] = unicode(about_object.license_text(), errors='replace')
1180+
1181+
"""
1182+
if about_object.license_text():
1183+
license_text_file_name.append(license_text_file)
1184+
license_text_file_content.append(unicode(about_object.license_text(), errors='replace'))
1185+
else:
1186+
msg = 'Name: %s - license_text does not exist.'\
11671187
' License generation is skipped.'\
11681188
% about_object.get_about_name()
1169-
self.genattrib_errors.append(Error(GENATTRIB,\
1170-
'license_text',\
1171-
about_object.get_license_text_file_name(), msg))
1189+
self.genattrib_errors.append(Error(GENATTRIB,\
1190+
'license_text',\
1191+
license_text_file, msg))
1192+
"""
1193+
# Following code are useless as the 'license_text_file' is needed
1194+
# to grab the license for attribution generation.
1195+
# If there is no 'license_text_file' key or value, the tool
1196+
# should throw an error
1197+
"""
1198+
if dje_license_name:
1199+
if not dje_license_name in license_dict \
1200+
and not dje_license_name == None:
1201+
if about_object.license_text():
1202+
license_dict[about_object.get_dje_license_name()] = unicode(about_object.license_text(), errors='replace')
1203+
else:
1204+
msg = 'Name: %s - license_text does not exist.'\
1205+
' License generation is skipped.'\
1206+
% about_object.get_about_name()
1207+
self.genattrib_errors.append(Error(GENATTRIB,\
1208+
'dje_license',\
1209+
dje_license_name, msg))
1210+
elif about_object.get_license_text_file_name():
1211+
if not about_object.get_license_text_file_name() in license_dict:
1212+
if about_object.license_text():
1213+
license_dict[about_object.get_license_text_file_name()] = unicode(about_object.license_text(), errors='replace')
1214+
else:
1215+
msg = 'Name: %s - license_text does not exist.'\
1216+
' License generation is skipped.'\
1217+
% about_object.get_about_name()
1218+
self.genattrib_errors.append(Error(GENATTRIB,\
1219+
'license_text',\
1220+
about_object.get_license_text_file_name(), msg))
1221+
"""
11721222
else:
1173-
msg = 'No dje_license or license_text is found. License generation is skipped.'
1223+
msg = 'No license_text is found. License generation is skipped.'
11741224
self.genattrib_errors.append(Error(GENATTRIB, 'name',\
11751225
about_object.get_about_name(),\
11761226
msg))
@@ -1191,6 +1241,8 @@ def generate_attribution(self, template_path=None, limit_to=None):
11911241
return template.render(about_objects=validated_fields,
11921242
license_keys=license_key,
11931243
license_texts = license_text,
1244+
#license_keys=license_text_file_name,
1245+
#license_texts = license_text_file_content,
11941246
notice_texts=notice_text,
11951247
license_dicts=license_dict,
11961248
common_licenses=COMMON_LICENSES)

about_code_tool/templates/default.html

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ <h1>OPEN SOURCE SOFTWARE INFORMATION</h1>
4141

4242
<div class="oss-table-of-contents">
4343
{% for about_object in about_objects %}
44-
<p><a href="#component_{{ loop.index0 }}">{{ about_object.name }}{% if about_object.version %} {{ about_object.version }}{% endif %}</a></p>
44+
<p><a href="#component_{{ loop.index0 }}">{{ about_object.name }}
45+
{% if about_object.version %}
46+
{{ about_object.version }}
47+
{% endif %}
48+
</a></p>
4549
{% endfor %}
4650
</div>
4751

@@ -52,8 +56,10 @@ <h1>OPEN SOURCE SOFTWARE INFORMATION</h1>
5256
<h3 class="component-name">{{ about_object.name }}
5357
{% if about_object.version %}{{ about_object.version }}{% endif %}
5458
</h3>
55-
{% if about_object.dje_license_name in license_dicts.keys() %}
56-
<p>This component is licensed under {{about_object.dje_license_name }}.
59+
{% if about_object.license_text_file 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 %}
5763
{% endif %}
5864
{% if about_object.copyright %}
5965
<pre>{{about_object.copyright}}</pre>
@@ -63,28 +69,20 @@ <h3 class="component-name">{{ about_object.name }}
6369
{% elif about_object.notice_file %}
6470
<pre class="component-notice">{{ notice_texts[loop.index0] }}</pre>
6571
{% endif %}
66-
{% if about_object.dje_license_name in license_dicts.keys() %}
67-
{% if about_object.dje_license_name in common_licenses %}
68-
<p>Full text of
69-
<a class="{{ about_object.dje_license_name }}" href="#component-license-{{ about_object.dje_license_name }}">
70-
{{ about_object.dje_license_name }}
71-
</a>
72-
is available at the end of this document.</p>
73-
{% else %}
74-
<pre>{{ license_dicts[about_object.dje_license_name]|e }}</pre>
72+
{% if about_object.license_text_file %}
73+
{% if not about_object.license_text_file.endswith('.LICENSE') %}
74+
<pre>{{ license_dicts[about_object.name + '_' + about_object.license_text_file]|e }}</pre>
7575
{% endif %}
76-
{% elif about_object.license_text_file in license_dicts.keys() %}
77-
{% if about_object.dje_license_name in common_licenses %}
78-
<p>
79-
This component is licensed under {{ about_object.dje_license_name }}.
80-
</p>
81-
<p>Full text of
82-
<a class="{{ about_object.license_text_file }}" href="#component-license-{{ about_object.license_text_file }}">
83-
{{ about_object.license_text_file }}
84-
</a>
85-
is available at the end of this document.</p>
86-
{% else %}
87-
<pre>{{ license_dicts[about_object.license_text_file]|e }}</pre>
76+
{% if about_object.license_text_file in license_dicts.keys() %}
77+
{% if about_object.license_text_file in common_licenses %}
78+
<p>Full text of
79+
<a class="{{ about_object.license_text_file }}" href="#component-license-{{ about_object.license_text_file }}">
80+
{{ about_object.license_text_file }}
81+
</a>
82+
is available at the end of this document.</p>
83+
{% else %}
84+
<pre>{{ license_dicts[about_object.license_text_file]|e }}</pre>
85+
{% endif %}
8886
{% endif %}
8987
{% endif %}
9088
</div>

0 commit comments

Comments
 (0)