This guide helps you migrate from CAsMan v1.x to v2.0, which introduces breaking changes due to complete package modularization.
CAsMan v2.0 represents a complete architectural overhaul:
The most significant change is the new modular import structure.
# OLD (v1.x) - No longer works
from casman.parts import add_parts_interactive, get_last_part_number
# NEW (v2.x) - Required
from casman.parts.interactive import add_parts_interactive
from casman.parts.generation import get_last_part_number
# OLD (v1.x) - No longer works
from casman.assembly import build_connection_chains, print_assembly_chains
# NEW (v2.x) - Required
from casman.assembly.chains import build_connection_chains, print_assembly_chains
# OLD (v1.x) - No longer works
from casman.database import get_parts_by_criteria, init_parts_db
# NEW (v2.x) - Required
from casman.database.operations import get_parts_by_criteria
from casman.database.initialization import init_parts_db
# OLD (v1.x) - No longer works
from casman.config import get_config, load_config
# NEW (v2.x) - Required
from casman.config.core import get_config, load_config
# OLD (v1.x) - No longer works
from casman.barcode_utils import generate_barcode, create_printpage
# NEW (v2.x) - Required
from casman.barcode.generation import generate_barcode
from casman.barcode.printing import create_printpage
# OLD (v1.x) - No longer works
from casman.visualization import format_ascii_chains, get_chain_summary
# NEW (v2.x) - Required
from casman.visualization.core import format_ascii_chains, get_chain_summary
While most CLI commands remain the same, there are important changes:
# OLD (v1.x) - No longer works
casman database scan
# NEW (v2.x) - Required
casman scan connect # Full interactive scanning workflow
casman scan connection # Basic connection scanning
# NEW in v2.x - Enhanced database management
casman database clear # Clear databases with safety features
casman database clear --parts # Clear only parts database
casman database clear --assembled # Clear only assembly database
casman database print # Display formatted database contents
# Enhanced in v2.x
casman parts list # List all parts (unchanged)
casman parts add # Interactive addition with ALL option
casman parts search # NEW: Search functionality
casman parts validate # NEW: Validation tools
grep -r "from casman" your_project/
grep -r "import casman" your_project/
Update each import according to the mapping above
# Test script to verify imports work
try:
from casman.parts.interactive import add_parts_interactive
from casman.assembly.chains import build_connection_chains
from casman.database.operations import get_parts_by_criteria
print("✅ All imports successful")
except ImportError as e:
print(f"❌ Import failed: {e}")
# Replace this
casman database scan
# With this
casman scan connect
# New safety features for database management
casman database clear --parts # Safer than manual deletion
casman database print # Better than manual SQL queries
Problem: ImportError: cannot import name 'function_name' from 'casman.module'
Solution: Update the import to use the new modular structure:
# If you see this error:
# ImportError: cannot import name 'add_parts_interactive' from 'casman.parts'
# Change this:
from casman.parts import add_parts_interactive
# To this:
from casman.parts.interactive import add_parts_interactive
Problem: casman database scan
returns “command not found”
Solution: Use the new command structure:
# Old command no longer exists
casman database scan
# Use new command
casman scan connect
Problem: Configuration functions not found
Solution: Update config imports:
# Change this:
from casman.config import get_config
# To this:
from casman.config.core import get_config
CAsMan v2.0 does not include a compatibility layer for v1.x imports due to the complete architectural changes. All code must be updated to use the new modular structure.
After migrating, you can take advantage of new v2.0 features:
# New safety features in database operations
from casman.database.operations import backup_database
from casman.database.migrations import check_database_integrity
# Create backups before operations
backup_database("parts.db", "pre_migration")
# Enhanced part validation
from casman.parts.validation import validate_part_format
from casman.assembly.connections import validate_connection_rules
# Validate parts before operations
is_valid = validate_part_format("ANT-P1-00001")
# Enhanced configuration handling
from casman.config.core import get_config
from casman.config.environments import load_environment_config
# Environment-specific configurations
config = load_environment_config("production")
Create a test script to verify your migration:
#!/usr/bin/env python3
"""
CAsMan v2.0 Migration Test Script
"""
def test_imports():
"""Test that all new imports work correctly."""
try:
# Test parts imports
from casman.parts.interactive import add_parts_interactive
from casman.parts.generation import get_last_part_number
# Test assembly imports
from casman.assembly.chains import build_connection_chains
from casman.assembly.connections import validate_connection_rules
# Test database imports
from casman.database.operations import get_parts_by_criteria
from casman.database.initialization import init_parts_db
# Test configuration imports
from casman.config.core import get_config
print("✅ All imports successful")
return True
except ImportError as e:
print(f"❌ Import failed: {e}")
return False
def test_cli_commands():
"""Test that CLI commands work correctly."""
import subprocess
commands = [
["casman", "--help"],
["casman", "parts", "--help"],
["casman", "scan", "--help"],
["casman", "database", "--help"],
]
for cmd in commands:
try:
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode == 0:
print(f"✅ Command works: {' '.join(cmd)}")
else:
print(f"❌ Command failed: {' '.join(cmd)}")
return False
except FileNotFoundError:
print(f"❌ Command not found: {' '.join(cmd)}")
return False
return True
if __name__ == "__main__":
print("Testing CAsMan v2.0 Migration...")
if test_imports() and test_cli_commands():
print("\n🎉 Migration successful! CAsMan v2.0 is ready to use.")
else:
print("\n❌ Migration issues detected. Please review the errors above.")
Test key functionality manually:
# Test CLI structure
casman --help
# Test parts management
casman parts list
# Test scanning workflow
casman scan connect
# Test database management
casman database print
# Test visualization
casman visualize chains
If you encounter issues during migration:
--help
for detailed informationOnce migrated to v2.0, you’ll benefit from:
The modular v2.0 architecture provides a solid foundation for future development and significantly improves the user experience with enhanced safety features and better organization.