Skip to content

Commit 525f046

Browse files
authored
Store extension in CodebaseResource.name #467 (#493)
* Create migration on CodebaseResource to append extension to name, if name does not end with extension * Update exptected test results Signed-off-by: Jono Yang <[email protected]>
1 parent f44fd36 commit 525f046

16 files changed

+1589
-1538
lines changed

CHANGELOG.rst

+8
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ v31.0.0 (next)
7373
to any filters.
7474
https://github.com/nexB/scancode.io/issues/296
7575

76+
- CodebaseResource.name now contains both the bare file name with extension, as
77+
opposed to just the bare file name without extension.
78+
79+
- Using a name stripped from its extension was something that was not used in
80+
other AboutCode project or tools.
81+
82+
https://github.com/nexB/scancode.io/issues/467
83+
7684
v30.2.0 (2021-12-17)
7785
--------------------
7886

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Generated by Django 4.0.6 on 2022-08-04 18:36
2+
3+
from django.db import migrations
4+
from django.db.models import F, Q
5+
from django.db.models.functions import Concat
6+
7+
8+
def concat_codebaseresource_name_and_extension(apps, schema_editor):
9+
CodebaseResource = apps.get_model('scanpipe', 'CodebaseResource')
10+
qs = CodebaseResource.objects.filter(
11+
Q(extension__isnull=False) # Has an "extension" value
12+
& ~Q(name__endswith=F("extension")) # "name" do not ends with the "extension"
13+
)
14+
qs.update(name=Concat(F("name"), F("extension")))
15+
16+
17+
class Migration(migrations.Migration):
18+
19+
dependencies = [
20+
('scanpipe', '0018_codebaseresource_tag'),
21+
]
22+
23+
operations = [
24+
migrations.RunPython(concat_codebaseresource_name_and_extension),
25+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 4.0.6 on 2022-08-09 17:08
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('scanpipe', '0019_auto_20220804_1836'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='codebaseresource',
15+
name='name',
16+
field=models.CharField(blank=True, help_text='File or directory name of this resource with its extension.', max_length=255),
17+
),
18+
]

scanpipe/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ class Type(models.TextChoices):
14121412
name = models.CharField(
14131413
max_length=255,
14141414
blank=True,
1415-
help_text=_("File or directory name of this resource."),
1415+
help_text=_("File or directory name of this resource with its extension."),
14161416
)
14171417
extension = models.CharField(
14181418
max_length=100,

scanpipe/pipes/scancode.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def get_resource_info(location):
136136
file_info.update(
137137
{
138138
"type": resource_type,
139-
"name": fileutils.file_base_name(location),
139+
"name": fileutils.file_name(location),
140140
"extension": fileutils.file_extension(location),
141141
}
142142
)

0 commit comments

Comments
 (0)