Improve EPUB restoration, book terminology and Calibre QA workflow
This commit is contained in:
@@ -38,8 +38,11 @@ class ManifestManager:
|
||||
try:
|
||||
# Pydantic v2: model_dump(mode='json') or just list dump
|
||||
data = [entry.model_dump(mode='json') for entry in self.entries]
|
||||
with open(self.manifest_path, 'w', encoding='utf-8') as f:
|
||||
self.manifest_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
temp = self.manifest_path.with_suffix('.tmp')
|
||||
with open(temp, 'w', encoding='utf-8') as f:
|
||||
json.dump(data, f, indent=2, ensure_ascii=False)
|
||||
temp.replace(self.manifest_path)
|
||||
logger.info(f"Saved {len(self.entries)} entries to manifest.")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to save manifest: {e}")
|
||||
@@ -50,16 +53,18 @@ class ManifestManager:
|
||||
Adds new entries to the manifest.
|
||||
If an entry with the same ID exists, it keeps the EXISTING one (to preserve translations).
|
||||
"""
|
||||
count = 0
|
||||
# Re-extraction is authoritative for source text/maps. Keep a translation
|
||||
# only if both stayed identical; remove stale entries after force-clean.
|
||||
reconciled = []
|
||||
for entry in new_entries:
|
||||
if entry.entry_id not in self._entries_map:
|
||||
self.entries.append(entry)
|
||||
self._entries_map[entry.entry_id] = entry
|
||||
count += 1
|
||||
|
||||
if count > 0:
|
||||
logger.info(f"Added {count} new entries to manifest.")
|
||||
|
||||
previous = self._entries_map.get(entry.entry_id)
|
||||
if previous and previous.original_text == entry.original_text and previous.placeholders == entry.placeholders:
|
||||
reconciled.append(previous)
|
||||
else:
|
||||
reconciled.append(entry)
|
||||
self.entries = reconciled
|
||||
self._rebuild_map()
|
||||
|
||||
def update_translation(self, entry_id: str, translation: str):
|
||||
"""Updates translation for a specific entry."""
|
||||
if entry_id in self._entries_map:
|
||||
|
||||
Reference in New Issue
Block a user