Skip to content

Commit 9e3c3ad

Browse files
committed
Update default template and code enhancement
Signed-off-by: Chin Yeung Li <[email protected]>
1 parent 9b40ac4 commit 9e3c3ad

File tree

4 files changed

+49
-45
lines changed

4 files changed

+49
-45
lines changed

src/attributecode/attrib.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,6 @@ def generate(abouts, is_about_input, license_dict, min_license_score, template=N
114114
# Add the license name expression string into the about object as a list
115115
about.license_name_expression = lic_name_expression
116116

117-
# Sort the license object by key
118-
licenses_list = sorted(licenses_list, key=lambda x: x.key)
119-
120117
rendered = template.render(
121118
abouts=abouts,
122119
common_licenses=COMMON_LICENSES,

src/attributecode/cmd.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,10 @@ def attrib(input, output, api_url, api_key, scancode, min_license_score, referen
370370
license_dict = {}
371371
errors = []
372372

373+
if not quiet:
374+
print_version()
375+
click.echo('Generating attribution...')
376+
373377
# accept zipped ABOUT files as input
374378
if input.lower().endswith('.zip'):
375379
input = extract_zip(input)
@@ -409,8 +413,6 @@ def attrib(input, output, api_url, api_key, scancode, min_license_score, referen
409413
if errors:
410414
errors = unique(errors)
411415
errors_count = report_errors(errors, quiet, verbose, log_file_loc=output + '-error.log')
412-
msg = 'Attribution generation halted.'
413-
click.echo(msg)
414416
else:
415417
msg = 'No ABOUT file or reference is found from the input. Attribution generation halted.'
416418
click.echo(msg)
@@ -445,9 +447,6 @@ def attrib(input, output, api_url, api_key, scancode, min_license_score, referen
445447
#sys.exit(1)
446448

447449
if abouts:
448-
if not quiet:
449-
print_version()
450-
click.echo('Generating attribution...')
451450
attrib_errors, rendered = generate_attribution_doc(
452451
abouts=abouts,
453452
is_about_input=is_about_input,

src/attributecode/model.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,10 +1576,10 @@ def pre_process_and_fetch_license_dict(abouts, api_url=None, api_key=None, scanc
15761576
converted_lic_exp = about.license_expressions.value.strip("[").strip("]").replace('\'','').replace(' ','')
15771577
# Convert the updated lic_exp string to list
15781578
converted_lic_list = converted_lic_exp.split(',')
1579-
for lic in converted_lic_list:
1580-
# Only keep unique license keys
1581-
if not lic in lic_list:
1582-
lic_list.append(lic)
1579+
for lic in converted_lic_list:
1580+
# Only keep unique license keys
1581+
if not lic in lic_list:
1582+
lic_list.append(lic)
15831583
lic_exp = " AND ".join(lic_list)
15841584
about.license_expression.value = lic_exp
15851585
about.license_expression.present = True

templates/default_html.template

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,48 +32,56 @@ Read the JSON file to see what information can be extracted from the licenses.
3232

3333
{% for about_object in abouts %}
3434
<div class="oss-component" id="component_{{ loop.index0 }}">
35-
<h3 class="component-name">{{ about_object.name.value }} {% if about_object.version.value %}{{ about_object.version.value }}{% endif %} </h3>
36-
{% if about_object.license_expression.value %}
37-
<p>This component is licensed under {{ about_object.license_expression.value }}</p>
38-
{% endif %}
39-
{% if about_object.copyright.value %}
40-
<pre>
41-
{{about_object.copyright.value}}
35+
<h3 class="component-name">{{ about_object.name.value }} {% if about_object.version.value %}{{ about_object.version.value }}{% endif %} </h3>
36+
{% if about_object.license_expression.value %}
37+
<p>This component is licensed under {{ about_object.license_expression.value }}</p>
38+
{% endif %}
39+
{% if about_object.copyright.value %}
40+
<pre>
41+
{{about_object.copyright.value}}
42+
</pre>
43+
{% endif %}
44+
{% if about_object.notice_file.value %}
45+
{% for notice in about_object.notice_file.value %}
46+
<pre class="component-notice">
47+
{{ about_object.notice_file.value[notice] }}
4248
</pre>
43-
{% endif %}
44-
{% if about_object.notice_file.value %}
45-
{% for notice in about_object.notice_file.value %}
46-
<pre class="component-notice">
47-
{{ about_object.notice_file.value[notice] }}
48-
</pre>
49+
{% endfor %}
50+
{% endif %}
51+
{% if about_object.license_key.value %}
52+
{% if about_object.license_file.value %}
53+
{% for lic_file_name in about_object.license_file.value %}
54+
{% for license in licenses_list %}
55+
{% if license.filename == lic_file_name %}
56+
{% if not license.key in common_licenses %}
57+
<pre> {{ license.text | e}} </pre>
58+
{% endif %}
59+
{% endif %}
60+
{% endfor %}
4961
{% endfor %}
50-
{% endif %}
51-
{% if about_object.license_key.value %}
62+
{% else %}
5263
{% for license_key in about_object.license_key.value %}
5364
{% if license_key in common_licenses %}
5465
<p>Full text of <a class="{{ license_key }}" href="#component-license-{{ license_key }}"> {{ license_key }}</a> is available at the end of this document.</p>
55-
{% endif %}
56-
{% endfor %}
57-
{% if about_object.license_file.value %}
58-
{% for lic_file_name in about_object.license_file.value %}
66+
{% else %}
5967
{% for license in licenses_list %}
60-
{% if license.filename == lic_file_name %}
61-
{% if not license.key in common_licenses %}
62-
<pre> {{ license.text | e}} </pre>
63-
{% endif %}
68+
{% if license_key == license.key %}
69+
<h3 id="component-license-{{ license.key }}">{{ license.key }}</h3>
70+
<pre> {{ license.text | e }} </pre>
6471
{% endif %}
6572
{% endfor %}
66-
{% endfor %}
67-
{% endif %}
68-
{% else %}
69-
{% if about_object.license_file.value %}
70-
{% for lic_file_name in about_object.license_file.value %}
71-
{% if about_object.license_file.value[lic_file_name] %}
72-
<pre> {{ about_object.license_file.value[lic_file_name] | e}} </pre>
73-
{% endif %}
74-
{% endfor %}
75-
{% endif %}
73+
{% endif %}
74+
{% endfor %}
7675
{% endif %}
76+
{% else %}
77+
{% if about_object.license_file.value %}
78+
{% for lic_file_name in about_object.license_file.value %}
79+
{% if about_object.license_file.value[lic_file_name] %}
80+
<pre> {{ about_object.license_file.value[lic_file_name] | e}} </pre>
81+
{% endif %}
82+
{% endfor %}
83+
{% endif %}
84+
{% endif %}
7785
</div>
7886
{% endfor %}
7987

0 commit comments

Comments
 (0)