mirror of
https://github.com/gmbrax/Pilgrim.git
synced 2026-11-10 01:20:16 +00:00
Implemented directory management and improved TravelDiary and Photo handling logic.
- Added `DirectoryManager` utility for consistent directory operations. - Introduced directory name sanitization and uniqueness enforcement for `TravelDiary`. - Updated `TravelDiaryService` with enhanced creation, update, and deletion workflows, including filesystem management. - Improved `PhotoService` to hash files, copy photos to specific diary directories, and manage updates safely. - Refined error handling and cascaded changes across related entities (e.g., `Entry` relationships).
This commit is contained in:
parent
b1e83aabbb
commit
090bbeda1a
@@ -1,47 +1,18 @@
|
||||
from pilgrim.database import Database
|
||||
from pilgrim.service.servicemanager import ServiceManager
|
||||
from pilgrim.ui.ui import UIApp
|
||||
from pathlib import Path
|
||||
import os
|
||||
import sys
|
||||
from pilgrim.utils import DirectoryManager
|
||||
|
||||
|
||||
class Application:
|
||||
def __init__(self):
|
||||
self.config_dir = self._ensure_config_directory()
|
||||
self.config_dir = DirectoryManager.get_config_directory()
|
||||
self.database = Database()
|
||||
session = self.database.session()
|
||||
session_manager = ServiceManager()
|
||||
session_manager.set_session(session)
|
||||
self.ui = UIApp(session_manager)
|
||||
|
||||
def _ensure_config_directory(self) -> Path:
|
||||
"""
|
||||
Ensures the ~/.pilgrim directory exists and has the correct permissions.
|
||||
Creates it if it doesn't exist.
|
||||
Returns the Path object for the config directory.
|
||||
"""
|
||||
home = Path.home()
|
||||
config_dir = home / ".pilgrim"
|
||||
|
||||
try:
|
||||
# Create directory if it doesn't exist
|
||||
config_dir.mkdir(exist_ok=True)
|
||||
|
||||
# Ensure correct permissions (rwx for user only)
|
||||
os.chmod(config_dir, 0o700)
|
||||
|
||||
# Create an empty .gitignore if it doesn't exist
|
||||
gitignore = config_dir / ".gitignore"
|
||||
if not gitignore.exists():
|
||||
gitignore.write_text("*\n")
|
||||
|
||||
return config_dir
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error setting up Pilgrim configuration directory: {str(e)}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
def run(self):
|
||||
self.database.create()
|
||||
self.ui.run()
|
||||
|
||||
Reference in New Issue
Block a user