Skip to content

Commit 9b40ac4

Browse files
committed
Code enhancement and provide template of license reference
Signed-off-by: Chin Yeung Li <[email protected]>
1 parent 90c91f9 commit 9b40ac4

File tree

3 files changed

+75
-4
lines changed

3 files changed

+75
-4
lines changed

src/attributecode/attrib.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ 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+
117120
rendered = template.render(
118121
abouts=abouts,
119122
common_licenses=COMMON_LICENSES,

src/attributecode/cmd.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,6 @@ 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-
377373
# accept zipped ABOUT files as input
378374
if input.lower().endswith('.zip'):
379375
input = extract_zip(input)
@@ -413,6 +409,8 @@ def attrib(input, output, api_url, api_key, scancode, min_license_score, referen
413409
if errors:
414410
errors = unique(errors)
415411
errors_count = report_errors(errors, quiet, verbose, log_file_loc=output + '-error.log')
412+
msg = 'Attribution generation halted.'
413+
click.echo(msg)
416414
else:
417415
msg = 'No ABOUT file or reference is found from the input. Attribution generation halted.'
418416
click.echo(msg)
@@ -447,6 +445,9 @@ def attrib(input, output, api_url, api_key, scancode, min_license_score, referen
447445
#sys.exit(1)
448446

449447
if abouts:
448+
if not quiet:
449+
print_version()
450+
click.echo('Generating attribution...')
450451
attrib_errors, rendered = generate_attribution_doc(
451452
abouts=abouts,
452453
is_about_input=is_about_input,
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<style type="text/css">
5+
div.additional-license-text-list {display:block}
6+
body {font-family: Helvetica, Arial, sans-serif;}
7+
pre {white-space: pre-wrap;}
8+
li {font-weight: bold;}
9+
#header {font-family: Helvetica; font-style:italic}
10+
</style>
11+
<title>{{ variables['title'] }}</title>
12+
</head>
13+
<body>
14+
<h1>{{ variables['title'] }}</h1>
15+
<pre id="header">
16+
17+
This document lists the open source and third-party components of a [COMPANY NAME] product with additional information regarding licenses, acknowledgments and required copyright notices for these components. This document is for internal [COMPANY NAME] use only.
18+
19+
</pre>
20+
21+
<hr>
22+
<div class="oss-table-of-contents">
23+
{% for license in licenses_list %}
24+
<p>
25+
<a href="#group_{{ loop.index0 }}">{{ license.name }}
26+
</a>
27+
</p>
28+
{% endfor %}
29+
30+
</div>
31+
<hr>
32+
33+
{% for license in licenses_list %}
34+
<div id="group_{{ loop.index0 }}">
35+
<h3>{{ license.name }}</h3>
36+
<p>This product contains the following open source software packages licensed under the terms of the license: {{license.name}}</p>
37+
38+
<div class="oss-component" id="component_{{ loop.index0 }}">
39+
{%for about_object in abouts %}
40+
{% if loop.first %}
41+
{% if license.url %}
42+
<p>License Gallery URL: <a href="{{ license.url }}">{{license.url}}</a> </p>
43+
{% endif %}
44+
{% endif %}
45+
{% if license.key in about_object.license_key.value %}
46+
<li>{{ about_object.name.value }}{% if about_object.version.value %} - Version {{ about_object.version.value }}{% endif %}</li>
47+
{% if about_object.copyright.value %}
48+
<pre>{{about_object.copyright.value}}</pre>
49+
{% endif %}
50+
{% if about_object.notice_file.value %}
51+
<pre>{{ about_object.notice_file.value }}</pre>
52+
{% elif about_object.notice_file.value %}
53+
<pre class="component-notice">{{ about_object.notice_text.value }}</pre>
54+
{% endif %}
55+
{% endif %}
56+
{% if loop.last %}
57+
<pre>{{license.text}}</pre>
58+
{% endif %}
59+
{% endfor %}
60+
</div>
61+
</div>
62+
{% endfor %}
63+
<hr>
64+
<hr>
65+
<h3><a id="End">End</a></h3>
66+
</body>
67+
</html>

0 commit comments

Comments
 (0)