mirror of
https://github.com/gmbrax/Pilgrim.git
synced 2026-11-10 01:20:16 +00:00
Changed the base directory where the data generated by the program to be at the home directory and also added a check to ensure the creation of the program directory
This commit is contained in:
parent
394f813f6f
commit
d114357d50
@@ -1,16 +1,47 @@
|
||||
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
|
||||
|
||||
|
||||
class Application:
|
||||
def __init__(self):
|
||||
self.config_dir = self._ensure_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