Replace string paths with pathlib's path #11

Merged
Toast merged 2 commits from pathlib into main 2025-05-25 14:34:03 +02:00
2 changed files with 9 additions and 6 deletions
Showing only changes of commit 5cfab64b07 - Show all commits

View file

@ -1,17 +1,18 @@
import tomlkit
from pathlib import Path
from tomlkit import TOMLDocument
class Mod:
__config: TOMLDocument
__path: str
__path: Path
__name: str
__description: str
__author: str
__enabled: bool
@property
def path(self) -> str:
def path(self) -> Path:
return self.__path
# Mod metadata
@ -44,15 +45,17 @@ class Mod:
# Nothing to do
return
with open(self.__path + "config.toml", "w") as config_file:
config_toml = Path(self.__path, "config.toml")
with config_toml.open("w") as config_file:
self.__config["enabled"] = value
tomlkit.dump(self.__config, config_file)
def __init__(self, path: str) -> None:
def __init__(self, path: Path) -> None:
self.__path = path
try:
with open(path + "config.toml") as config_file:
config_toml = Path(self.__path, "config.toml")
with config_toml.open() as config_file:
self.__config = tomlkit.load(config_file)
if "enabled" not in self.__config:

View file

@ -20,7 +20,7 @@ class QModListModel(QAbstractListModel):
for dir in MOD_PATH.iterdir():
try:
new_mod: Mod = Mod(f"{dir.as_posix()}/")
new_mod: Mod = Mod(dir)
mods.append(new_mod)
except InvalidModError as e:
print(f"Found invalid mod at {dir}: {e.message}")