-
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 dcf34fd
Showing
11 changed files
with
204 additions
and
80 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
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,5 @@ | ||
from pydantic import BaseModel, Field | ||
|
||
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,50 @@ | ||
from pydantic import BaseModel, Field, ConfigDict | ||
from src.core.library.alchemy.library import Library | ||
from datetime import datetime | ||
from appdirs import user_cache_dir | ||
import structlog | ||
from pathlib import Path | ||
import toml | ||
from typing import Optional | ||
|
||
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: | ||
print("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: | ||
print("path is not none") | ||
file = path | ||
|
||
print(file) | ||
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
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.