Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An app to detect licenses from the provided input license text #450

Draft
wants to merge 79 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
0a4915a
create an app to detect licenses from input text
lf32 Jun 16, 2022
d5c4018
Merge branch 'main' into lf32-licensetext-devel
lf32 Jun 16, 2022
4c1483a
Merge branch 'main' of nexB/scancode.io into lf32-licensetext-devel
lf32 Jun 17, 2022
9c25575
Improved UI, Changed Scan Path
lf32 Jun 20, 2022
49fe7a5
changed card title from name to short_name
lf32 Jun 20, 2022
cb9de2d
Improved License Input and Details UI #450
lf32 Jun 20, 2022
d2bd8d0
Run License Detection On Text Submission with tempfile #450
lf32 Jun 20, 2022
a113c14
Rename license form, prevent text stripping, temp_file attr update #450
lf32 Jun 22, 2022
0fa7fbb
Detect unknown licenses and return matched text by default #450
lf32 Jun 22, 2022
ea6f4bb
Flush contents of the temfile before passing as an argument #450
lf32 Jun 22, 2022
947faaf
Flush contents of the tempfile before passing as an argument #450
lf32 Jun 22, 2022
dd62121
Merge branch 'lf32-licensetext-devel' of https://github.com/nexB/scan…
lf32 Jun 22, 2022
60af913
Deleted models.py and migrations #450
lf32 Jun 22, 2022
28d0dcf
Added comment related to flushing tempfile #450
lf32 Jun 22, 2022
e46107a
Commenting inside views with pound over docstring #450
lf32 Jun 22, 2022
4468085
Write comments in multiple lines inside views #450
lf32 Jun 22, 2022
8e7c72b
Input text is rendered inside the box over the textarea #450
lf32 Jun 22, 2022
a87ace7
Merge branch 'main' of https://github.com/nexB/scancode.io into lf32-…
lf32 Jun 24, 2022
91ca751
Display form errors, detect licenses for input text file #450
lf32 Jun 27, 2022
cfb7a37
Improve file error response in views #450
lf32 Jul 1, 2022
7eedf84
Moved license summary to details with new UI #450
lf32 Jul 1, 2022
2d4f7f6
Fixed broken short lines #450
lf32 Jul 1, 2022
bbe58d0
New line at the end of the page #450
lf32 Jul 1, 2022
5602a6e
Merge branch 'main' of nexB/scancode.io -> lf32-licensetext-devel
lf32 Jul 2, 2022
a19a762
Ace Editor Restored with improved UI #450
lf32 Jul 4, 2022
b77976d
Highlight and scroll down to matched text #450
lf32 Jul 5, 2022
0333932
Close all cards while opening a new one #450
lf32 Jul 5, 2022
b206145
Removed details option in the view #450
lf32 Jul 7, 2022
b53e45c
Restore details tab with matched text #450
lf32 Jul 16, 2022
fe66aa2
Merge remote-tracking branch 'origin' into lf32-licensetext-devel
lf32 Jul 23, 2022
ce9b294
Merge remote-tracking branch 'origin' into lf32-licensetext-devel
lf32 Jul 25, 2022
1293066
Highlight text with colors #450
lf32 Jul 28, 2022
dddb4ad
Merge branch 'main' of https://github.com/nexB/scancode.io into lf32-…
lf32 Jul 28, 2022
a6b34de
Fix failing text for `make valid` #450
lf32 Jul 28, 2022
1bdf9d1
Fix failing test for `make valid` #450
lf32 Jul 28, 2022
ab56010
Merge branch 'main' of into lf32-licensetext-devel
lf32 Jul 29, 2022
fda2356
Merge branch 'main' into lf32-licensetext-devel
lf32 Aug 4, 2022
b82d1a2
Merge branch 'main' into lf32-licensetext-devel
lf32 Aug 6, 2022
67462c5
Testing out new UI to match the projects page #450
lf32 Aug 7, 2022
0f675ff
Add match_text tests to scantext #450
lf32 Aug 9, 2022
76e8a03
Make scancode match text test pass
pombredanne Aug 9, 2022
8727cb7
Add list of matches to Token
pombredanne Aug 9, 2022
04b8d21
Merge branch 'main' into lf32-licensetext-devel
lf32 Aug 11, 2022
3f7b640
Add all detected values into the table #450
lf32 Aug 12, 2022
658df1f
Add details page to view matched license details #450
lf32 Aug 17, 2022
8edf207
Add a mini licenses file to test for development #450
lf32 Aug 17, 2022
787133a
Move import of Token to top #450
lf32 Aug 17, 2022
4a08ea9
Add `license_chart_data` to render charts #450
lf32 Aug 17, 2022
32c3931
Add eye friendly green color to match highlights #450
lf32 Aug 17, 2022
4442f7c
Highlight all detected licenses in one match #450
lf32 Aug 18, 2022
840b395
Fix tests by running make valid
lf32 Aug 18, 2022
60683d0
Match token args correction #450
lf32 Aug 18, 2022
68205f8
Add hyperlinks to urls in details #450
lf32 Aug 19, 2022
968c538
Update details, Improve UI #450
lf32 Aug 25, 2022
3108089
Merge v31.0.0 of 'main' into lf32-licensetext-devel
lf32 Aug 27, 2022
6cd0243
Ace editor upgraded from v1.4.12 to v1.9.5
lf32 Aug 27, 2022
65277f1
Improve details, highlights and tests
lf32 Aug 31, 2022
bdae386
Add report functionality to the summary
lf32 Sep 2, 2022
81d1c6d
Add new user interface and cleanup the old one
lf32 Sep 6, 2022
bd15385
Merge branch 'main' into lf32-licensetext-devel
lf32 Sep 7, 2022
5c88367
Remove unused tests and validate code format #450
lf32 Sep 7, 2022
57a1d62
Indent html, handle input, fix modules & tests#450
lf32 Sep 18, 2022
3def711
Add more licenses, highlight text properly #450
lf32 Sep 19, 2022
ebcb6e2
Set cursor style to help, add token attr desc #450
lf32 Sep 19, 2022
cda3a40
Connect left and right part of ui #450
lf32 Sep 21, 2022
9c404cc
Set predefined colors to 3 #450
lf32 Sep 21, 2022
6fab923
Add more colors & new test licenses
lf32 Sep 26, 2022
4760050
Add highlight color and get rid of modal #450
lf32 Sep 28, 2022
e3281f7
Merge branch 'main' into lf32-licensetext-devel
lf32 Oct 11, 2022
45acd64
Fix failing tests #450
lf32 Oct 17, 2022
b719948
Fix width for dropdown #450
lf32 Oct 17, 2022
e3c8d79
Merge branch 'main' into lf32-licensetext-devel
lf32 Oct 21, 2022
3bca8e7
Merge branch 'main' into lf32-licensetext-devel
lf32 Nov 23, 2022
a165bd1
Merge branch 'main' into lf32-licensetext-devel
lf32 Dec 10, 2022
73a6571
Merge branch 'main' into lf32-licensetext-devel
lf32 Jan 25, 2023
dd2e8ab
Write input file either in chunks or text #450
lf32 Feb 5, 2023
5c30510
Move scan to utility dropdown #450
lf32 Feb 5, 2023
a5fa2b4
Merge branch 'main' into lf32-licensetext-devel
lf32 Feb 27, 2023
9787f44
(tests) code format is vaildated #450
lf32 Feb 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion scancodeio/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=[".localhost", "127.0.0.1", "[::1]"])

# SECURITY WARNING: don't run with debug turned on in production
DEBUG = env.bool("SCANCODEIO_DEBUG", default=False)
DEBUG = env.bool("SCANCODEIO_DEBUG", default=True)

SCANCODEIO_REQUIRE_AUTHENTICATION = env.bool(
"SCANCODEIO_REQUIRE_AUTHENTICATION", default=False
Expand Down Expand Up @@ -78,6 +78,7 @@
# Local apps
# Must come before Third-party apps for proper templates override
"scanpipe",
"scantext",
# Django built-in
"django.contrib.auth",
"django.contrib.contenttypes",
Expand Down
Binary file added scancodeio/static/favicon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions scancodeio/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
path("admin/", admin.site.urls),
path("api/", include(api_router.urls)),
path("license/", include(licenses.urls)),
path("scan/", include("scantext.urls")),
path("", include("scanpipe.urls")),
path("", RedirectView.as_view(url="project/")),
]
1 change: 1 addition & 0 deletions scanpipe/templates/scanpipe/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}ScanCode.io{% endblock %}</title>
<link rel="icon" href="{% static 'favicon.ico' %}" type="image/x-icon"/>
<link rel="stylesheet" href="{% static 'bulma-0.9.2.min.css' %}" crossorigin="anonymous">
<link rel="stylesheet" href="{% static 'highlight-10.6.0.css' %}" crossorigin="anonymous">
<style>
Expand Down
21 changes: 21 additions & 0 deletions scantext/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# SPDX-License-Identifier: Apache-2.0
#
# http://nexb.com and https://github.com/nexB/scancode.io
# The ScanCode.io software is licensed under the Apache License version 2.0.
# Data generated with ScanCode.io is provided as-is without warranties.
# ScanCode is a trademark of nexB Inc.
#
# You may not use this software except in compliance with the License.
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
#
# Data Generated with ScanCode.io is provided on an "AS IS" BASIS, WITHOUT WARRANTIES
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
# ScanCode.io should be considered or used as legal advice. Consult an Attorney
# for any legal advice.
#
# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
# Visit https://github.com/nexB/scancode.io for support and download.
25 changes: 25 additions & 0 deletions scantext/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# SPDX-License-Identifier: Apache-2.0
#
# http://nexb.com and https://github.com/nexB/scancode.io
# The ScanCode.io software is licensed under the Apache License version 2.0.
# Data generated with ScanCode.io is provided as-is without warranties.
# ScanCode is a trademark of nexB Inc.
#
# You may not use this software except in compliance with the License.
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
#
# Data Generated with ScanCode.io is provided on an "AS IS" BASIS, WITHOUT WARRANTIES
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
# ScanCode.io should be considered or used as legal advice. Consult an Attorney
# for any legal advice.
#
# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
# Visit https://github.com/nexB/scancode.io for support and download.

from django.contrib import admin

# Register your models here.
28 changes: 28 additions & 0 deletions scantext/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# SPDX-License-Identifier: Apache-2.0
#
# http://nexb.com and https://github.com/nexB/scancode.io
# The ScanCode.io software is licensed under the Apache License version 2.0.
# Data generated with ScanCode.io is provided as-is without warranties.
# ScanCode is a trademark of nexB Inc.
#
# You may not use this software except in compliance with the License.
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
#
# Data Generated with ScanCode.io is provided on an "AS IS" BASIS, WITHOUT WARRANTIES
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
# ScanCode.io should be considered or used as legal advice. Consult an Attorney
# for any legal advice.
#
# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
# Visit https://github.com/nexB/scancode.io for support and download.

from django.apps import AppConfig


class ScantextConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "scantext"
64 changes: 64 additions & 0 deletions scantext/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# SPDX-License-Identifier: Apache-2.0
#
# http://nexb.com and https://github.com/nexB/scancode.io
# The ScanCode.io software is licensed under the Apache License version 2.0.
# Data generated with ScanCode.io is provided as-is without warranties.
# ScanCode is a trademark of nexB Inc.
#
# You may not use this software except in compliance with the License.
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
#
# Data Generated with ScanCode.io is provided on an "AS IS" BASIS, WITHOUT WARRANTIES
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
# ScanCode.io should be considered or used as legal advice. Consult an Attorney
# for any legal advice.
#
# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
# Visit https://github.com/nexB/scancode.io for support and download.

from django import forms


class EditorForm(forms.Form):
input_text = forms.CharField(
widget=forms.Textarea(
attrs={
"rows": 30,
"class": "textarea has-fixed-size",
"placeholder": "Paste your license text here.",
}
),
required=True,
)

# def clean_input_text(self):
# input_text = self.cleaned_data.get("input_text")
# return " ".join(input_text.split())

# def save(self, *args, **kwargs):
# license = super().save(*args, **kwargs)
# self.handle_input(license)
# return license

# class Media:
# js = ("add-inputs.js",)

# def handle_inputs(self, project):
# input_file = self.files.getlist("input_files")
# input_text = self.cleaned_data.get("input_text")
# print(input_text)
# if input_file:
# license.add_uploads(input_file)
# elif input_text:
# license.add_license(input_text)

# input_files = forms.FileField(
# required=False,
# widget=forms.ClearableFileInput(
# attrs={"class": "file-input", "multiple": False},
# ),
# )
Empty file added scantext/migrations/__init__.py
Empty file.
25 changes: 25 additions & 0 deletions scantext/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# SPDX-License-Identifier: Apache-2.0
#
# http://nexb.com and https://github.com/nexB/scancode.io
# The ScanCode.io software is licensed under the Apache License version 2.0.
# Data generated with ScanCode.io is provided as-is without warranties.
# ScanCode is a trademark of nexB Inc.
#
# You may not use this software except in compliance with the License.
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
#
# Data Generated with ScanCode.io is provided on an "AS IS" BASIS, WITHOUT WARRANTIES
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
# ScanCode.io should be considered or used as legal advice. Consult an Attorney
# for any legal advice.
#
# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
# Visit https://github.com/nexB/scancode.io for support and download.

from django.db import models

# Create your models here.
35 changes: 35 additions & 0 deletions scantext/templates/scantext/includes/license_summary_level.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{% load humanize %}
<nav class="level is-mobile">
<div class="level-item has-text-centered">
<div>
<p class="heading">Percentage Of License Text</p>
<p class="title">
<span>
{{ expr.percentage_of_license_text }}
</span>
</p>
</div>
</div>
<div class="level-item has-text-centered">
<div>
<p class="heading">License Expressions</p>
<p class="title">
<span>
{{ expr.license_expressions | length }}

</span>
</p>
</div>
</div>
<div class="level-item has-text-centered">
<div>
<p class="heading">Licenses</p>
<p class="title">
<span>
{{ expr.licenses | length }}

</span>
</p>
</div>
</div>
</nav>
107 changes: 107 additions & 0 deletions scantext/templates/scantext/license_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{% extends 'scanpipe/base.html' %}
{% load static humanize %}


{% block extrahead %}
<link rel="stylesheet" href="{% static 'billboard-3.0.1-datalab.min.css' %}" crossorigin="anonymous" />
{% endblock %}

{% block content %}
<div class="container is-widescreen">
{% include 'scanpipe/includes/navbar_header.html' %}
<div class="mx-5 mb-2">{% include 'scanpipe/includes/messages.html' %}</div>

<section class="section pt-0">
<div class="is-flex is-justify-content-space-between mb-2">
<div class="mb-2">
<h1 class="title is-4">License Detection Summary</h1>
</div>
<div>
<a href="{% url 'license_scan' %}" class="button is-link">
Scan Again
</a>
</div>
</div>
</section>

<hr class="mx-5">
{% include "scantext/includes/license_summary_level.html" with expr=expr %}

<hr class="mx-5">

<div class="columns">
<div class="column is-half">
<p class="title is-4">Input License Text</p>
<div class="box">
{% for line in text %}
<p>{{line}}</p>
{% endfor %}
</div>
</div>
<div class="column is-half">
<p class="title is-4">Detected License Errors</p>

{% for license in expr.licenses %}

<div class="card">
<div class="card-header">
<div class="card-header-title">
<a class="" href="{{license.homepage_url}}" title="{{license.short_name}}">{{license.name| center:"15"}}</a>
<p class="tag is-6 mx-1 is-light
{% if license.score == 100 %}
is-success
{% else %}
is-warning
{% endif %}
">{{license.score}}</p>
<p class="tag is-6 mx-1 is-light is-info">
{% if license.start_line == license.end_line %}
Line {{license.start_line}}
{% else %}
Lines {{license.start_line}} - {{license.end_line}}
{% endif %}
</p>
<p class="tag is-6 mx-1 is-light is-primary">{{license.category}}</p>
</div>
<p class="card-header-icon" aria-label="more options">
<span class="icon">
<i class="fas fa-angle-down" aria-hidden="true"></i>
</span>
</p>
</div>
{% if license.score < 100 %}
<div class="card-content">
<p class="subtitle is-5">Recommended License</p>
<p class="content">{{license}}</p>
</div>
{% endif %}
</div>
<br>
{% endfor %}
</div>
</div>
</div>
{% endblock %}

{% block scripts %}
<script type="text/javascript">
const cards = document.querySelectorAll('.card')

// const cardsicons = document.querySelectorAll('.card-header-icon')
// cardsicons.forEach(icon => {
// icon.addEventListener('click', (e, index) => {
// e.preventDefault();
// removeActiveCards();
// console.log(e)
// console.log(index)
// icon.parentNode.parentNode.parentNode.querySelector('.card-content').style.display="visible"
// })
// })

// function removeActiveCards() {
// cards.forEach(card => {
// card.parentNode.parentNode.parentNode.querySelector('.card-content').style.display="none"
// })
// }
</script>
{% endblock %}
Loading