Move source code to src/leek

This makes the package work again
This commit is contained in:
Toast 2025-05-22 22:52:08 +02:00
parent 1a626fddff
commit 6061590270
9 changed files with 16 additions and 10 deletions

71
src/leek/mod.py Normal file
View file

@ -0,0 +1,71 @@
import tomlkit
class Mod:
@property
def path(self) -> str:
return self.__path
# Mod metadata
@property
def name(self) -> str | None:
if "name" not in self.__config:
return None
return self.__config["name"].as_string()
@property
def description(self) -> str | None:
if "description" not in self.__config.keys():
return None
else:
return self.__config["description"].as_string()
@property
def author(self) -> str | None:
if "author" not in self.__config:
return None
return self.__config["author"].as_string()
@property
def enabled(self) -> bool:
return True if self.__enabled == "true" else False
@enabled.setter
def enabled(self, value: bool) -> None:
if value == self.__enabled:
# Nothing to do
return
with open(self.__path + "config.toml", "w") as config_file:
self.__config["enabled"] = value
tomlkit.dump(self.__config, config_file)
def __init__(self, path: str) -> None:
self.__path = path
try:
with open(path + "config.toml") as config_file:
self.__config = tomlkit.load(config_file)
if "enabled" not in self.__config:
raise InvalidModError("config.toml does not contain the enabled key")
else:
self.__enabled = self.__config["enabled"]
except FileNotFoundError:
raise InvalidModError("config.toml does not exist")
def __str__(self) -> str:
return f"Mod({self.__path})"
class InvalidModError(Exception):
"""
This exception is raised when the Mod class gets given a path of something that's not a valid mod
"""
def __init__(self, message: str) -> None:
super().__init__(message)
self.message = message
def __str__(self) -> str:
return f"{self.message}"