mirror of
https://github.com/aclist/dztui.git
synced 2026-08-30 11:47:17 +02:00
Compare commits
2 Commits
3f7dfa7cd5
...
6bc6d816df
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6bc6d816df | ||
|
|
4de5147899 |
@ -66,18 +66,19 @@ def copy_bare_configs(config: "Path", resolution: "Path") -> tuple[bool, bool]:
|
|||||||
]
|
]
|
||||||
config_changed = False
|
config_changed = False
|
||||||
state_changed = False
|
state_changed = False
|
||||||
if APP_NAME_LOWER not in str(config):
|
if config.parent.exists() is False:
|
||||||
new_file = config.parent / APP_NAME_LOWER / conf
|
new_file = config
|
||||||
if config.is_file():
|
old_file = config.parent.parent / conf
|
||||||
|
if old_file.is_file():
|
||||||
make_parents(new_file)
|
make_parents(new_file)
|
||||||
shutil.copy(config, new_file)
|
shutil.copy(old_file, new_file)
|
||||||
config_changed = True
|
config_changed = True
|
||||||
if APP_NAME_LOWER not in str(resolution):
|
if resolution.parent.exists() is False:
|
||||||
state_path = resolution.parent
|
state_path = resolution.parent
|
||||||
for state_file in state:
|
for state_file in state:
|
||||||
old_file = state_path / state_file
|
old_file = state_path.parent / state_file
|
||||||
if old_file.is_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)
|
make_parents(new_file)
|
||||||
shutil.copy(old_file, new_file)
|
shutil.copy(old_file, new_file)
|
||||||
state_changed = True
|
state_changed = True
|
||||||
|
|||||||
@ -29,9 +29,9 @@ def is_writeable(path_str: str) -> bool:
|
|||||||
if not path.exists():
|
if not path.exists():
|
||||||
try:
|
try:
|
||||||
path.mkdir(parents=True)
|
path.mkdir(parents=True)
|
||||||
|
path.unlink()
|
||||||
except OSError:
|
except OSError:
|
||||||
return False
|
return False
|
||||||
path.unlink()
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -121,6 +121,7 @@ class BootDialog(Gtk.Dialog):
|
|||||||
|
|
||||||
self.error_box.hide()
|
self.error_box.hide()
|
||||||
|
|
||||||
|
print(self.xdg.ips)
|
||||||
steps = [
|
steps = [
|
||||||
(StoredFunc(is_dayz_installed, self.xdg.config), preboot.dayz, False),
|
(StoredFunc(is_dayz_installed, self.xdg.config), preboot.dayz, False),
|
||||||
(StoredFunc(rebuild_symlinks, self.xdg.config), preboot.symlinks, False),
|
(StoredFunc(rebuild_symlinks, self.xdg.config), preboot.symlinks, False),
|
||||||
|
|||||||
@ -1,9 +1,15 @@
|
|||||||
import pytest
|
import pytest
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import os
|
||||||
|
|
||||||
from dzgui.app_init import copy_bare_configs
|
from dzgui.app_init import copy_bare_configs
|
||||||
|
from dzgui.config.xdg import get_xdg_paths, parse_filepaths
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
CONF_STRING = "DZGUI_CONF\n"
|
||||||
|
STATE_STRING = "DZGUI_STATE\n"
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def state_files():
|
def state_files():
|
||||||
state = [
|
state = [
|
||||||
@ -14,55 +20,58 @@ def state_files():
|
|||||||
"dzg.columns.json",
|
"dzg.columns.json",
|
||||||
"dzg.notes.json",
|
"dzg.notes.json",
|
||||||
"ips.csv",
|
"ips.csv",
|
||||||
".month"
|
".month",
|
||||||
]
|
]
|
||||||
return state
|
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
|
@pytest.mark.mods
|
||||||
def test_config_file_import(state_files):
|
def test_config_file_import(xdg_paths, state_files):
|
||||||
conf_string = "DZGUI_CONF\n"
|
|
||||||
state_string = "DZGUI_STATE\n"
|
|
||||||
|
|
||||||
tmp = tempfile.TemporaryDirectory()
|
tmp_conf = xdg_paths.config.parent.parent
|
||||||
tmp2 = tempfile.TemporaryDirectory()
|
tmp_conf_file = tmp_conf / xdg_paths.config.name
|
||||||
tmp_conf = Path(tmp.name)
|
tmp_conf_file.write_text(CONF_STRING)
|
||||||
tmp_state = Path(tmp2.name)
|
|
||||||
|
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:
|
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"
|
assert (tmp_conf / xdg_paths.config.name).read_text() == CONF_STRING
|
||||||
config_changed, state_changed = copy_bare_configs(tmp_conf_file, tmp_state_file)
|
|
||||||
|
|
||||||
assert (tmp_conf / "dzgui/config.json").read_text() == conf_string
|
|
||||||
for file in state_files:
|
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 config_changed is True
|
||||||
assert state_changed is True
|
assert state_changed is True
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.mods
|
@pytest.mark.mods
|
||||||
def test_config_file_no_import(state_files):
|
def test_config_file_no_import(xdg_paths, state_files):
|
||||||
conf_string = "DZGUI_CONF\n"
|
for subdir in xdg_paths.config.parent, xdg_paths.resolution.parent:
|
||||||
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"
|
|
||||||
subdir.mkdir()
|
subdir.mkdir()
|
||||||
|
|
||||||
tmp_conf_file = tmp_conf / "dzgui/config.json"
|
tmp_conf_file = xdg_paths.config
|
||||||
tmp_conf_file.write_text(conf_string)
|
tmp_conf_file.write_text(CONF_STRING)
|
||||||
|
|
||||||
|
tmp_state_file = xdg_paths.resolution
|
||||||
|
|
||||||
for file in state_files:
|
for file in state_files:
|
||||||
tmp_state.joinpath("dzgui").joinpath(file).write_text(state_string)
|
xdg_paths.resolution.parent.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)
|
config_changed, state_changed = copy_bare_configs(xdg_paths.config, xdg_paths.resolution)
|
||||||
assert config_changed is False
|
assert config_changed is False
|
||||||
assert state_changed is False
|
assert state_changed is False
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user