From 1799f5a3c707f81b361f6e2c66031409134cb026 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Tue, 28 Feb 2023 19:33:28 +0200 Subject: [PATCH] (Added) os paths for the data and the config by default. Added if config is missing, then the hint shows its path. Updated pyproject.toml information. --- CHANGELOG.org | 4 ++++ pyproject.toml | 15 ++++++++------- src/config.py | 5 +++-- src/main.py | 22 +++++++++++++++++++--- src/notify.py | 2 +- 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.org b/CHANGELOG.org index fd7f396..fec3872 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -31,3 +31,7 @@ Updated my name to my fullname and release years. ** 1.0.2 <2023-01-15> Refactor the database class and remove function for the creating file. +** 1.1.1 <2023-02-28> + Added os paths for the data and the config by default. + Added if config is missing, then the hint shows its path. + Updated pyproject.toml information. diff --git a/pyproject.toml b/pyproject.toml index ba5b04d..9c2fc9a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "anitube-simple-notification" -version = "1.0.0" +version = "1.1.1" authors = [ { name="Kostiantyn Klochko", email="kostya_klochko@ukr.net" }, ] @@ -18,12 +18,13 @@ classifiers = [ "Operating System :: OS Independent", ] dependencies = [ - "requests", - "bs4", - "notify-py", - "rich", - "tomli", - "loguru" + "requests~=2.28.2", + "beautifulsoup4~=4.11.1", + "notify-py~=0.3.39", + "rich~=13.1.0", + "tomli~=2.0.1", + "loguru~=0.5.3", + "platformdirs~=3.0.0" ] [project.urls] diff --git a/src/config.py b/src/config.py index 5e9ae8d..1f87b98 100644 --- a/src/config.py +++ b/src/config.py @@ -24,7 +24,7 @@ This module has all for simplify work with the toml configuration file. from rich.console import Console import tomli -import os +from pathlib import PosixPath class Config: @staticmethod @@ -70,7 +70,7 @@ class Config: del config["URLS"] @staticmethod - def get_config(config_path:str, console:Console) -> dict: + def get_config(config_path:PosixPath, console:Console) -> dict: """ Read the configuration file and return dict as configuration. The configuration file must be in the application folder. @@ -81,6 +81,7 @@ class Config: config = tomli.load(file) except FileNotFoundError: console.print(f"[red][ERROR] Please, create configuration file.[/]") + console.print(f"[yellow][ERROR] The configuration file path: {config_path}.[/]") except tomli.TOMLDecodeError: console.print(f"[red][ERROR] Please, check configuration file for correctness.[/]") Config.config_validation_error(config) diff --git a/src/main.py b/src/main.py index e0bcb58..799dfea 100644 --- a/src/main.py +++ b/src/main.py @@ -25,16 +25,32 @@ from rich.console import Console from rich.progress import track import time import os +import platformdirs def main(): # Const sections. # Console initialising console = Console() + + APPNAME = "anitube-simple-notification" + APPAUTHOR = "KKlochko" + CONFIG_NAME = "config.toml" BASE_DIR = os.path.dirname(__file__) - DB_PATH = os.path.join(BASE_DIR, 'user.db') - POSTERS_PATH = os.path.join(BASE_DIR, 'posters') - CONFIG_PATH = os.path.join(BASE_DIR, 'config.toml') + DATA_DIR = platformdirs.user_data_dir(APPNAME, APPAUTHOR) + + DB_PATH = os.path.join(DATA_DIR, 'user.db') + POSTERS_PATH = os.path.join(DATA_DIR, 'posters') + + CONFIG_PATH = platformdirs.user_config_path(APPNAME, APPAUTHOR, CONFIG_NAME) + + # check for existing of dirs + if not os.path.exists(DATA_DIR): + os.makedirs(DATA_DIR) + + if not os.path.exists(CONFIG_PATH): + os.makedirs(CONFIG_PATH) + config = Config.get_config(CONFIG_PATH, console) # Here you can change testing headers to yours. diff --git a/src/notify.py b/src/notify.py index 7c8242c..f0553ab 100644 --- a/src/notify.py +++ b/src/notify.py @@ -27,7 +27,7 @@ from notifypy import Notify class Notification: """The handler of notification.""" def __init__(self, title, message, icon_path=""): - """Initialising the connection information.""" + """Initialising the notification information.""" self.title, self.message, self.icon_path = title, message, icon_path def send(self):