Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Merlijn Wajer
Python Derivermodule
Commits
bb36b373
Commit
bb36b373
authored
Mar 12, 2022
by
Merlijn Wajer
Browse files
imagestack: add validate_imagestack
parent
5739edf5
Changes
1
Hide whitespace changes
Inline
Side-by-side
derivermodule/imagestack.py
View file @
bb36b373
from
pathlib
import
Path
from
os.path
import
splitext
from
subprocess
import
check_call
from
time
import
time
import
zipfile
import
tarfile
from
.logger
import
logger
def
get_imagestack_info
(
task_info
):
...
...
@@ -79,6 +82,7 @@ def unpack_and_validate_imagestack(imagestack_path, imagestack_info, dst):
return
str
(
img_dir
),
image_count
def
iterate_imagestack
(
imagestack_path
,
imagestack_info
,
sort
=
True
):
"""Unpack and validate an imagestack
...
...
@@ -140,3 +144,18 @@ def iterate_imagestack(imagestack_path, imagestack_info, sort=True):
raise
ValueError
(
'Cannot extract archive_type %s'
%
imagestack_info
[
'archive_type'
])
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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment