mirror of
https://github.com/aclist/dztui.git
synced 2026-10-31 15:12:48 +01:00
Merge pull request #20 from aclist/fix/better-config-check
fix: more robust version/config file check
This commit is contained in:
4 files changed
+40
-16
No files matched your search
@@ -48,6 +48,8 @@ WINDOW_DEFAULT_X = 1400
|
|||||||
WINDOW_DEFAULT_Y = 800
|
WINDOW_DEFAULT_Y = 800
|
||||||
|
|
||||||
LEGACY_CONFIG_PATH = ".config/dztui/dztuirc"
|
LEGACY_CONFIG_PATH = ".config/dztui/dztuirc"
|
||||||
|
LEGACY_COLS_PATH = ".local/state/dzgui/dzg.cols.json"
|
||||||
|
LEGACY_IPS_PATH = ".local/share/dzgui/helpers/ips.csv"
|
||||||
|
|
||||||
DEBUG_LOG = f"{APP_NAME}_DEBUG.LOG"
|
DEBUG_LOG = f"{APP_NAME}_DEBUG.LOG"
|
||||||
SYSTEM_LOG = f"{APP_NAME}_SYSTEM.LOG"
|
SYSTEM_LOG = f"{APP_NAME}_SYSTEM.LOG"
|
||||||
@@ -34,7 +34,7 @@ from dzgui.const.enum import (
|
|||||||
ContextMenu,
|
ContextMenu,
|
||||||
)
|
)
|
||||||
|
|
||||||
from dzgui.const.constants import LIBRARYFOLDERS_PATH, APPID_DAYZ, APPID_DAYZ_EXP, HEX_RED
|
from dzgui.const.constants import LIBRARYFOLDERS_PATH, APPID_DAYZ, APPID_DAYZ_EXP, HEX_RED, WINDOW_DEFAULT_X, WINDOW_DEFAULT_Y
|
||||||
from dzgui.controllers.model import ModelManager
|
from dzgui.controllers.model import ModelManager
|
||||||
|
|
||||||
from dzgui.config import update
|
from dzgui.config import update
|
||||||
|
|||||||
+25
-9
@@ -1,13 +1,13 @@
|
|||||||
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from dzgui.const.constants import LEGACY_CONFIG_PATH
|
from dzgui.const.constants import LEGACY_CONFIG_PATH, LEGACY_COLS_PATH, LEGACY_IPS_PATH
|
||||||
from dzgui.config.convert import rc2json
|
from dzgui.config.convert import rc2json
|
||||||
|
from dzgui.util._json import read_json, write_json
|
||||||
|
|
||||||
|
|
||||||
def test_legacy_conf(config: Path) -> None:
|
def migrate_legacy_conf(config: Path) -> None:
|
||||||
if config.exists() is True:
|
|
||||||
return
|
|
||||||
old_conf = Path.home() / LEGACY_CONFIG_PATH
|
old_conf = Path.home() / LEGACY_CONFIG_PATH
|
||||||
if old_conf.is_file():
|
if old_conf.is_file():
|
||||||
j = rc2json(old_conf)
|
j = rc2json(old_conf)
|
||||||
@@ -18,20 +18,36 @@ def test_legacy_conf(config: Path) -> None:
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def move_state_files(state_path: Path) -> None:
|
def has_new_config(config: Path) -> bool:
|
||||||
|
return config.exists()
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_cols_file(res: Path) -> None:
|
||||||
|
old_res = Path.home() / LEGACY_COLS_PATH
|
||||||
|
if old_res.is_file():
|
||||||
|
j = read_json(old_res)
|
||||||
|
cols = j["cols"]
|
||||||
|
if "View" in cols:
|
||||||
|
return
|
||||||
|
cols["View"] = cols.pop("Perspective")
|
||||||
|
cols["Max"] = cols.pop("Maximum")
|
||||||
|
write_json(j, res)
|
||||||
|
|
||||||
|
|
||||||
|
def copy_state_files(state_path: Path) -> None:
|
||||||
home = Path.home()
|
home = Path.home()
|
||||||
legacy = home / ".local/state/dzgui"
|
legacy = home / ".local/state/dzgui"
|
||||||
if state_path == legacy:
|
if state_path == legacy:
|
||||||
# TODO: log this
|
# TODO: log this
|
||||||
return
|
return
|
||||||
for file in legacy.iterdir():
|
for file in legacy.iterdir():
|
||||||
file.rename(state_path / file.name)
|
shutil.copy(file, state_path / file.name)
|
||||||
|
|
||||||
|
|
||||||
def move_ipdb(ips_path: Path) -> None:
|
def copy_ipdb(ips_path: Path) -> None:
|
||||||
home = Path.home()
|
home = Path.home()
|
||||||
name = "ips.csv"
|
name = "ips.csv"
|
||||||
legacy = home / ".local/share/helpers/dzgui" / name
|
legacy = home / LEGACY_IPS_PATH
|
||||||
if ips_path == legacy:
|
if ips_path == legacy:
|
||||||
return
|
return
|
||||||
legacy.rename(ips_path)
|
shutil.copy(legacy, ips_path)
|
||||||
+12
-6
@@ -17,7 +17,13 @@ from dzgui.const.update import ALLOW_UPDATES
|
|||||||
from dzgui.init.coords import get_local_coords
|
from dzgui.init.coords import get_local_coords
|
||||||
from dzgui.init.dayz import is_dayz_installed
|
from dzgui.init.dayz import is_dayz_installed
|
||||||
from dzgui.init.flock import lock_acquire, lock_release
|
from dzgui.init.flock import lock_acquire, lock_release
|
||||||
from dzgui.init.migrate import test_legacy_conf, move_state_files, move_ipdb
|
from dzgui.init.migrate import (
|
||||||
|
has_new_config,
|
||||||
|
migrate_cols_file,
|
||||||
|
migrate_legacy_conf,
|
||||||
|
copy_state_files,
|
||||||
|
copy_ipdb,
|
||||||
|
)
|
||||||
from dzgui.init.prefix import get_version
|
from dzgui.init.prefix import get_version
|
||||||
from dzgui.init.prereqs import has_steam_client
|
from dzgui.init.prereqs import has_steam_client
|
||||||
from dzgui.init.proc import is_dayz_running, is_steam_running
|
from dzgui.init.proc import is_dayz_running, is_steam_running
|
||||||
@@ -61,11 +67,11 @@ def main() -> None:
|
|||||||
xdg_paths = get_xdg_paths()
|
xdg_paths = get_xdg_paths()
|
||||||
XDG = parse_filepaths(xdg_paths)
|
XDG = parse_filepaths(xdg_paths)
|
||||||
|
|
||||||
# NOTE: one-time operation when upgrading
|
if has_new_config(XDG.config) is False:
|
||||||
if Version(version) < Version("7.0.0"):
|
migrate_legacy_conf(XDG.config)
|
||||||
test_legacy_conf(XDG.config)
|
migrate_cols_file(XDG.columns)
|
||||||
move_state_files(xdg_paths["XDG_STATE_HOME"])
|
copy_state_files(xdg_paths["XDG_STATE_HOME"])
|
||||||
move_ipdb(XDG.ips)
|
copy_ipdb(XDG.ips)
|
||||||
|
|
||||||
_format = "%(asctime)s␞%(levelname)s␞%(filename)s::%(funcName)s::%(lineno)s␞%(message)s"
|
_format = "%(asctime)s␞%(levelname)s␞%(filename)s::%(funcName)s::%(lineno)s␞%(message)s"
|
||||||
logging.basicConfig(filename=XDG.debug, format=_format, level=logging.DEBUG)
|
logging.basicConfig(filename=XDG.debug, format=_format, level=logging.DEBUG)
|
||||||
|
|||||||
Reference in new issue
Block a user