Replace string paths with pathlib's path #11
2 changed files with 9 additions and 6 deletions
|
|
@ -1,17 +1,18 @@
|
||||||
import tomlkit
|
import tomlkit
|
||||||
|
from pathlib import Path
|
||||||
from tomlkit import TOMLDocument
|
from tomlkit import TOMLDocument
|
||||||
|
|
||||||
|
|
||||||
class Mod:
|
class Mod:
|
||||||
__config: TOMLDocument
|
__config: TOMLDocument
|
||||||
__path: str
|
__path: Path
|
||||||
__name: str
|
__name: str
|
||||||
__description: str
|
__description: str
|
||||||
__author: str
|
__author: str
|
||||||
__enabled: bool
|
__enabled: bool
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def path(self) -> str:
|
def path(self) -> Path:
|
||||||
return self.__path
|
return self.__path
|
||||||
|
|
||||||
# Mod metadata
|
# Mod metadata
|
||||||
|
|
@ -44,15 +45,17 @@ class Mod:
|
||||||
# Nothing to do
|
# Nothing to do
|
||||||
return
|
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
|
self.__config["enabled"] = value
|
||||||
tomlkit.dump(self.__config, config_file)
|
tomlkit.dump(self.__config, config_file)
|
||||||
|
|
||||||
def __init__(self, path: str) -> None:
|
def __init__(self, path: Path) -> None:
|
||||||
self.__path = path
|
self.__path = path
|
||||||
|
|
||||||
try:
|
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)
|
self.__config = tomlkit.load(config_file)
|
||||||
|
|
||||||
if "enabled" not in self.__config:
|
if "enabled" not in self.__config:
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ class QModListModel(QAbstractListModel):
|
||||||
|
|
||||||
for dir in MOD_PATH.iterdir():
|
for dir in MOD_PATH.iterdir():
|
||||||
try:
|
try:
|
||||||
new_mod: Mod = Mod(f"{dir.as_posix()}/")
|
new_mod: Mod = Mod(dir)
|
||||||
mods.append(new_mod)
|
mods.append(new_mod)
|
||||||
except InvalidModError as e:
|
except InvalidModError as e:
|
||||||
print(f"Found invalid mod at {dir}: {e.message}")
|
print(f"Found invalid mod at {dir}: {e.message}")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue