Skip to content

Store extension in CodebaseResource.name #467 #493

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

Merged
merged 1 commit into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ v31.0.0 (next)
to any filters.
https://github.com/nexB/scancode.io/issues/296

- CodebaseResource.name now contains both the bare file name with extension, as
opposed to just the bare file name without extension.

- Using a name stripped from its extension was something that was not used in
other AboutCode project or tools.

https://github.com/nexB/scancode.io/issues/467

v30.2.0 (2021-12-17)
--------------------

Expand Down
25 changes: 25 additions & 0 deletions scanpipe/migrations/0019_auto_20220804_1836.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.0.6 on 2022-08-04 18:36

from django.db import migrations
from django.db.models import F, Q
from django.db.models.functions import Concat


def concat_codebaseresource_name_and_extension(apps, schema_editor):
CodebaseResource = apps.get_model('scanpipe', 'CodebaseResource')
qs = CodebaseResource.objects.filter(
Q(extension__isnull=False) # Has an "extension" value
& ~Q(name__endswith=F("extension")) # "name" do not ends with the "extension"
)
qs.update(name=Concat(F("name"), F("extension")))


class Migration(migrations.Migration):

dependencies = [
('scanpipe', '0018_codebaseresource_tag'),
]

operations = [
migrations.RunPython(concat_codebaseresource_name_and_extension),
]
18 changes: 18 additions & 0 deletions scanpipe/migrations/0020_alter_codebaseresource_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.0.6 on 2022-08-09 17:08

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('scanpipe', '0019_auto_20220804_1836'),
]

operations = [
migrations.AlterField(
model_name='codebaseresource',
name='name',
field=models.CharField(blank=True, help_text='File or directory name of this resource with its extension.', max_length=255),
),
]
2 changes: 1 addition & 1 deletion scanpipe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ class Type(models.TextChoices):
name = models.CharField(
max_length=255,
blank=True,
help_text=_("File or directory name of this resource."),
help_text=_("File or directory name of this resource with its extension."),
)
extension = models.CharField(
max_length=100,
Expand Down
2 changes: 1 addition & 1 deletion scanpipe/pipes/scancode.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def get_resource_info(location):
file_info.update(
{
"type": resource_type,
"name": fileutils.file_base_name(location),
"name": fileutils.file_name(location),
"extension": fileutils.file_extension(location),
}
)
Expand Down
Loading