Skip to content

Commit

Permalink
Change data storage to AppData
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexeh committed Mar 13, 2024
1 parent 4a5d578 commit 958d4e4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
10 changes: 9 additions & 1 deletion joystick_diagrams/__main__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import logging
from logging.handlers import RotatingFileHandler
from pathlib import Path

from joystick_diagrams import app_init
from joystick_diagrams.utils import create_directory, data_root

log_path = Path.joinpath(data_root(), "logs")
create_directory(str(log_path))

logging.basicConfig(
level=logging.INFO,
format="%(module)s %(filename)s - %(asctime)s - %(levelname)s - %(message)s",
handlers=[
logging.StreamHandler(),
RotatingFileHandler(
"application.log", mode="a", maxBytes=5 * 1000000, backupCount=1
str(Path.joinpath(log_path, "application.log")),
mode="a",
maxBytes=5 * 1000000,
backupCount=1,
),
],
)
Expand Down
5 changes: 3 additions & 2 deletions joystick_diagrams/db/db_connection.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import os
from sqlite3 import Connection, connect

from joystick_diagrams.utils import data_root

DB_DIR = "data"
DB_NAME = "joystick_diagrams.db"


def connection() -> Connection:
path = os.path.join(os.getcwd(), DB_DIR, DB_NAME)
path = str(data_root().joinpath(DB_DIR, DB_NAME))
connection = connect(path)
return connection
2 changes: 1 addition & 1 deletion joystick_diagrams/db/db_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
def init() -> None:
_logger.info("Initialising datastores")

utils.create_directory("data")
utils.create_directory(utils.data_root().joinpath("data"))
db_device_management.create_new_db_if_not_exist()
db_bind_text.create_new_db_if_not_exist()
db_plugin_data.create_new_db_if_not_exist()
Expand Down
11 changes: 10 additions & 1 deletion joystick_diagrams/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@

_logger = logging.getLogger(__name__)

JOYSTICK_DIAGRAMS_DATA_DIR = "Joystick Diagrams"


def data_root() -> Path:
"""Returns the user data path for storage of data"""
return Path.joinpath(
Path().home(), "AppData", "Roaming", JOYSTICK_DIAGRAMS_DATA_DIR
)


def create_directory(directory) -> None:
try:
Expand All @@ -15,7 +24,7 @@ def create_directory(directory) -> None:


def install_root() -> str:
"""Returns the currently root directory of the package
"""Returns the current root directory of the package i.e. installation location
"" in local development environments
"path_to_frozen_app_exe" in frozen environment
Expand Down

0 comments on commit 958d4e4

Please sign in to comment.