Skip to content

Commit

Permalink
siegfried - add method to identify multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoCampinoti94 committed Oct 16, 2023
1 parent fb585be commit aca0141
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions acacore/siegfried/siegfried.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime
from os import PathLike
from pathlib import Path
from subprocess import CompletedProcess
from subprocess import run
from typing import Optional
Expand Down Expand Up @@ -107,3 +108,28 @@ def identify(self, path: Union[str, PathLike]) -> SiegfriedResult:
return SiegfriedResult.model_validate_json(process.stdout)
except ValueError as err:
raise IdentificationError(err)

def identify_many(self, paths: list[Path]) -> tuple[tuple[Path, SiegfriedFile]]:
"""
Identify multiple files.
Args:
paths: The paths to the files
Returns:
A tuple of tuples joining the paths with their SiegfriedFile result
Raises:
IdentificationError: If there is an error calling Siegfried or processing its results
"""
process: CompletedProcess = run(
[self.binary, "-json", "-multi", "1024", *map(str, paths)],
capture_output=True,
encoding="utf-8",
)
_check_process(process)
try:
result = SiegfriedResult.model_validate_json(process.stdout)
return tuple(zip(paths, result.files))
except ValueError as err:
raise IdentificationError(err)

0 comments on commit aca0141

Please sign in to comment.