Skip to content

Commit

Permalink
added cache generation of problems.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Barakudum committed Feb 24, 2024
1 parent 1d9c55a commit 9709518
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/jarklin/cache/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
from pathlib import Path
from functools import cached_property
from configlib import ConfigInterface
from ..common.types import InfoEntry
from ..common.types import InfoEntry, ProblemEntry
from ..common import dot_ignore, scheduling
from ._cache_generator import CacheGenerator
from .video import VideoCacheGenerator
from .gallery import GalleryCacheGenerator
from .util import is_video_file, is_gallery, is_deprecated, is_incomplete, get_creation_time, get_modification_time
try:
from better_exceptions import format_exception
except ModuleNotFoundError:
from traceback import format_exception


__all__ = ['Cache']
Expand Down Expand Up @@ -97,12 +101,16 @@ def invalidate(self) -> None:
def generate(self) -> None:
logging.info("cache.generate()")
info: t.List[InfoEntry] = []
problems: t.List[ProblemEntry] = []
generators: t.List[CacheGenerator] = self.find_generators()

def generate_info_file():
logging.info("generating info.json")
with open(self.root.joinpath('.jarklin/info.json'), 'w') as fp:
fp.write(json.dumps(info))
logging.info("generating problems.json")
with open(self.root.joinpath('.jarklin/problems.json'), 'w') as fp:
fp.write(json.dumps(problems))

for generator in generators:
source = generator.source
Expand All @@ -115,6 +123,12 @@ def generate_info_file():
generator.generate()
except Exception as error:
logging.error(f"Cache: generation failed ({generator})", exc_info=error)
problems.append(ProblemEntry(
file=str(source.relative_to(self.root)),
type=type(error).__name__,
description=str(error),
traceback='\n'.join(format_exception(type(error), error, error.__traceback__))
))
continue
generate_info_file()
info.append(InfoEntry(
Expand Down
10 changes: 10 additions & 0 deletions src/jarklin/common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
# -------------------------------------------------------------------------------------------------------------------- #


class ProblemEntry(_t.TypedDict):
file: str
type: str
description: str
traceback: str


# -------------------------------------------------------------------------------------------------------------------- #


class InfoEntry(_t.TypedDict):
path: str
name: str
Expand Down

0 comments on commit 9709518

Please sign in to comment.