From 75a744ffe792fd6c677f0460336e5648656a3e46 Mon Sep 17 00:00:00 2001 From: Sarita Singh Date: Sat, 5 Jun 2021 18:33:14 +0530 Subject: [PATCH 1/2] Add emails and urls Add emails and urls in converted_infos. Add holders, authors, emails and urls information in html template. Signed-off-by: Sarita Singh Co-authored-by: Avinal Kumar --- src/formattedcode/output_html.py | 4 +- .../templates/html/template.html | 100 ++++++++++++++++++ 2 files changed, 101 insertions(+), 3 deletions(-) diff --git a/src/formattedcode/output_html.py b/src/formattedcode/output_html.py index 8af9dfac74b..d3187092c6e 100644 --- a/src/formattedcode/output_html.py +++ b/src/formattedcode/output_html.py @@ -155,8 +155,6 @@ def generate_output(results, version, template): LICENSES = 'licenses' COPYRIGHTS = 'copyrights' PACKAGES = 'packages' - URLS = 'urls' - EMAILS = 'emails' # Create a flattened data dict keyed by path for scanned_file in results: @@ -197,7 +195,7 @@ def generate_output(results, version, template): # denormalizing the list here?? converted_infos[path] = {} for name, value in scanned_file.items(): - if name in (LICENSES, PACKAGES, COPYRIGHTS, EMAILS, URLS): + if name in (LICENSES, PACKAGES, COPYRIGHTS): continue converted_infos[path][name] = value diff --git a/src/formattedcode/templates/html/template.html b/src/formattedcode/templates/html/template.html index 484dddffa99..6f97e1dc726 100644 --- a/src/formattedcode/templates/html/template.html +++ b/src/formattedcode/templates/html/template.html @@ -131,6 +131,106 @@ {% endfor %} + + + + + + + + + + + + {% for path, row in files.infos.items() %} + {% if row.holders %} + {% for data in row.holders %} + + + + + + + {% endfor %} + {% endif %} + {% endfor %} + +
Holders
pathholderstartend
{{ path }}{{ data.value }}{{ data.start_line }}{{ data.end_line }}
+ + + + + + + + + + + + {% for path, row in files.infos.items() %} + {% if row.authors %} + {% for data in row.authors %} + + + + + + + {% endfor %} + {% endif %} + {% endfor %} + +
Authors
pathAuthorstartend
{{ path }}{{ data.value }}{{ data.start_line }}{{ data.end_line }}
+ + + + + + + + + + + + {% for path, row in files.infos.items() %} + {% if row.emails %} + {% for data in row.emails %} + + + + + + + {% endfor %} + {% endif %} + {% endfor %} + +
Emails
pathemailstartend
{{ path }}{{ data.email |urlize(target='_blank') }}{{ data.start_line }}{{ data.end_line }}
+ + + + + + + + + + + + {% for path, row in files.infos.items() %} + {% if row.urls %} + {% for data in row.urls %} + + + + + + + {% endfor %} + {% endif %} + {% endfor %} + +
Urls
pathurlstartend
{{ path }}{{ data.url |urlize(target='_blank') }}{{ data.start_line }}{{ data.end_line }}
{% endif %} {% if files.packages %} From b7e35b730223a6422f1ecc373c5b2277636743ea Mon Sep 17 00:00:00 2001 From: Sarita Singh Date: Mon, 7 Jun 2021 00:30:11 +0530 Subject: [PATCH 2/2] Add test for sample HTML template and update changelog Signed-off-by: Sarita Singh Co-authored-by: Avinal Kumar --- CHANGELOG.rst | 3 + .../data/templated/sample-template.html | 104 +++- .../data/templated/simple-expected.html | 251 ++++++++ .../data/templated/tree/expected.html | 557 ++++++++++++++++++ tests/formattedcode/test_output_templated.py | 18 +- 5 files changed, 927 insertions(+), 6 deletions(-) create mode 100644 tests/formattedcode/data/templated/simple-expected.html create mode 100644 tests/formattedcode/data/templated/tree/expected.html diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6680a0ee178..9fa30292f0a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -27,6 +27,9 @@ Important API changes: that contains each package instance that can be aggregating data from multiple manifests for a single package instance. + - The data structure for HTML output has been changed to include emails and urls under the + "infos" object. Now HTML template will output holders, authors, emails, and + urls into separate tables like "licenses" and "copyrights". Copyright detection: ~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/formattedcode/data/templated/sample-template.html b/tests/formattedcode/data/templated/sample-template.html index a8c53d7b3fc..a0c2bc5d96e 100644 --- a/tests/formattedcode/data/templated/sample-template.html +++ b/tests/formattedcode/data/templated/sample-template.html @@ -62,7 +62,7 @@ -

Scanned with ScanCode version {{ version }}

+

Scanned with ScanCode

{% if files.license_copyright %} @@ -104,7 +104,6 @@ - @@ -127,7 +126,6 @@ - @@ -145,6 +143,106 @@ {% endfor %}
Copyrights and Licenses Information
type name extensiondate size sha1 md5{{ row.type }} {{ row.name }} {{ row.extension }}{{ row.date }} {{ row.size }} {{ row.sha1 }} {{ row.md5 }}
+ + + + + + + + + + + + {% for path, row in files.infos.items() %} + {% if row.holders %} + {% for data in row.holders %} + + + + + + + {% endfor %} + {% endif %} + {% endfor %} + +
Holders
pathholderstartend
{{ path }}{{ data.value }}{{ data.start_line }}{{ data.end_line }}
+ + + + + + + + + + + + {% for path, row in files.infos.items() %} + {% if row.authors %} + {% for data in row.authors %} + + + + + + + {% endfor %} + {% endif %} + {% endfor %} + +
Authors
pathAuthorstartend
{{ path }}{{ data.value }}{{ data.start_line }}{{ data.end_line }}
+ + + + + + + + + + + + {% for path, row in files.infos.items() %} + {% if row.emails %} + {% for data in row.emails %} + + + + + + + {% endfor %} + {% endif %} + {% endfor %} + +
Emails
pathemailstartend
{{ path }}{{ data.email |urlize(target='_blank') }}{{ data.start_line }}{{ data.end_line }}
+ + + + + + + + + + + + {% for path, row in files.infos.items() %} + {% if row.urls %} + {% for data in row.urls %} + + + + + + + {% endfor %} + {% endif %} + {% endfor %} + +
Urls
pathurlstartend
{{ path }}{{ data.url |urlize(target='_blank') }}{{ data.start_line }}{{ data.end_line }}
{% endif %} {% if files.packages %} diff --git a/tests/formattedcode/data/templated/simple-expected.html b/tests/formattedcode/data/templated/simple-expected.html new file mode 100644 index 00000000000..85d5e54aea0 --- /dev/null +++ b/tests/formattedcode/data/templated/simple-expected.html @@ -0,0 +1,251 @@ + + + + + + + Custom Template + + + +

Scanned with ScanCode

+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Copyrights and Licenses Information
pathstartendwhatvalue
simple/copyright_acme_c-c.c11copyrightCopyright (c) 2000 ACME, Inc.
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
File Information
pathtypenameextensionsizesha1md5files_countmime_typefile_typeprogramming_languageis_binaryis_textis_archiveis_mediais_sourceis_script
simpledirectorysimple0NoneNoneNoneNoneNoneFalseFalseFalseFalseFalseFalse
simple/copyright_acme_c-c.cfilecopyright_acme_c-c.c.c55e2466d5b764d27fb301ceb439ffb5da22e43ab1dbdf7c572beb4094c2059508fa73c05a4text/plainUTF-8 Unicode text, with no line terminatorsCFalseTrueFalseFalseTrueFalse
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Holders
pathholderstartend
simple/copyright_acme_c-c.cACME, Inc.11
+ + + + + + + + + + + + + + + + + +
Authors
pathAuthorstartend
+ + + + + + + + + + + + + + + + + +
Emails
pathemailstartend
+ + + + + + + + + + + + + + + + + +
Urls
pathurlstartend
+ + + + + + + + + + + + + + + + + + + + +
Package Information
pathtypepackagingprimary_language
+ + + + +
+

Generated with ScanCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + No content created from ScanCode should be considered or used as legal advice. Consult an Attorney for any legal advice. + ScanCode is a free software code scanning tool from nexB Inc. and others. + Visit http://www.nexb.com and https://github.com/nexB/scancode-toolkit/ for support and download. +

+ \ No newline at end of file diff --git a/tests/formattedcode/data/templated/tree/expected.html b/tests/formattedcode/data/templated/tree/expected.html new file mode 100644 index 00000000000..6a79da819f0 --- /dev/null +++ b/tests/formattedcode/data/templated/tree/expected.html @@ -0,0 +1,557 @@ + + + + + + + Custom Template + + + +

Scanned with ScanCode

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Copyrights and Licenses Information
pathstartendwhatvalue
copy1.c11copyrightCopyright (c) 2000 ACME, Inc.
copy2.c11copyrightCopyright (c) 2000 ACME, Inc.
copy3.c11copyrightCopyright (c) 2000 ACME, Inc.
subdir/copy1.c11copyrightCopyright (c) 2000 ACME, Inc.
subdir/copy2.c11copyrightCopyright (c) 2000 ACME, Inc.
subdir/copy3.c11copyrightCopyright (c) 2000 ACME, Inc.
subdir/copy4.c11copyrightCopyright (c) 2000 ACME, Inc.
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
File Information
pathtypenameextensionsizesha1md5files_countmime_typefile_typeprogramming_languageis_binaryis_textis_archiveis_mediais_sourceis_script
copy1.cfilecopy1.c.c913922760d8492eb8f853c10a627f5a73f9eaec6fffc7f53659b7a9db8b6dff0638641778etext/plainUTF-8 Unicode textCFalseTrueFalseFalseTrueFalse
copy2.cfilecopy2.c.c913922760d8492eb8f853c10a627f5a73f9eaec6fffc7f53659b7a9db8b6dff0638641778etext/plainUTF-8 Unicode textCFalseTrueFalseFalseTrueFalse
copy3.cfilecopy3.c.c91c91811eb5fdc7ab440355f9f8d1580e1518b0c2fe999e21c9d7de4d0f943aefbb6f21b99text/plainUTF-8 Unicode textCFalseTrueFalseFalseTrueFalse
subdirdirectorysubdir0NoneNoneNoneNoneNoneFalseFalseFalseFalseFalseFalse
subdir/copy1.cfilecopy1.c.c913922760d8492eb8f853c10a627f5a73f9eaec6fffc7f53659b7a9db8b6dff0638641778etext/plainUTF-8 Unicode textCFalseTrueFalseFalseTrueFalse
subdir/copy2.cfilecopy2.c.c913922760d8492eb8f853c10a627f5a73f9eaec6fffc7f53659b7a9db8b6dff0638641778etext/plainUTF-8 Unicode textCFalseTrueFalseFalseTrueFalse
subdir/copy3.cfilecopy3.c.c84389af7e629a9853056e42b262d5e30bf4579a74f290627a1387288ef77ae7e07946f3ecftext/plainUTF-8 Unicode textCFalseTrueFalseFalseTrueFalse
subdir/copy4.cfilecopy4.c.c9558748872d25374160692f1ed7075d0fe80a544b188e46475db9b1a68f415f6a3544eeb16text/plainUTF-8 Unicode textCFalseTrueFalseFalseTrueFalse
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Holders
pathholderstartend
copy1.cACME, Inc.11
copy2.cACME, Inc.11
copy3.cACME, Inc.11
subdir/copy1.cACME, Inc.11
subdir/copy2.cACME, Inc.11
subdir/copy3.cACME, Inc.11
subdir/copy4.cACME, Inc.11
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Authors
pathAuthorstartend
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Emails
pathemailstartend
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Urls
pathurlstartend
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Package Information
pathtypepackagingprimary_language
+ + + + + + \ No newline at end of file diff --git a/tests/formattedcode/test_output_templated.py b/tests/formattedcode/test_output_templated.py index 6d752941baa..e2a13d881f4 100644 --- a/tests/formattedcode/test_output_templated.py +++ b/tests/formattedcode/test_output_templated.py @@ -114,17 +114,29 @@ def test_custom_format_with_custom_filename_fails_for_directory(): def normalize_quotes(s): return s.replace("'", '"') +@pytest.mark.scanslow +def test_scan_custom_html_output_for_a_directory(): + test_dir = test_env.get_test_loc('templated/tree/scan/') + custom_template = test_env.get_test_loc('templated/sample-template.html') + expected_file = test_env.get_test_loc('templated/tree/expected.html') + result_file = test_env.get_temp_file('html') + args = ['-clip', '--strip-root', '--custom-template', custom_template, '--custom-output', result_file, test_dir] + run_scan_click(args) + results = open(result_file).read() + expected = open(expected_file).read() + assert expected == results @pytest.mark.scanslow def test_custom_format_with_custom_filename(): test_dir = test_env.get_test_loc('templated/simple') custom_template = test_env.get_test_loc('templated/sample-template.html') + expected_file = test_env.get_test_loc('templated/simple-expected.html') result_file = test_env.get_temp_file('html') - args = ['--info', '--custom-template', custom_template, '--custom-output', result_file, test_dir] + args = ['-clip', '--custom-template', custom_template, '--custom-output', result_file, test_dir] run_scan_click(args) results = open(result_file).read() - assert 'Custom Template' in results - assert __version__ in results + expected = open(expected_file).read() + assert expected == results @pytest.mark.scanslow