Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions deploy/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ services:
ports:
- "80:80"
volumes:
- ./_timetagger:/root/_timetagger
- ./_timetagger:/root/.local/share/timetagger
environment:
- TIMETAGGER_BIND=0.0.0.0:80
- TIMETAGGER_DATADIR=/root/_timetagger
- TIMETAGGER_DATADIR=/root/.local/share/timetagger
- TIMETAGGER_LOG_LEVEL=info
- TIMETAGGER_CREDENTIALS=test:$$2a$$08$$0CD1NFiIbancwWsu3se1v.RNR/b7YeZd71yg3cZ/3whGlyU6Iny5i # test:test
2 changes: 1 addition & 1 deletion deploy/image.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# mypaas.service = timetagger.test1
# mypaas.url = https://test1.timetagger.app
# mypaas.volume = /root/_timetagger:/root/_timetagger
# mypaas.volume = /root/.local/share/timetagger:/root/.local/share/timetagger
# mypaas.maxmem = 256m
# mypaas.env = TIMETAGGER_CREDENTIALS

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ jinja2
markdown
bcrypt
iptools
platformdirs
31 changes: 29 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@
from pytest import raises

from timetagger import config
from timetagger._config import set_config
from timetagger._config import set_config, get_default_datadir

from pathlib import Path
import platformdirs


def test_config():
# Defaults
default_bind = "127.0.0.1:8080"
set_config([], {})

assert config.bind == default_bind
assert config.datadir == "~/_timetagger"
expected_new_default = str(
platformdirs.user_data_path(appname="timetagger", appauthor="Klein").resolve()
)
assert config.datadir == expected_new_default

# argv
set_config(["--bind=localhost:8080"], {})
Expand Down Expand Up @@ -92,5 +99,25 @@ def test_config():
set_config()


def test_datadir_fallback_legacy(tmp_path, monkeypatch):
monkeypatch.setattr(Path, "home", lambda: tmp_path)

old_dir = tmp_path / "_timetagger"
old_dir.mkdir()
(old_dir / "timetagger.db").touch()

assert get_default_datadir() == str(old_dir)


def test_datadir_fallback_new(tmp_path, monkeypatch):
monkeypatch.setattr(Path, "home", lambda: tmp_path)

expected_new = str(
platformdirs.user_data_path(appname="timetagger", appauthor="Klein").resolve()
)

assert get_default_datadir() == expected_new


if __name__ == "__main__":
run_tests(globals())
24 changes: 22 additions & 2 deletions timetagger/_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import os
import sys
from pathlib import Path
import platformdirs


def get_default_datadir():
old_dir = Path.home() / "_timetagger"
new_dir = platformdirs.user_data_path(
appname="timetagger", appauthor="Klein"
).resolve()

# keep using old ~/_timetagger if not empty
if old_dir.exists() and old_dir.is_dir() and any(old_dir.iterdir()):
return str(old_dir)

# use new location based on platformdirs
return str(new_dir)


def to_bool(value):
Expand All @@ -24,7 +40,11 @@ class Config:
"""Object that holds config values.

* `bind (str)`: the address and port to bind on. Default "127.0.0.1:8080".
* `datadir (str)`: the directory to store data. Default "~/_timetagger".
* `datadir (str)`: the directory to store data.
Default depends on the OS
- ~/.local/share/timetagger
- ~/Library/Application Support/timetagger
- C:\\Users\\<User>\\AppData\\Local\\Klein\\timetagger
The user db's are stored in `datadir/users`.
* `log_level (str)`: the log level for timetagger and asgineer
(not the asgi server). Default "info".
Expand Down Expand Up @@ -57,7 +77,7 @@ class Config:

_ITEMS = [
("bind", str, "127.0.0.1:8080"),
("datadir", str, "~/_timetagger"),
("datadir", str, get_default_datadir()),
("log_level", str, "info"),
("credentials", str, ""),
("proxy_auth_enabled", to_bool, False),
Expand Down
4 changes: 2 additions & 2 deletions timetagger/server/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
from .. import config

# Init directory paths
ROOT_TT_DIR = os.path.expanduser(config.datadir)
ROOT_TT_DIR = config.datadir
ROOT_USER_DIR = os.path.join(ROOT_TT_DIR, "users")
if not os.path.isdir(ROOT_USER_DIR):
os.makedirs(ROOT_USER_DIR)
os.makedirs(ROOT_USER_DIR, exist_ok=True)

# Init logger
logger = logging.getLogger("asgineer")
Expand Down