Skip to content

Commit

Permalink
merge: Fix diagram cache documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Wuestengecko committed Oct 9, 2023
2 parents ce0c7cc + 17fd754 commit 20464ec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
16 changes: 10 additions & 6 deletions capellambse/_diagram_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
)


class _IndexEntry(t.TypedDict):
class IndexEntry(t.TypedDict):
"""An entry for the index JSON file."""

uuid: str
name: str
type: modeltypes.DiagramType
Expand Down Expand Up @@ -143,13 +145,13 @@ def _copy_images(
destdir: pathlib.Path,
extension: str,
background: bool,
) -> list[_IndexEntry]:
) -> list[IndexEntry]:
name_counts = collections.defaultdict[str, int](lambda: -1)
index: list[_IndexEntry] = []
index: list[IndexEntry] = []
files = {i.name: i for i in srcdir.glob("**/*") if i.is_file()}

for i in model.diagrams:
entry: _IndexEntry = {
entry: IndexEntry = {
"uuid": i.uuid,
"name": i.name,
"type": i.type,
Expand Down Expand Up @@ -244,7 +246,7 @@ def _write_index(
model: capellambse.MelodyModel,
extension: str,
dest: pathlib.Path,
index: list[_IndexEntry],
index: list[IndexEntry],
) -> None:
now = datetime.datetime.now().strftime("%A, %Y-%m-%d %H:%M:%S")
title = f"Capella diagram cache for {model.name!r}"
Expand All @@ -261,7 +263,7 @@ def _write_index(
body := E.body(E.h1(title), E.p({"class": "small"}, "Created: ", now)),
)

def sortkey(entry: _IndexEntry):
def sortkey(entry: IndexEntry):
try:
vp_index = VIEWPOINT_ORDER.index(entry["viewpoint"])
except ValueError:
Expand Down Expand Up @@ -290,6 +292,8 @@ def sortkey(entry: _IndexEntry):


class IndexEncoder(json.JSONEncoder):
"""A JSON encoder for the index file."""

def default(self, o):
if isinstance(o, modeltypes.DiagramType):
return o.name
Expand Down
3 changes: 3 additions & 0 deletions capellambse/diagram_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import capellambse
from capellambse import _diagram_cache, cli_helpers

# pylint: disable=unused-import
from capellambse._diagram_cache import IndexEntry

try:
import click
except ImportError:
Expand Down
5 changes: 4 additions & 1 deletion capellambse/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,11 @@ def update_diagram_cache(
list of dictionaries, each representing a diagram in the
model. The dictionaries come with the keys
- uuid: The unique ID of the diagram
- name: Name of the diagram as it has been set in Capella
- uuid: The UUID of the diagram
- type: The diagram type as it was created in Capella
- viewpoint: The source layer from where the representation
is loaded from. It is ``Common`` for layerless diagrams.
- success: A boolean stating if a diagram has been exported
from Capella
Expand Down

0 comments on commit 20464ec

Please sign in to comment.