From 1dce152bbe25f8c0c6cd6d4b21523d84eb749314 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Fri, 17 Mar 2023 16:55:49 +0200 Subject: [PATCH] (Added) the configuration to the application. Moved database file to the user data directory. --- CHANGELOG.org | 3 +++ poetry.lock | 18 ++++++++++++- pyproject.toml | 1 + tui_rsync/config/__init__.py | 2 ++ tui_rsync/config/app.py | 52 ++++++++++++++++++++++++++++++++++++ tui_rsync/models/models.py | 4 ++- 6 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 tui_rsync/config/__init__.py create mode 100644 tui_rsync/config/app.py diff --git a/CHANGELOG.org b/CHANGELOG.org index a716a1e..31f3afe 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -23,4 +23,7 @@ Added *path checking* function. ** 0.6.1 <2023-03-12 Sun> Added the *dry-run* flag to the *sync one* function. +** 0.7.0 <2023-03-17 Fri> + Added the configuration to the application. + Moved database file to the user data directory. diff --git a/poetry.lock b/poetry.lock index 561b1a1..37cbd67 100644 --- a/poetry.lock +++ b/poetry.lock @@ -75,6 +75,22 @@ files = [ {file = "peewee-3.15.4.tar.gz", hash = "sha256:2581520c8dfbacd9d580c2719ae259f0637a9e46eda47dfc0ce01864c6366205"}, ] +[[package]] +name = "platformdirs" +version = "3.1.1" +description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." +category = "main" +optional = false +python-versions = ">=3.7" +files = [ + {file = "platformdirs-3.1.1-py3-none-any.whl", hash = "sha256:e5986afb596e4bb5bde29a79ac9061aa955b94fca2399b7aaac4090860920dd8"}, + {file = "platformdirs-3.1.1.tar.gz", hash = "sha256:024996549ee88ec1a9aa99ff7f8fc819bb59e2c3477b410d90a16d32d6e707aa"}, +] + +[package.extras] +docs = ["furo (>=2022.12.7)", "proselint (>=0.13)", "sphinx (>=6.1.3)", "sphinx-autodoc-typehints (>=1.22,!=1.23.4)"] +test = ["appdirs (==1.4.4)", "covdefaults (>=2.2.2)", "pytest (>=7.2.1)", "pytest-cov (>=4)", "pytest-mock (>=3.10)"] + [[package]] name = "pyfzf" version = "0.3.1" @@ -145,4 +161,4 @@ test = ["black (>=22.3.0,<23.0.0)", "coverage (>=6.2,<7.0)", "isort (>=5.0.6,<6. [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "1cd42aa3f295e2a1c11c491125b55a32bdb6878a9e0f262c068397a6ce941a89" +content-hash = "63d5db59d0d54f5818a8274de848b03549d5df693c2310b67743e7e6c9e1968e" diff --git a/pyproject.toml b/pyproject.toml index 5302fc1..2e7eaf5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,6 +15,7 @@ rich = "^13.3.1" typer = "^0.7.0" peewee = "^3.15.4" pyfzf = "^0.3.1" +platformdirs = "^3.1.1" [build-system] requires = ["poetry-core"] diff --git a/tui_rsync/config/__init__.py b/tui_rsync/config/__init__.py new file mode 100644 index 0000000..3e9ca50 --- /dev/null +++ b/tui_rsync/config/__init__.py @@ -0,0 +1,2 @@ +from config.app import App + diff --git a/tui_rsync/config/app.py b/tui_rsync/config/app.py new file mode 100644 index 0000000..91ffe53 --- /dev/null +++ b/tui_rsync/config/app.py @@ -0,0 +1,52 @@ +################################################################################ +# Copyright (C) 2023 Kostiantyn Klochko # +# # +# This file is part of tui-rsync. # +# # +# tui-rsync is free software: you can redistribute it and/or modify it under # +# uthe 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. # +# # +# tui-rsync 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 # +# tui-rsync. If not, see . # +################################################################################ + +import platformdirs +import os + +class App: + """ + Configuration of the tui-rsync + """ + __APP_NAME = "tui-rsync" + __APP_AUTHOR = "KKlochko" + __DB_NAME = "sync.db" + + def get_db_path(self): + path = platformdirs.user_data_path( + self.__APP_NAME, + self.__APP_AUTHOR, + self.__DB_NAME + ) + App.safe_create_path(self.get_data_dir()) + return path + + def get_data_dir(self): + return platformdirs.user_data_dir( + self.__APP_NAME, + self.__APP_AUTHOR, + ) + + @staticmethod + def safe_create_path(path): + """ + Create path's folders if they do not exist + """ + if not os.path.exists(path): + os.makedirs(path) diff --git a/tui_rsync/models/models.py b/tui_rsync/models/models.py index 9650476..7ba201f 100644 --- a/tui_rsync/models/models.py +++ b/tui_rsync/models/models.py @@ -18,9 +18,11 @@ ################################################################################ from peewee import * +from config.app import App import os -db = SqliteDatabase('sync.db') +app = App() +db = SqliteDatabase(app.get_db_path()) class BaseModel(Model): class Meta: