Skip to content

Commit aa742bc

Browse files
authored
Add is_binary, is_text, and is_archive fields to the CodebaseResource model #75 (#182)
Signed-off-by: tdruez <tdruez@nexb.com>
1 parent 0686df0 commit aa742bc

6 files changed

Lines changed: 41 additions & 5 deletions

File tree

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// Release notes
22
// -------------
33

4+
### unreleased
5+
6+
- Add the is_binary, is_text, and is_archive fields to the CodebaseResource
7+
model.
8+
https://github.com/nexB/scancode.io/issues/75
9+
410
### v21.5.12
511

612
- Adds a new way to fetch docker images using skopeo provided as a
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Generated by Django 3.2.1 on 2021-05-27 12:38
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('scanpipe', '0006_codebaseresource_compliance_alert'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='codebaseresource',
15+
name='is_archive',
16+
field=models.BooleanField(default=False),
17+
),
18+
migrations.AddField(
19+
model_name='codebaseresource',
20+
name='is_binary',
21+
field=models.BooleanField(default=False),
22+
),
23+
migrations.AddField(
24+
model_name='codebaseresource',
25+
name='is_text',
26+
field=models.BooleanField(default=False),
27+
),
28+
]

scanpipe/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,9 @@ class Type(models.TextChoices):
967967
blank=True,
968968
help_text=_("Descriptive file type for this resource."),
969969
)
970+
is_binary = models.BooleanField(default=False)
971+
is_text = models.BooleanField(default=False)
972+
is_archive = models.BooleanField(default=False)
970973

971974
class Compliance(models.TextChoices):
972975
OK = "ok"

scanpipe/pipes/scancode.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ def get_resource_info(location):
101101

102102
# Missing fields on CodebaseResource model returned by `get_file_info`.
103103
unsupported_fields = [
104-
"is_binary",
105-
"is_text",
106-
"is_archive",
107104
"is_media",
108105
"is_source",
109106
"is_script",

scanpipe/tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,6 @@ def test_scanpipe_api_serializer_get_model_serializer(self):
371371

372372
def test_scanpipe_api_serializer_get_serializer_fields(self):
373373
self.assertEqual(28, len(get_serializer_fields(DiscoveredPackage)))
374-
self.assertEqual(21, len(get_serializer_fields(CodebaseResource)))
374+
self.assertEqual(24, len(get_serializer_fields(CodebaseResource)))
375375
with self.assertRaises(LookupError):
376376
get_serializer_fields(None)

scanpipe/tests/test_pipes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,16 @@ def test_scanpipe_pipes_scancode_get_resource_info(self):
221221
"type": CodebaseResource.Type.FILE,
222222
"name": "notice",
223223
"extension": ".NOTICE",
224+
"is_text": True,
224225
"size": 1178,
225226
"sha1": "4bd631df28995c332bf69d9d4f0f74d7ee089598",
226227
"md5": "90cd416fd24df31f608249b77bae80f1",
227228
"sha256": sha256,
228229
"mime_type": "text/plain",
229230
"file_type": "ASCII text",
230231
}
231-
self.assertEqual(expected, scancode.get_resource_info(input_location))
232+
resource_info = scancode.get_resource_info(input_location)
233+
self.assertEqual(expected, resource_info)
232234

233235
def test_scanpipe_pipes_scancode_scan_file(self):
234236
input_location = str(self.data_location / "notice.NOTICE")

0 commit comments

Comments
 (0)