Skip to content

Commit

Permalink
Ensure files are extracted to subdir
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvarner committed May 1, 2024
1 parent ca34117 commit f001e90
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
22 changes: 11 additions & 11 deletions readux_ingest_ecds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ class Local(IngestAbstractModel):
class Meta:
verbose_name_plural = 'Local'

# @property
# def tmp_directory(self):
# return os.path.join(
# settings.INGEST_TMP_DIR,
# self.manifest.pid
# )
@property
def tmp_directory(self):
return os.path.join(
settings.INGEST_TMP_DIR,
str(self.id),
)

@property
def ocr_directory(self):
Expand Down Expand Up @@ -120,14 +120,14 @@ def unzip_bundle(self):
continue

file_path = os.path.join(
settings.INGEST_TMP_DIR,
self.tmp_directory,
file_name
)

if is_image(file_name):
zip_ref.extract(
member=member,
path=settings.INGEST_TMP_DIR
path=os.path.join(self.tmp_directory)
)

file_to_process = move_image_file(self, file_path)
Expand All @@ -137,7 +137,7 @@ def unzip_bundle(self):
elif is_ocr(file_name):
zip_ref.extract(
member=member,
path=settings.INGEST_TMP_DIR
path=self.tmp_directory
)

move_ocr_file(self, file_path)
Expand All @@ -161,12 +161,12 @@ def open_metadata(self):

if os.path.splitext(os.path.basename(file_name))[0] == 'metadata':
metadata_file = os.path.join(
settings.INGEST_TMP_DIR,
self.tmp_directory,
file_name
)
zip_ref.extract(
member=member,
path=settings.INGEST_TMP_DIR
path=self.tmp_directory
)

if metadata_file is None or os.path.exists(metadata_file) is False:
Expand Down
18 changes: 18 additions & 0 deletions test_app/iiif/migrations/0005_canvas_resource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.23 on 2024-05-01 12:37

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('iiif', '0004_canvas_image_server'),
]

operations = [
migrations.AddField(
model_name='canvas',
name='resource',
field=models.TextField(blank=True, null=True),
),
]
1 change: 1 addition & 0 deletions test_app/iiif/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Canvas(models.Model):
# TODO: move this to the manifest level.
default_ocr = models.CharField(max_length=30, choices=preferred_ocr, default="word")
image_server = models.ForeignKey(ImageServer, on_delete=models.DO_NOTHING, null=True)
resource = models.TextField(blank=True, null=True)

def before_save(self):
return True
Expand Down
4 changes: 2 additions & 2 deletions test_app/tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def setUp(self):
conn = boto3.resource('s3', region_name='us-east-1')
conn.create_bucket(Bucket=settings.INGEST_TRIGGER_BUCKET)

def teardown_class():
rmtree(settings.INGEST_TMP_DIR, ignore_errors=True)
# def teardown_class():
# rmtree(settings.INGEST_TMP_DIR, ignore_errors=True)

def mock_local(self, bundle, with_manifest=False, metadata={}, from_bulk=False):
# Note, I tried to use the factory here, but could not get it to override the file for bundle.
Expand Down

0 comments on commit f001e90

Please sign in to comment.