Configuration directory abstraction

This commit is contained in:
Gnarwhal 2024-09-10 23:27:19 +00:00
parent 80057f151a
commit babba91ca2
Signed by: Gnarwhal
GPG key ID: 0989A73D8C421174
2 changed files with 33 additions and 13 deletions

View file

@ -0,0 +1,26 @@
# This file is part of SSHare.
#
# SSHare is free software: you can redistribute it and/or modify it under the terms of
# the GNU General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# SSHare is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# SSHare. If not, see <https://www.gnu.org/licenses/>.
import os
from pathlib import Path
LOCATION = Path(os.environ.get("XDG_CONFIG_DIR", f"{os.environ["HOME"]}/.config")) / "sshare"
def plugins():
return [
path for
path in
(LOCATION / "plugins").iterdir()
if path.is_file() and path.suffix == ".py"
]

View file

@ -19,8 +19,8 @@ import time
import tomllib
import subprocess
import sys
from pathlib import Path
from sshare import config_directory
from sshare.logger import Logger
from sshare.plugin import Plugin
from sshare.plugin import PluginManager
@ -38,8 +38,7 @@ def main():
help="Specify location of config file to use"
)
arguments, _ = arg_parser.parse_known_args()
config_directory = Path(os.environ.get("XDG_CONFIG_DIR", f"{os.environ["HOME"]}/.config")) / "sshare"
with open(arguments.config or (config_directory / "config.toml"), mode="rb") as file:
with open(arguments.config or (config_directory.LOCATION / "config.toml"), mode="rb") as file:
config = tomllib.load(file)
config["config"] = config.get("config", {})
config["flags" ] = config.get("flags", {})
@ -89,12 +88,7 @@ def main():
sys.dont_write_bytecode = True
plugins.add_from(
Plugin.external,
*[
path for
path in
(config_directory / "plugins").iterdir()
if path.is_file() and path.suffix == ".py"
]
*config_directory.plugins(),
)
sys.dont_write_bytecode = False
plugins.activate("logger")