#!/usr/bin/env python3 """Test PS3 update application stage.""" import sys import tempfile import shutil from pathlib import Path # Add project to path sys.path.insert(0, '/data/emu/rom-groomer-python/src') from romgroomer.stages.apply_ps3_updates import ApplyPS3UpdatesStage from romgroomer.stages.base import StageContext def test_update_application(): """Test applying updates to PS3 games.""" # Configuration nps_database = "/data/emu/source/nopaystation/PS3_DLCS.tsv" pkg_archive = "/data/emu/source/nopaystation/downloads-ps3-dlc" pkg2zip_path = "/data/emu/rom-groomer-python/tools/bin/pkg2zip" # Use existing game as test (copy to temp) source_game = Path("/data/emu/ps3netsrv/GAMES/Aegis of Earth - Protonovus Assault (USA).ps3") if not source_game.exists(): print(f"Error: Test game not found: {source_game}") sys.exit(1) print(f"Testing with game: {source_game.name}") print() # Create temp directory for test with tempfile.TemporaryDirectory() as temp_dir: temp_path = Path(temp_dir) test_game = temp_path / source_game.name print(f"Copying game to temp directory...") shutil.copytree(source_game, test_game) print(f" ✓ Copied to: {test_game}") print() # Create stage print(f"Initializing ApplyPS3UpdatesStage...") stage = ApplyPS3UpdatesStage( nps_database=nps_database, pkg_archive=pkg_archive, pkg2zip_path=pkg2zip_path, apply_updates=True, apply_dlc=False, ) print(f" ✓ Stage initialized") print() # Create context context = StageContext(working_dir=temp_path) # Execute stage print(f"=" * 70) print(f"Running update application...") print(f"=" * 70) result = stage.execute(context) print() # Check results print(f"=" * 70) print(f"Test Results:") print(f"=" * 70) if (test_game / "PS3_UPDATE").exists(): print(f"✓ PS3_UPDATE directory created") # List what was added update_files = list((test_game / "PS3_UPDATE").rglob("*")) print(f" Added {len(update_files)} files/directories") for f in sorted(update_files)[:10]: # Show first 10 rel_path = f.relative_to(test_game) if f.is_file(): size = f.stat().st_size print(f" {rel_path} ({size:,} bytes)") else: print(f" {rel_path}/") else: print(f"✗ No PS3_UPDATE directory created") print(f" This might be normal if no updates were found") print() print(f"Test complete!") if __name__ == '__main__': test_update_application()