Add library push to website from the content editor

This commit is contained in:
SirBlob committed 2026-11-03 00:39:33 -05:00
1 parent ec57bd73b3
commit 0f90babb7a
13 files changed
+281 -20

No files matched your search

+34 -1
View File
@@ -1,12 +1,14 @@
import sys
from textual import on
from textual import on, work
from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.widgets import DataTable, Footer, Header, TabbedContent, TabPane
import library_push
import portfolio
from tui.books_pane import BooksPane
from tui.dialogs import ConfirmDialog
from tui.games_pane import GamesPane
from tui.media_pane import MediaPane
from tui.music_pane import MusicPane
@@ -41,6 +43,7 @@ class ContentApp(App):
BINDINGS = [
Binding("q", "quit", "Quit"),
Binding("t", "next_theme", "Theme"),
Binding("P", "push_library", "Push to website"),
*[Binding(tab_key(number), f"show_tab('{tab_id}')", label, show=False) for number, (tab_id, label) in enumerate(TABS, start=1)],
]
@@ -97,6 +100,36 @@ class ContentApp(App):
def on_mount(self):
self.focus_active_table()
def action_push_library(self):
self.notify("Comparing the library with the website...")
self.prepare_push()
@work(thread=True, exclusive=True, group="push")
def prepare_push(self):
try:
plan = library_push.plan_push()
except (OSError, ValueError) as error:
self.call_from_thread(self.notify, str(error), title="Push", severity="error", timeout=10)
return
self.call_from_thread(self.confirm_push, plan)
def confirm_push(self, plan: library_push.PushPlan):
def confirmed(should_push: bool | None):
if should_push:
self.push_library(plan)
self.push_screen(ConfirmDialog(plan.describe(), "Push", "primary"), confirmed)
@work(thread=True, exclusive=True, group="push")
def push_library(self, plan: library_push.PushPlan):
progress = lambda message: self.call_from_thread(self.notify, message)
result = library_push.run_push(plan, progress)
for message in result.errors[:5]:
self.call_from_thread(self.notify, message, title="Push", severity="warning", timeout=10)
summary = f"Pushed {result.pushed} and removed {result.removed} on {plan.target.url}"
severity = "warning" if result.errors else "information"
self.call_from_thread(self.notify, f"{summary}, {len(result.errors)} failed", title="Push", severity=severity, timeout=10)
def action_show_tab(self, tab_id: str):
self.query_one(TabbedContent).active = tab_id