feat: Release v0.10 - Modular Architecture & External Config
- Refactor codebase into src/ (preprocessing, translation, assembly) - Add pipeline/ scripts for individual stages - Externalize configuration to config/config.yaml - Fix Cover Image preservation - Update documentation and manuals
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import argparse
|
||||
import sys
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
# Add project root to sys.path
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
||||
|
||||
from src.assembly.backfiller import BackfillEngine
|
||||
from src.assembly.builder import BilingualBuilder
|
||||
from src.translation.manifest_manager import ManifestManager
|
||||
from src.common.data_model import BookStructure
|
||||
from src.common.utils import setup_logger, ensure_directory
|
||||
from src.common.exceptions import EpubTranslatorError
|
||||
|
||||
logger = setup_logger("pipeline_assemble")
|
||||
|
||||
def run_assemble(args):
|
||||
input_path = Path(args.input_epub)
|
||||
if not input_path.exists():
|
||||
logger.error(f"Input file not found: {input_path}")
|
||||
sys.exit(1)
|
||||
|
||||
book_name = input_path.stem
|
||||
work_root = Path("work") / book_name
|
||||
structure_path = work_root / "book_structure.json"
|
||||
manifest_path = work_root / "manifest.json"
|
||||
|
||||
if not structure_path.exists() or not manifest_path.exists():
|
||||
logger.error("Missing structure or manifest. Run Step 1.")
|
||||
sys.exit(1)
|
||||
|
||||
output_dir = Path(args.output_dir)
|
||||
ensure_directory(output_dir)
|
||||
|
||||
try:
|
||||
# Load Data
|
||||
structure = BookStructure.load(structure_path)
|
||||
manager = ManifestManager(manifest_path)
|
||||
manager.load()
|
||||
|
||||
# Backfill
|
||||
logger.info(f"Backfilling translations (Mode: {args.mode})...")
|
||||
backfiller = BackfillEngine()
|
||||
updated_structure = backfiller.backfill(structure, manager.entries, mode=args.mode)
|
||||
|
||||
# Build
|
||||
logger.info("Building EPUB...")
|
||||
builder = BilingualBuilder(work_root, original_epub_path=input_path)
|
||||
output_filename = f"{book_name}_{args.mode}.epub"
|
||||
output_path = output_dir / output_filename
|
||||
|
||||
builder.build(updated_structure, output_path)
|
||||
logger.info(f"Assembly complete. Output: {output_path}")
|
||||
|
||||
except EpubTranslatorError as e:
|
||||
logger.error(f"Assembly failed: {e}")
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
logger.critical(f"Unexpected error: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Step 3: Assembly (Backfill + Build)")
|
||||
parser.add_argument("input_epub", help="Path to original EPUB")
|
||||
parser.add_argument("--output-dir", default="output", help="Output directory")
|
||||
parser.add_argument("--mode", default="bilingual", choices=["bilingual", "target_only"], help="Output mode")
|
||||
|
||||
args = parser.parse_args()
|
||||
run_assemble(args)
|
||||
Reference in New Issue
Block a user