mirror of
https://github.com/aclist/dztui.git
synced 2026-08-28 02:37:20 +02:00
fix: parse parent directory
Some checks are pending
Mirror to Codeberg / mirror-to-codeberg (push) Waiting to run
Some checks are pending
Mirror to Codeberg / mirror-to-codeberg (push) Waiting to run
This commit is contained in:
parent
4c31cd7ecd
commit
4de5147899
@ -66,18 +66,19 @@ def copy_bare_configs(config: "Path", resolution: "Path") -> tuple[bool, bool]:
|
||||
]
|
||||
config_changed = False
|
||||
state_changed = False
|
||||
if APP_NAME_LOWER not in str(config):
|
||||
new_file = config.parent / APP_NAME_LOWER / conf
|
||||
if config.is_file():
|
||||
if config.parent.exists() is False:
|
||||
new_file = config
|
||||
old_file = config.parent.parent / conf
|
||||
if old_file.is_file():
|
||||
make_parents(new_file)
|
||||
shutil.copy(config, new_file)
|
||||
shutil.copy(old_file, new_file)
|
||||
config_changed = True
|
||||
if APP_NAME_LOWER not in str(resolution):
|
||||
if resolution.parent.exists() is False:
|
||||
state_path = resolution.parent
|
||||
for state_file in state:
|
||||
old_file = state_path / state_file
|
||||
old_file = state_path.parent / state_file
|
||||
if old_file.is_file():
|
||||
new_file = state_path / APP_NAME_LOWER / state_file
|
||||
new_file = state_path / state_file
|
||||
make_parents(new_file)
|
||||
shutil.copy(old_file, new_file)
|
||||
state_changed = True
|
||||
|
||||
@ -29,9 +29,9 @@ def is_writeable(path_str: str) -> bool:
|
||||
if not path.exists():
|
||||
try:
|
||||
path.mkdir(parents=True)
|
||||
path.unlink()
|
||||
except OSError:
|
||||
return False
|
||||
path.unlink()
|
||||
return True
|
||||
|
||||
try:
|
||||
|
||||
@ -121,6 +121,7 @@ class BootDialog(Gtk.Dialog):
|
||||
|
||||
self.error_box.hide()
|
||||
|
||||
print(self.xdg.ips)
|
||||
steps = [
|
||||
(StoredFunc(is_dayz_installed, self.xdg.config), preboot.dayz, False),
|
||||
(StoredFunc(rebuild_symlinks, self.xdg.config), preboot.symlinks, False),
|
||||
|
||||
@ -1,9 +1,15 @@
|
||||
import pytest
|
||||
import tempfile
|
||||
import os
|
||||
|
||||
from dzgui.app_init import copy_bare_configs
|
||||
from dzgui.config.xdg import get_xdg_paths, parse_filepaths
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
CONF_STRING = "DZGUI_CONF\n"
|
||||
STATE_STRING = "DZGUI_STATE\n"
|
||||
|
||||
@pytest.fixture
|
||||
def state_files():
|
||||
state = [
|
||||
@ -14,55 +20,58 @@ def state_files():
|
||||
"dzg.columns.json",
|
||||
"dzg.notes.json",
|
||||
"ips.csv",
|
||||
".month"
|
||||
".month",
|
||||
]
|
||||
return state
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def xdg_paths():
|
||||
paths = []
|
||||
routes = {"XDG_CONFIG_HOME": "", "XDG_STATE_HOME": "", "XDG_DATA_HOME": "", "XDG_CACHE_HOME": ""}
|
||||
for route in routes:
|
||||
tmp = tempfile.TemporaryDirectory(delete=False)
|
||||
routes[route] = tmp.name
|
||||
for k, v in routes.items():
|
||||
os.environ[k] = v
|
||||
env = get_xdg_paths()
|
||||
return parse_filepaths(env)
|
||||
|
||||
@pytest.mark.mods
|
||||
def test_config_file_import(state_files):
|
||||
conf_string = "DZGUI_CONF\n"
|
||||
state_string = "DZGUI_STATE\n"
|
||||
def test_config_file_import(xdg_paths, state_files):
|
||||
|
||||
tmp = tempfile.TemporaryDirectory()
|
||||
tmp2 = tempfile.TemporaryDirectory()
|
||||
tmp_conf = Path(tmp.name)
|
||||
tmp_state = Path(tmp2.name)
|
||||
tmp_conf = xdg_paths.config.parent.parent
|
||||
tmp_conf_file = tmp_conf / xdg_paths.config.name
|
||||
tmp_conf_file.write_text(CONF_STRING)
|
||||
|
||||
tmp_state = xdg_paths.resolution.parent.parent
|
||||
tmp_state_file = tmp_state / xdg_paths.resolution.name
|
||||
|
||||
tmp_conf_file = tmp_conf / "config.json"
|
||||
tmp_conf_file.write_text(conf_string)
|
||||
for file in state_files:
|
||||
tmp_state.joinpath(file).write_text(state_string)
|
||||
tmp_state.joinpath(file).write_text(STATE_STRING)
|
||||
config_changed, state_changed = copy_bare_configs(xdg_paths.config, xdg_paths.resolution)
|
||||
|
||||
tmp_state_file = tmp_state / "dzg.res.json"
|
||||
config_changed, state_changed = copy_bare_configs(tmp_conf_file, tmp_state_file)
|
||||
|
||||
assert (tmp_conf / "dzgui/config.json").read_text() == conf_string
|
||||
assert (tmp_conf / xdg_paths.config.name).read_text() == CONF_STRING
|
||||
for file in state_files:
|
||||
assert (tmp_state / "dzgui" / file).read_text() == state_string
|
||||
assert (tmp_state / file).read_text() == STATE_STRING
|
||||
|
||||
assert config_changed is True
|
||||
assert state_changed is True
|
||||
|
||||
|
||||
@pytest.mark.mods
|
||||
def test_config_file_no_import(state_files):
|
||||
conf_string = "DZGUI_CONF\n"
|
||||
state_string = "DZGUI_STATE\n"
|
||||
|
||||
tmp = tempfile.TemporaryDirectory()
|
||||
tmp2 = tempfile.TemporaryDirectory()
|
||||
tmp_conf = Path(tmp.name)
|
||||
tmp_state = Path(tmp2.name)
|
||||
|
||||
for d in tmp_conf, tmp_state:
|
||||
subdir = d / "dzgui"
|
||||
def test_config_file_no_import(xdg_paths, state_files):
|
||||
for subdir in xdg_paths.config.parent, xdg_paths.resolution.parent:
|
||||
subdir.mkdir()
|
||||
|
||||
tmp_conf_file = tmp_conf / "dzgui/config.json"
|
||||
tmp_conf_file.write_text(conf_string)
|
||||
tmp_conf_file = xdg_paths.config
|
||||
tmp_conf_file.write_text(CONF_STRING)
|
||||
|
||||
tmp_state_file = xdg_paths.resolution
|
||||
|
||||
for file in state_files:
|
||||
tmp_state.joinpath("dzgui").joinpath(file).write_text(state_string)
|
||||
tmp_state_file = tmp_state / "dzgui/dzg.res.json"
|
||||
config_changed, state_changed = copy_bare_configs(tmp_conf_file, tmp_state_file)
|
||||
xdg_paths.resolution.parent.joinpath(file).write_text(STATE_STRING)
|
||||
|
||||
config_changed, state_changed = copy_bare_configs(xdg_paths.config, xdg_paths.resolution)
|
||||
assert config_changed is False
|
||||
assert state_changed is False
|
||||
|
||||
Loading…
Reference in New Issue
Block a user