mirror of
https://github.com/gmbrax/Pilgrim.git
synced 2026-11-09 17:20:17 +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
@@ -0,0 +1,3 @@
|
||||
from .directory_manager import DirectoryManager
|
||||
|
||||
__all__ = ['DirectoryManager']
|
||||
@@ -0,0 +1,39 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class DirectoryManager:
|
||||
@staticmethod
|
||||
def get_config_directory() -> Path:
|
||||
"""
|
||||
Get the ~/.pilgrim directory path.
|
||||
Creates it if it doesn't exist.
|
||||
"""
|
||||
home = Path.home()
|
||||
config_dir = home / ".pilgrim"
|
||||
config_dir.mkdir(exist_ok=True)
|
||||
os.chmod(config_dir, 0o700)
|
||||
return config_dir
|
||||
|
||||
@staticmethod
|
||||
def get_diaries_root() -> Path:
|
||||
"""Returns the path to the diaries directory."""
|
||||
diaries_dir = DirectoryManager.get_config_directory() / "diaries"
|
||||
diaries_dir.mkdir(exist_ok=True)
|
||||
os.chmod(diaries_dir, 0o700)
|
||||
return diaries_dir
|
||||
|
||||
@staticmethod
|
||||
def get_diary_directory(directory_name: str) -> Path:
|
||||
"""Returns the directory path for a specific diary."""
|
||||
return DirectoryManager.get_diaries_root() / directory_name
|
||||
|
||||
@staticmethod
|
||||
def get_diary_data_directory(directory_name: str) -> Path:
|
||||
"""Returns the data directory path for a specific diary."""
|
||||
return DirectoryManager.get_diary_directory(directory_name) / "data"
|
||||
|
||||
@staticmethod
|
||||
def get_diary_images_directory(directory_name: str) -> Path:
|
||||
"""Returns the images directory path for a specific diary."""
|
||||
return DirectoryManager.get_diary_data_directory(directory_name) / "images"
|
||||
Reference in New Issue
Block a user