(Added) the configuration to the application.

Moved database file to the user data directory.
dev
KKlochko 2 years ago
parent 353d1ec478
commit 1dce152bbe

@ -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.

18
poetry.lock generated

@ -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"

@ -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"]

@ -0,0 +1,2 @@
from config.app import App

@ -0,0 +1,52 @@
################################################################################
# Copyright (C) 2023 Kostiantyn Klochko <kostya_klochko@ukr.net> #
# #
# 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 <https://www.gnu.org/licenses/>. #
################################################################################
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)

@ -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:

Loading…
Cancel
Save