From d19406d3b450557f0378fcac8f73666e516f505a Mon Sep 17 00:00:00 2001 From: Hellow <74311245+HeIIow2@users.noreply.github.com> Date: Tue, 13 Feb 2024 21:43:29 +0100 Subject: [PATCH] implemented base dir for all files --- publish_meetups/__init__.py | 7 ------- publish_meetups/feeds/mastodon_feed.py | 4 ++-- publish_meetups/utils/__init__.py | 9 ++++++--- publish_meetups/utils/config.py | 6 ++---- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/publish_meetups/__init__.py b/publish_meetups/__init__.py index 8585402..e69de29 100644 --- a/publish_meetups/__init__.py +++ b/publish_meetups/__init__.py @@ -1,7 +0,0 @@ -from pathlib import Path -import json -import logging - -import toml - -from .utils import config diff --git a/publish_meetups/feeds/mastodon_feed.py b/publish_meetups/feeds/mastodon_feed.py index 1bea007..daa8416 100644 --- a/publish_meetups/feeds/mastodon_feed.py +++ b/publish_meetups/feeds/mastodon_feed.py @@ -3,12 +3,12 @@ from pathlib import Path from mastodon import Mastodon from . import Feed -from ..utils import PROGRAM_NAME, prompt, config +from ..utils import PROGRAM_DATA_DIR, prompt, config class MastodonFeed(Feed): __config_name__ = "mastodon" - CLIENTCRED_PATH: Path = config.CONFIG_PATH.joinpath("mastodon_clientcred.secret") + CLIENTCRED_PATH: Path = PROGRAM_DATA_DIR.joinpath("mastodon_clientcred.secret") @classmethod def prompt_auth(cls) -> dict: diff --git a/publish_meetups/utils/__init__.py b/publish_meetups/utils/__init__.py index 2c3f772..32a1ab9 100644 --- a/publish_meetups/utils/__init__.py +++ b/publish_meetups/utils/__init__.py @@ -1,9 +1,12 @@ import logging +import platformdirs + logging.basicConfig(level=logging.INFO) - - PROGRAM_NAME: str = "publish-meetups" +PROGRAM_DATA_DIR: str = platformdirs.user_config_path(appname=PROGRAM_NAME) +PROGRAM_DATA_DIR.mkdir(parents=True, exist_ok=True) -__all__ = ["prompt", "CONFIG_PATH", "PROGRAM_NAME", "errors", "config"] + +__all__ = ["prompt", "PROGRAM_DATA_DIR", "PROGRAM_NAME", "errors", "config"] diff --git a/publish_meetups/utils/config.py b/publish_meetups/utils/config.py index d05bff1..d8d1954 100644 --- a/publish_meetups/utils/config.py +++ b/publish_meetups/utils/config.py @@ -3,7 +3,7 @@ import logging import toml import platformdirs -from . import PROGRAM_NAME +from . import PROGRAM_DATA_DIR, PROGRAM_NAME logger = logging.getLogger("config") _config: dict = { @@ -17,9 +17,7 @@ _config: dict = { } -CONFIG_PATH = platformdirs.user_config_path(appname=PROGRAM_NAME) -CONFIG_PATH.mkdir(parents=True, exist_ok=True) -CONFIG_FILE = CONFIG_PATH / f"{PROGRAM_NAME}.toml" +CONFIG_FILE = PROGRAM_DATA_DIR / f"{PROGRAM_NAME}.toml" logger.info(f"Config file: {CONFIG_FILE}")