Skip to content

Commit

Permalink
make configuration name based on config version.
Browse files Browse the repository at this point in the history
store static files based on bmds-ui version
  • Loading branch information
shapiromatron committed Aug 1, 2024
1 parent 1cb2474 commit a4419db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
7 changes: 4 additions & 3 deletions bmds_ui/desktop/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from .. import __version__
from ..main.settings import desktop
from .config import Database, DesktopConfig, get_app_home
from .config import Database, DesktopConfig, get_app_home, get_version_path
from .log import log, stream


Expand All @@ -33,8 +33,9 @@ def setup_django_environment(db: Database):

desktop.DATABASES["default"]["NAME"] = str(db.path)

public_data_root = app_home / "public"
logs_path = app_home / "logs"
version = get_version_path(__version__)
public_data_root = app_home / "public" / version
logs_path = app_home / "logs" / version

public_data_root.mkdir(exist_ok=True, parents=False)
logs_path.mkdir(exist_ok=True, parents=False)
Expand Down
10 changes: 4 additions & 6 deletions bmds_ui/desktop/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from pydantic import BaseModel, ConfigDict, Field, ValidationError, field_validator

from .. import __version__
from .exceptions import DesktopException


Expand Down Expand Up @@ -117,15 +116,14 @@ def get_default_config_path() -> Path:
# adapted from `hatch` source code
# https://github.com/pypa/hatch/blob/3adae6c0dfd5c20dfe9bf6bae19b44a696c22a43/docs/config/hatch.md?plain=1#L5-L15
app_home = Path.home()
version = get_version_path(__version__)
match platform.system():
case "Windows":
app_home = app_home / "AppData" / "Local" / "bmds" / version
app_home = app_home / "AppData" / "Local" / "bmds"
case "Darwin":
app_home = app_home / "Library" / "Application Support" / "bmds" / version
app_home = app_home / "Library" / "Application Support" / "bmds"
case "Linux" | _:
config = Path(os.environ.get("XDG_CONFIG_HOME", "~/.config")).expanduser().resolve()
app_home = config / "bmds" / version
app_home = config / "bmds"
return app_home


Expand All @@ -146,7 +144,7 @@ class Config:
@classmethod
def get_config_path(cls) -> Path:
# if configuration file doesn't exist, create one. return the file
config = get_app_home() / "config.json"
config = get_app_home() / f"config_v{LATEST_CONFIG_VERSION}.json"
if not config.exists():
config.write_text(DesktopConfig.default().model_dump_json(indent=2))
return config
Expand Down

0 comments on commit a4419db

Please sign in to comment.