mirror of
https://github.com/gmbrax/Pilgrim.git
synced 2026-11-10 10:40:17 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b131a2f0a5 | ||
|
|
f825236c45 | ||
|
|
8f36e5a770 | ||
|
|
11e9cf6e75 |
@@ -1,36 +0,0 @@
|
|||||||
import sqlite3
|
|
||||||
import zipfile
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
|
|
||||||
from pilgrim.utils.directory_manager import DirectoryManager
|
|
||||||
|
|
||||||
|
|
||||||
class BackupService:
|
|
||||||
def __init__(self, session):
|
|
||||||
self.session = session
|
|
||||||
|
|
||||||
def create_backup(self):
|
|
||||||
db_path = DirectoryManager.get_database_path()
|
|
||||||
if not db_path.exists():
|
|
||||||
raise FileNotFoundError("No Database Found")
|
|
||||||
|
|
||||||
with self.session.connection() as conn:
|
|
||||||
raw_conn = conn.connection
|
|
||||||
dump = "\n".join(line for line in raw_conn.iterdump())
|
|
||||||
|
|
||||||
filename = DirectoryManager.get_config_directory() / "backup.zip"
|
|
||||||
diaries_root_path = DirectoryManager.get_diaries_root()
|
|
||||||
|
|
||||||
try:
|
|
||||||
with zipfile.ZipFile(filename, "w",zipfile.ZIP_DEFLATED) as zipf:
|
|
||||||
zipf.writestr("database.sql", dump)
|
|
||||||
if diaries_root_path.exists():
|
|
||||||
for file_path in diaries_root_path.rglob('*'):
|
|
||||||
if file_path.is_file():
|
|
||||||
arcname = file_path.relative_to(diaries_root_path.parent)
|
|
||||||
zipf.write(file_path, arcname=arcname)
|
|
||||||
return True, filename
|
|
||||||
except Exception as e:
|
|
||||||
return False, str(e)
|
|
||||||
|
|
||||||
@@ -14,8 +14,6 @@ from pilgrim.ui.screens.edit_diary_modal import EditDiaryModal
|
|||||||
from pilgrim.ui.screens.new_diary_modal import NewDiaryModal
|
from pilgrim.ui.screens.new_diary_modal import NewDiaryModal
|
||||||
from pilgrim.ui.screens.edit_entry_screen import EditEntryScreen
|
from pilgrim.ui.screens.edit_entry_screen import EditEntryScreen
|
||||||
|
|
||||||
from pilgrim.service.backup_service import BackupService
|
|
||||||
|
|
||||||
|
|
||||||
class DiaryListScreen(Screen):
|
class DiaryListScreen(Screen):
|
||||||
TITLE = "Pilgrim - Main"
|
TITLE = "Pilgrim - Main"
|
||||||
@@ -300,18 +298,3 @@ class DiaryListScreen(Screen):
|
|||||||
self.notify("Invalid diary ID")
|
self.notify("Invalid diary ID")
|
||||||
else:
|
else:
|
||||||
self.notify("Select a diary to open the settings")
|
self.notify("Select a diary to open the settings")
|
||||||
|
|
||||||
|
|
||||||
def action_backup(self):
|
|
||||||
session = self.app.service_manager.get_session()
|
|
||||||
if session:
|
|
||||||
backup_service = BackupService(session)
|
|
||||||
result_operation, result_data = backup_service.create_backup()
|
|
||||||
if result_operation:
|
|
||||||
self.notify(f"Backup result: {result_data}")
|
|
||||||
else:
|
|
||||||
self.notify(f"Error performing backup: {result_data}")
|
|
||||||
else:
|
|
||||||
self.notify("Error: Session not found",severity="error")
|
|
||||||
self.app.exit()
|
|
||||||
|
|
||||||
|
|||||||
@@ -37,11 +37,6 @@ class UIApp(App):
|
|||||||
"Open About Pilgrim",
|
"Open About Pilgrim",
|
||||||
screen.action_about_cmd
|
screen.action_about_cmd
|
||||||
)
|
)
|
||||||
yield SystemCommand(
|
|
||||||
"Backup Database",
|
|
||||||
"Backup the Database",
|
|
||||||
screen.action_backup
|
|
||||||
)
|
|
||||||
|
|
||||||
elif isinstance(screen, AboutScreen):
|
elif isinstance(screen, AboutScreen):
|
||||||
yield SystemCommand(
|
yield SystemCommand(
|
||||||
|
|||||||
Reference in New Issue
Block a user