mirror of
https://github.com/aclist/dztui.git
synced 2026-08-28 18:57:12 +02:00
fix: copy bare config files to named directory (#375)
This commit is contained in:
parent
cd1fd1b179
commit
61f90d6016
@ -1,9 +1,10 @@
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
|
||||
from dzgui.const.constants import APP_NAME
|
||||
from dzgui.const.constants import APP_NAME, APP_NAME_LOWER
|
||||
from dzgui.const.enum import Preferences
|
||||
from dzgui.config.query import lookup
|
||||
from dzgui.config.userprefs import UserPrefs
|
||||
@ -50,6 +51,34 @@ def setup_logger(log_path: "Path") -> None:
|
||||
logger.addHandler(fh)
|
||||
|
||||
|
||||
|
||||
def copy_bare_configs(config: "Path", resolution: "Path") -> None:
|
||||
# NOTE: temporary workaround for #375
|
||||
conf = "config.json"
|
||||
state = [
|
||||
"dzg.history",
|
||||
"dzg.versions",
|
||||
"dzg.res.json",
|
||||
"dzg.filters.json",
|
||||
"dzg.columns.json",
|
||||
"dzg.notes.json",
|
||||
"ips.csv",
|
||||
".month"
|
||||
]
|
||||
if APP_NAME_LOWER not in str(config):
|
||||
new_file = config.parent / APP_NAME_LOWER / conf
|
||||
make_parents(new_file)
|
||||
if config.is_file():
|
||||
shutil.copy(config, new_file)
|
||||
if APP_NAME_LOWER not in str(resolution):
|
||||
state_path = resolution.parent
|
||||
for state_file in state:
|
||||
old_file = state_path / state_file
|
||||
if old_file.is_file():
|
||||
new_file = state_path / APP_NAME_LOWER / state_file
|
||||
make_parents(new_file)
|
||||
shutil.copy(old_file, new_file)
|
||||
|
||||
def load_gui(version: str, is_debug: bool) -> None:
|
||||
lock = lock_acquire() # noqa
|
||||
|
||||
@ -58,6 +87,8 @@ def load_gui(version: str, is_debug: bool) -> None:
|
||||
xdg_paths = get_xdg_paths()
|
||||
XDG = parse_filepaths(xdg_paths)
|
||||
|
||||
copy_bare_configs(XDG.config, XDG.resolution)
|
||||
|
||||
if XDG.resolution.parent.is_dir() is False:
|
||||
make_parents(XDG.resolution)
|
||||
|
||||
|
||||
@ -55,11 +55,12 @@ def get_xdg_paths() -> dict:
|
||||
|
||||
resolved_paths = {}
|
||||
for path in xdg_paths:
|
||||
rp = os.environ.get(path)
|
||||
if rp is not None and is_writeable(rp):
|
||||
resolved_paths[path] = Path(rp)
|
||||
real_path = os.environ.get(path)
|
||||
if real_path is not None and is_writeable(real_path):
|
||||
new_path = Path(real_path)
|
||||
else:
|
||||
resolved_paths[path] = xdg_paths[path] / APP_NAME_LOWER
|
||||
new_path = xdg_paths[path]
|
||||
resolved_paths[path] = new_path / APP_NAME_LOWER
|
||||
return resolved_paths
|
||||
|
||||
|
||||
|
||||
37
tests/test_bare_conf_files.py
Normal file
37
tests/test_bare_conf_files.py
Normal file
@ -0,0 +1,37 @@
|
||||
import pytest
|
||||
import tempfile
|
||||
|
||||
from dzgui.app_init import copy_bare_configs
|
||||
from pathlib import Path
|
||||
|
||||
@pytest.mark.mods
|
||||
def test_bare_file_import():
|
||||
conf_string = "DZGUI_CONF\n"
|
||||
state_string = "DZGUI_STATE\n"
|
||||
state = [
|
||||
"dzg.history",
|
||||
"dzg.versions",
|
||||
"dzg.res.json",
|
||||
"dzg.filters.json",
|
||||
"dzg.columns.json",
|
||||
"dzg.notes.json",
|
||||
"ips.csv",
|
||||
".month"
|
||||
]
|
||||
|
||||
tmp = tempfile.TemporaryDirectory()
|
||||
tmp2 = tempfile.TemporaryDirectory()
|
||||
tmp_conf = Path(tmp.name)
|
||||
tmp_state = Path(tmp2.name)
|
||||
|
||||
tmp_conf_file = tmp_conf / "config.json"
|
||||
tmp_conf_file.write_text(conf_string)
|
||||
for file in state:
|
||||
tmp_state.joinpath(file).write_text(state_string)
|
||||
|
||||
tmp_state_file = tmp_state / "dzg.res.json"
|
||||
copy_bare_configs(tmp_conf_file, tmp_state_file)
|
||||
|
||||
assert (tmp_conf / "dzgui/config.json").read_text() == conf_string
|
||||
for file in state:
|
||||
assert (tmp_state / "dzgui" / file).read_text() == state_string
|
||||
Loading…
Reference in New Issue
Block a user