Skip to content

Commit

Permalink
Merge pull request #23 from aarhusstadsarkiv/dev-matca
Browse files Browse the repository at this point in the history
Version 1.1.3
  • Loading branch information
clausjuhl authored Nov 22, 2023
2 parents 31e3941 + 0535c50 commit 6bf4fde
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions acacore/models/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,32 @@
from .reference_files import Action
from .reference_files import ActionData
from .reference_files import CustomSignature
from .reference_files import IgnoreIfAction
from .reference_files import ManualAction
from .reference_files import TActionType


def _ignore_if(file: "File", ignore_ifs: list[IgnoreIfAction]) -> "File":
for ignore_if in ignore_ifs:
if ignore_if.pixel_total or ignore_if.pixel_width or ignore_if.pixel_height:
width, height = image_size(file.get_absolute_path())
if (
width * height < (ignore_if.pixel_total or 0)
or width < (ignore_if.pixel_width or 0)
or height < (ignore_if.pixel_height or 0)
):
file.action = "ignore"
file.action_data.ignore.reason = ignore_if.reason or file.action_data.ignore.reason
elif file.is_binary and file.size < (ignore_if.binary_size or 0): # noqa: SIM114
file.action = "ignore"
file.action_data.ignore.reason = ignore_if.reason or file.action_data.ignore.reason
elif file.size < (ignore_if.size or 0):
file.action = "ignore"
file.action_data.ignore.reason = ignore_if.reason or file.action_data.ignore.reason

return file


class File(ACABase):
"""
File model containing all information used by the rest of the archival suite of tools.
Expand Down Expand Up @@ -131,23 +153,11 @@ def from_file(
file.action_data = ActionData(manual=ManualAction(reason="Re-identify failure", process=""))
file.puid = file.signature = file.warning = None

if file.action_data and file.action_data.ignore and file.action_data.ignore.ignore_if:
for ignore_if in file.action_data.ignore.ignore_if:
if ignore_if.pixel_total or ignore_if.pixel_width or ignore_if.pixel_height:
width, height = image_size(file.get_absolute_path())
if (
width * height < (ignore_if.pixel_total or 0)
or width < (ignore_if.pixel_width or 0)
or height < (ignore_if.pixel_height or 0)
):
file.action = "ignore"
file.action_data.ignore.reason = ignore_if.reason or file.action_data.ignore.reason
elif file.is_binary and file.size < (ignore_if.binary_size or 0): # noqa: SIM114
file.action = "ignore"
file.action_data.ignore.reason = ignore_if.reason or file.action_data.ignore.reason
elif file.size < (ignore_if.size or 0):
file.action = "ignore"
file.action_data.ignore.reason = ignore_if.reason or file.action_data.ignore.reason
if file.action_data and file.action_data.ignore:
file = _ignore_if(file, file.action_data.ignore.ignore_if)

if file.action != "ignore" and actions and "*" in actions:
file = _ignore_if(file, actions["*"].ignore.ignore_if if actions["*"].ignore else [])

return file

Expand Down Expand Up @@ -235,7 +245,7 @@ def get_action(
if self.is_binary:
identifiers.append("!binary")
if not self.size:
identifiers.append("!empty")
identifiers.insert(0, "!empty")

for identifier in identifiers:
action = actions.get(identifier)
Expand Down

0 comments on commit 6bf4fde

Please sign in to comment.