Skip to content

Commit

Permalink
Merge pull request #671 from aarhusstadsarkiv/dev-matca
Browse files Browse the repository at this point in the history
Version 1.0.4
  • Loading branch information
MatteoCampinoti94 authored Nov 21, 2023
2 parents d10e522 + 07860d9 commit ba662c9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion digiarch/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.3"
__version__ = "1.0.4"
19 changes: 14 additions & 5 deletions digiarch/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@
from click import pass_context
from click import Path as ClickPath
from click import version_option
from PIL import Image
from PIL import UnidentifiedImageError
from PIL.Image import DecompressionBombError
from pydantic import TypeAdapter

from .__version__ import __version__
from .database import FileDB

Image.MAX_IMAGE_PIXELS = int(50e3**2)


def handle_rename(file: File, action: RenameAction) -> Union[tuple[Path, Path], tuple[None, None]]:
old_path: Path = file.get_absolute_path()
Expand Down Expand Up @@ -71,7 +75,7 @@ def handle_end(ctx: Context, database: FileDB, exception: ExceptionManager, *log
program_end: HistoryEntry = HistoryEntry.command_history(
ctx,
"end",
data=1 if exception.exception else 0,
data=repr(exception.exception) if exception.exception else None,
reason="".join(format_tb(exception.traceback)) if exception.traceback else None,
)

Expand Down Expand Up @@ -196,15 +200,20 @@ def app_identify(

file_history: list[HistoryEntry] = []

with ExceptionManager(UnidentifiedImageError) as image_exception:
with ExceptionManager(
Exception,
UnidentifiedImageError,
DecompressionBombError,
allow=[OSError, IOError],
) as identify_error:
file = File.from_file(path, root, siegfried, actions, custom_signatures)

if image_exception.exception:
if identify_error.exception:
file = File.from_file(path, root, siegfried)
file.action = "manual"
file.action_data = ActionData(
manual=ManualAction(
reason=image_exception.exception.__class__.__name__,
reason=identify_error.exception.__class__.__name__,
process="Identify and fix error.",
),
)
Expand All @@ -213,7 +222,7 @@ def app_identify(
ctx,
"file:identify:error",
file.uuid,
repr(image_exception.exception),
repr(identify_error.exception),
"".join(format_tb(exception.traceback)) if exception.traceback else None,
),
)
Expand Down
14 changes: 7 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "digiarch"
version = "1.0.3"
version = "1.0.4"
description = "Tools for the Digital Archive Project at Aarhus Stadsarkiv"
authors = ["Aryan Muhammadi Landi <[email protected]>", "Nina Jensen <[email protected]>", "Aarhus Stadsarkiv <[email protected]>"]
license = "GPL-3.0"
Expand All @@ -12,7 +12,7 @@ include = ["pyproject.toml"]

[tool.poetry.dependencies]
python = "^3.9"
acacore = {git = "https://github.com/aarhusstadsarkiv/acacore.git", tag = "v1.1.1"}
acacore = {git = "https://github.com/aarhusstadsarkiv/acacore.git", tag = "v1.1.2"}

[tool.poetry.group.dev.dependencies]
pytest = "^7.0"
Expand Down
3 changes: 2 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ def test_identify(tests_folder: Path, files_folder: Path, files_folder_copy: Pat

with FileDB(files_folder_copy / "_metadata" / "files.db") as database:
last_history: HistoryEntry = sorted(database.history, key=lambda h: h.time).pop()
assert last_history.data == 1
assert isinstance(last_history.data, str)
assert last_history.data.startswith("FileNotFoundError")
assert last_history.reason is not None


Expand Down

0 comments on commit ba662c9

Please sign in to comment.