Configuration directory abstraction
This commit is contained in:
parent
80057f151a
commit
babba91ca2
2 changed files with 33 additions and 13 deletions
26
src/sshare/config_directory.py
Normal file
26
src/sshare/config_directory.py
Normal 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"
|
||||||
|
]
|
|
@ -19,12 +19,12 @@ import time
|
||||||
import tomllib
|
import tomllib
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from sshare.logger import Logger
|
from sshare import config_directory
|
||||||
from sshare.plugin import Plugin
|
from sshare.logger import Logger
|
||||||
from sshare.plugin import PluginManager
|
from sshare.plugin import Plugin
|
||||||
from sshare.version import version
|
from sshare.plugin import PluginManager
|
||||||
|
from sshare.version import version
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
arg_parser = argparse.ArgumentParser(
|
arg_parser = argparse.ArgumentParser(
|
||||||
|
@ -38,8 +38,7 @@ def main():
|
||||||
help="Specify location of config file to use"
|
help="Specify location of config file to use"
|
||||||
)
|
)
|
||||||
arguments, _ = arg_parser.parse_known_args()
|
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.LOCATION / "config.toml"), mode="rb") as file:
|
||||||
with open(arguments.config or (config_directory / "config.toml"), mode="rb") as file:
|
|
||||||
config = tomllib.load(file)
|
config = tomllib.load(file)
|
||||||
config["config"] = config.get("config", {})
|
config["config"] = config.get("config", {})
|
||||||
config["flags" ] = config.get("flags", {})
|
config["flags" ] = config.get("flags", {})
|
||||||
|
@ -89,12 +88,7 @@ def main():
|
||||||
sys.dont_write_bytecode = True
|
sys.dont_write_bytecode = True
|
||||||
plugins.add_from(
|
plugins.add_from(
|
||||||
Plugin.external,
|
Plugin.external,
|
||||||
*[
|
*config_directory.plugins(),
|
||||||
path for
|
|
||||||
path in
|
|
||||||
(config_directory / "plugins").iterdir()
|
|
||||||
if path.is_file() and path.suffix == ".py"
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
sys.dont_write_bytecode = False
|
sys.dont_write_bytecode = False
|
||||||
plugins.activate("logger")
|
plugins.activate("logger")
|
||||||
|
|
Loading…
Reference in a new issue