-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11d0553
commit 037ebde
Showing
12 changed files
with
184 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.12.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
__all__ = ["tssettings"] | ||
from .tssettings import TSSettings | ||
|
||
__all__ = ["TSSettings"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from pydantic import BaseModel | ||
|
||
|
||
class LibSettings(BaseModel): | ||
# Cant think of any library-specific properties lol | ||
test_prop: bool = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from datetime import datetime | ||
from pathlib import Path | ||
|
||
import structlog | ||
import toml | ||
from appdirs import user_cache_dir | ||
from pydantic import BaseModel, ConfigDict, Field | ||
from src.core.library.alchemy.library import Library | ||
|
||
logger = structlog.get_logger(__name__) | ||
|
||
cache_dir = Path(user_cache_dir()) / ".TagStudio" | ||
cache_location = cache_dir / "cache.toml" | ||
|
||
|
||
class TSCachedData(BaseModel): | ||
model_config = ConfigDict(arbitrary_types_allowed=True) | ||
last_library: Library | None = Field(default=None) | ||
library_history: dict[datetime, str] = Field(default_factory=dict[datetime, str]) | ||
|
||
path: str = Field() | ||
|
||
@staticmethod | ||
def open(path: str | None = None) -> "TSCachedData": | ||
file: str | None = None | ||
|
||
if path is None: | ||
if not Path(cache_dir).exists(): | ||
logger.info("Cache directory does not exist - creating", path=cache_dir) | ||
Path.mkdir(cache_dir) | ||
if not Path(cache_location).exists(): | ||
logger.info("Cache file does not exist - creating", path=cache_location) | ||
open(cache_location, "w").close() | ||
file = str(cache_location) | ||
else: | ||
file = path | ||
|
||
data = toml.load(file) | ||
data["path"] = str(path) if path is not None else str(cache_location) | ||
cached_data = TSCachedData(**data) | ||
return cached_data | ||
|
||
def save(self): | ||
with open(self.path, "wb") as f: | ||
f.writelines(toml.dumps(self)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.