Spaces:
Runtime error
Runtime error
Legacy Code Removal Plan for OMIRL Web Services
Overview
After successful migration to the new web services architecture, we can now safely remove legacy OMIRL-specific code that has been replaced by the generic architecture.
Migration Status β
- β OMIRL adapter migrated to use new architecture via compatibility layer
- β All integration tests passing
- β All compatibility tests passing
- β Performance validated
- β Zero breaking changes confirmed
Files Safe to Remove
1. Core Legacy Files (OMIRL-Specific)
services/web/browser.py (468 lines)
- β SAFE TO REMOVE
- Replaced by:
services/web/generic_browser.py+services/web/configs/omirl_config.py - All OMIRL-specific browser knowledge moved to configuration
- No longer used by OMIRL adapter (uses compat layer)
services/web/table_scraper.py (465 lines)
- β SAFE TO REMOVE
- Replaced by:
services/web/generic_table.py+services/web/adapters/omirl_adapter.py - All OMIRL table scraping logic preserved in new architecture
- No longer used by OMIRL adapter (uses compat layer)
2. Files That Need to Stay
services/web/compat.py
- β KEEP - Provides backward compatibility layer
- Used by OMIRL adapter for seamless migration
- Wraps new architecture with old API
services/web/configs/omirl_config.py
- β KEEP - Contains all preserved OMIRL knowledge
- Essential for new architecture functionality
- Centralizes all OMIRL-specific configuration
services/web/adapters/omirl_adapter.py
- β KEEP - New OMIRL implementation using generic components
- Core of the new architecture
- Provides same functionality as old files but more maintainable
services/web/generic_*.py and base.py
- β KEEP - Core new architecture components
- Generic, reusable for future websites
- Foundation of the new system
Files That Reference Legacy Code
Files Still Using Legacy Imports (Need Updates)
scripts/discovery/test_massimi_precipitazioni.py
- Current:
from services.web.table_scraper import fetch_omirl_massimi_precipitazioni - Change to:
from services.web.compat import fetch_omirl_massimi_precipitazioni
- Current:
scripts/discovery/test_valori_stazioni_after_changes.py
- Current:
from services.web.table_scraper import fetch_omirl_stations - Change to:
from services.web.compat import fetch_omirl_stations
- Current:
services/media/init.py (Line 52-53)
- Current:
from services.web.browser import get_browser_context - Current:
from services.web.table_scraper import extract_table_data - Note: This needs investigation - media services might need different solution
- Current:
Test Files Using Legacy Imports
tests/omirl/test_fast.py
- Uses
@patch('services.web.table_scraper.fetch_omirl_stations') - Change to:
@patch('services.web.compat.fetch_omirl_stations')
- Uses
tests/test_omirl_implementation.py
- Uses
from services.web.browser import _browser_manager - Change to: Use new architecture browser management
- Uses
tests/omirl/performance_analysis.py
- Uses
from services.web.browser import close_all_browser_sessions - Change to:
from services.web.compat import close_all_browser_sessions
- Uses
Removal Steps (Safe Order)
Phase 1: Update Remaining References
- Update discovery scripts to use compat layer
- Update test files to use compat layer
- Investigate and fix media services imports
- Run full test suite to validate changes
Phase 2: Remove Legacy Files
- Move
browser.pytobrowser_legacy.py(backup) - Move
table_scraper.pytotable_scraper_legacy.py(backup) - Run full test suite
- If all tests pass, delete backup files
Phase 3: Clean Up (Optional)
- Remove any remaining references to old files
- Update documentation
- Remove backup files after confidence period
Risk Assessment
Low Risk β
- Legacy files are no longer used by production OMIRL adapter
- Compatibility layer provides identical API
- All functionality preserved in new architecture
- Easy rollback by renaming files back
Medium Risk β οΈ
- Some test files need updates
- Discovery scripts need updates
- Media services import needs investigation
High Risk β
- None identified - migration was successful
Validation Plan
Before Removal
# Ensure all current tests pass
python tests/test_omirl_integration.py
python tests/omirl/test_adapter_integration.py
python tests/services/test_compatibility.py
After Each Step
# Validate specific functionality
python -c "from services.web.compat import fetch_omirl_stations; print('β
Import works')"
python tests/test_omirl_integration.py
Final Validation
# Complete integration test
python tests/services/test_integration.py
Benefits of Removal
- Reduced Codebase: ~933 lines of legacy code removed
- No Confusion: Only one way to do OMIRL scraping
- Easier Maintenance: Generic architecture easier to extend
- Better Testing: New architecture has comprehensive test coverage
- Future-Proof: Ready for additional websites
Rollback Plan
If issues discovered after removal:
- Restore files from git:
git checkout HEAD -- services/web/browser.py services/web/table_scraper.py - Update OMIRL adapter imports back to legacy files
- Investigate and fix new architecture issues
- Re-attempt removal after fixes
Success Criteria
Removal is successful when:
- All OMIRL functionality works unchanged
- All tests pass
- No import errors
- No references to removed files
- New architecture handles all use cases
- Performance maintained or improved