Commit bb36b373 authored by Merlijn Wajer's avatar Merlijn Wajer
Browse files

imagestack: add validate_imagestack

parent 5739edf5
from pathlib import Path from pathlib import Path
from os.path import splitext
from subprocess import check_call from subprocess import check_call
from time import time from time import time
import zipfile import zipfile
import tarfile import tarfile
from .logger import logger from .logger import logger
def get_imagestack_info(task_info): def get_imagestack_info(task_info):
...@@ -79,6 +82,7 @@ def unpack_and_validate_imagestack(imagestack_path, imagestack_info, dst): ...@@ -79,6 +82,7 @@ def unpack_and_validate_imagestack(imagestack_path, imagestack_info, dst):
return str(img_dir), image_count return str(img_dir), image_count
def iterate_imagestack(imagestack_path, imagestack_info, sort=True): def iterate_imagestack(imagestack_path, imagestack_info, sort=True):
"""Unpack and validate an imagestack """Unpack and validate an imagestack
...@@ -140,3 +144,18 @@ def iterate_imagestack(imagestack_path, imagestack_info, sort=True): ...@@ -140,3 +144,18 @@ def iterate_imagestack(imagestack_path, imagestack_info, sort=True):
raise ValueError('Cannot extract archive_type %s' % imagestack_info['archive_type']) raise ValueError('Cannot extract archive_type %s' % imagestack_info['archive_type'])
return return
def validate_imagestack(imagestack_path, imagestack_info):
image_count = 0
for img_path, _ in iterate_imagestack(imagestack_path, imagestack_info):
_, file_extension = splitext(img_path)
if file_extension[1:] == imagestack_info['image_type']:
image_count += 1
if image_count == 0:
raise Exception('Imagestack contains no valid images.')
return
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment