Skip to content

Commit

Permalink
models.file:Masterfile.from_file - pass actions as `dict[str, MasterC…
Browse files Browse the repository at this point in the history
…onvertAction]`
  • Loading branch information
MatteoCampinoti94 committed Nov 25, 2024
1 parent c089daf commit 01bfbba
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions acacore/models/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from .reference_files import IgnoreAction
from .reference_files import IgnoreIfAction
from .reference_files import ManualAction
from .reference_files import MasterConvertAction
from .reference_files import TActionType

_A = TypeVar("_A")
Expand Down Expand Up @@ -335,6 +336,7 @@ def from_file(
parent=parent,
processed=processed or False,
lock=lock or False,
original_path=file_base.relative_path,
)

from_custom_signatures: bool = False
Expand Down Expand Up @@ -462,8 +464,7 @@ def from_file(
original_uuid: UUID | None = None,
siegfried: Siegfried | SiegfriedFile | None = None,
custom_signatures: list[CustomSignature] | None = None,
actions_access: dict[str, ConvertAction] | None = None,
actions_statutory: dict[str, ConvertAction] | None = None,
actions: dict[str, MasterConvertAction] | None = None,
uuid: UUID | None = None,
processed: bool = False,
) -> Self:
Expand All @@ -482,21 +483,19 @@ def from_file(
processed=processed,
)

if actions_access:
file.get_action("access", actions_access, set_match=True)

if actions_statutory:
file.get_action("statutory", actions_statutory, set_match=True)
if actions:
file.get_action("access", actions, set_match=True)
file.get_action("statutory", actions, set_match=True)

return file

def get_action(
self,
target: Literal["access", "statutory"],
actions: dict[str, ConvertAction],
actions: dict[str, MasterConvertAction],
*,
set_match: bool = False,
) -> ConvertAction | None:
) -> MasterConvertAction | None:
"""
Returns the access ``Action`` matching the file's PUID.
Expand All @@ -505,13 +504,13 @@ def get_action(
:param set_match: Set the matched action if ``True``, defaults to ``False``.
:return: The matched ``Action`` object, if any, otherwise ``None``.
"""
action: ConvertAction | None = get_identifier(self, [], actions)
action: MasterConvertAction | None = get_identifier(self, [], actions)

if set_match and action:
if target == "access":
self.convert_access = action
self.convert_access = action.access
elif target == "statutory":
self.convert_statutory = action
self.convert_statutory = action.statutory
elif set_match:
if target == "access":
self.convert_access = None
Expand Down

0 comments on commit 01bfbba

Please sign in to comment.