diff --git a/src/sshare/config_directory.py b/src/sshare/config_directory.py new file mode 100644 index 0000000..4617622 --- /dev/null +++ b/src/sshare/config_directory.py @@ -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 . + +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" + ] diff --git a/src/sshare/main.py b/src/sshare/main.py index 6523d6b..8198545 100644 --- a/src/sshare/main.py +++ b/src/sshare/main.py @@ -19,12 +19,12 @@ import time import tomllib import subprocess import sys -from pathlib import Path -from sshare.logger import Logger -from sshare.plugin import Plugin -from sshare.plugin import PluginManager -from sshare.version import version +from sshare import config_directory +from sshare.logger import Logger +from sshare.plugin import Plugin +from sshare.plugin import PluginManager +from sshare.version import version def main(): arg_parser = argparse.ArgumentParser( @@ -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")