mirror of https://github.com/gmbrax/Pilgrim.git
Move get_database_path from database.py to directory_manager.py
This commit is contained in:
parent
3843be6e13
commit
fe35cb93bd
|
|
@ -5,36 +5,14 @@ from pathlib import Path
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
|
|
||||||
Base = declarative_base()
|
Base = declarative_base()
|
||||||
|
|
||||||
def get_database_path() -> Path:
|
|
||||||
"""
|
|
||||||
Get the database file path following XDG Base Directory specification.
|
|
||||||
Creates the directory if it doesn't exist.
|
|
||||||
"""
|
|
||||||
# Get home directory
|
|
||||||
home = Path.home()
|
|
||||||
|
|
||||||
# Create .pilgrim directory if it doesn't exist
|
|
||||||
pilgrim_dir = home / ".pilgrim"
|
|
||||||
pilgrim_dir.mkdir(exist_ok=True)
|
|
||||||
|
|
||||||
# Database file path
|
|
||||||
db_path = pilgrim_dir / "database.db"
|
|
||||||
|
|
||||||
# If database doesn't exist in new location but exists in current directory,
|
|
||||||
# migrate it
|
|
||||||
if not db_path.exists():
|
|
||||||
current_db = Path("database.db")
|
|
||||||
if current_db.exists():
|
|
||||||
shutil.copy2(current_db, db_path)
|
|
||||||
print(f"Database migrated from {current_db} to {db_path}")
|
|
||||||
|
|
||||||
return db_path
|
|
||||||
|
|
||||||
class Database:
|
class Database:
|
||||||
def __init__(self):
|
def __init__(self,):
|
||||||
db_path = get_database_path()
|
db_path = "./"
|
||||||
self.engine = create_engine(
|
self.engine = create_engine(
|
||||||
f"sqlite:///{db_path}",
|
f"sqlite:///{db_path}",
|
||||||
echo=False,
|
echo=False,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -37,3 +38,26 @@ class DirectoryManager:
|
||||||
def get_diary_images_directory(directory_name: str) -> Path:
|
def get_diary_images_directory(directory_name: str) -> Path:
|
||||||
"""Returns the images directory path for a specific diary."""
|
"""Returns the images directory path for a specific diary."""
|
||||||
return DirectoryManager.get_diary_data_directory(directory_name) / "images"
|
return DirectoryManager.get_diary_data_directory(directory_name) / "images"
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_database_path() -> Path:
|
||||||
|
"""
|
||||||
|
Get the database file path following XDG Base Directory specification.
|
||||||
|
Creates the directory if it doesn't exist.
|
||||||
|
"""
|
||||||
|
|
||||||
|
pilgrim_dir = DirectoryManager.get_config_directory()
|
||||||
|
pilgrim_dir.mkdir(exist_ok=True)
|
||||||
|
|
||||||
|
# Database file path
|
||||||
|
db_path = pilgrim_dir / "database.db"
|
||||||
|
|
||||||
|
# If database doesn't exist in new location but exists in current directory,
|
||||||
|
# migrate it
|
||||||
|
if not db_path.exists():
|
||||||
|
current_db = Path("database.db")
|
||||||
|
if current_db.exists():
|
||||||
|
shutil.copy2(current_db, db_path)
|
||||||
|
print(f"Database migrated from {current_db} to {db_path}")
|
||||||
|
|
||||||
|
return db_path
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue