
import zipfile
import os
from pathlib import Path

def create_project_zip():
    """Create a zip file of the entire Django project"""
    
    # Define the zip file name
    zip_filename = "pos_254_project.zip"
    
    # Get the current directory (project root)
    project_root = Path.cwd()
    
    # Files and directories to exclude
    exclude_patterns = [
        '__pycache__',
        '*.pyc',
        '.git',
        '.idea',
        'staticfiles',
        '*.sqlite3',
        '.env',
        'venv',
        'env',
        '.DS_Store',
        'Thumbs.db',
        '*.log',
        'node_modules',
        '.replit',
        'replit.nix',
        'attached_assets',
        'poetry.lock',
        'replit_zip_error_log.txt'
    ]
    
    def should_exclude(file_path):
        """Check if file should be excluded"""
        path_str = str(file_path)
        for pattern in exclude_patterns:
            if pattern in path_str or file_path.name.startswith('.'):
                return True
        return False
    
    print(f"Creating zip file: {zip_filename}")
    
    with zipfile.ZipFile(zip_filename, 'w', zipfile.ZIP_DEFLATED) as zipf:
        for root, dirs, files in os.walk(project_root):
            # Remove excluded directories from dirs list
            dirs[:] = [d for d in dirs if not should_exclude(Path(root) / d)]
            
            for file in files:
                file_path = Path(root) / file
                
                # Skip if file should be excluded
                if should_exclude(file_path):
                    continue
                
                # Calculate relative path from project root
                relative_path = file_path.relative_to(project_root)
                
                # Add file to zip
                zipf.write(file_path, relative_path)
                print(f"Added: {relative_path}")
    
    print(f"\nZip file created successfully: {zip_filename}")
    print(f"File size: {os.path.getsize(zip_filename) / (1024*1024):.2f} MB")
    
    return zip_filename

if __name__ == "__main__":
    create_project_zip()
