Compare commits
2 commits
4d22e68a9b
...
ca7e1bb2d1
| Author | SHA1 | Date | |
|---|---|---|---|
| ca7e1bb2d1 | |||
| 94891dea5d |
1 changed files with 19 additions and 2 deletions
|
|
@ -1,10 +1,16 @@
|
|||
import tomlkit
|
||||
import json
|
||||
from pathlib import Path
|
||||
from tomlkit import TOMLDocument
|
||||
from typing import Any
|
||||
|
||||
|
||||
class Mod:
|
||||
__config: TOMLDocument
|
||||
|
||||
__has_meta_json: bool
|
||||
__meta: dict[str, Any]
|
||||
|
||||
__path: Path
|
||||
__name: str
|
||||
__description: str
|
||||
|
|
@ -53,6 +59,7 @@ class Mod:
|
|||
|
||||
def __init__(self, path: Path) -> None:
|
||||
self.__path = path
|
||||
self.__meta = {}
|
||||
|
||||
try:
|
||||
config_toml = Path(self.__path, "config.toml")
|
||||
|
|
@ -61,11 +68,21 @@ class Mod:
|
|||
|
||||
if "enabled" not in self.__config:
|
||||
raise InvalidModError("config.toml does not contain the enabled key")
|
||||
else:
|
||||
self.__enabled = self.__config.get("enabled", bool)
|
||||
self.__enabled = self.__config.get("enabled", bool)
|
||||
except FileNotFoundError:
|
||||
raise InvalidModError("config.toml does not exist")
|
||||
|
||||
meta_json: Path = Path(self.__path, "meta.json")
|
||||
if meta_json.exists():
|
||||
self.__has_meta_json = True
|
||||
try:
|
||||
with meta_json.open() as file:
|
||||
self.__meta = json.load(file)
|
||||
except json.JSONDecodeError as e:
|
||||
print("Failed to parse meta.json!: ", e.msg)
|
||||
else:
|
||||
self.__has_meta_json = False
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"Mod({self.__path})"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue