File size: 9,153 Bytes
c293f7c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#!/usr/bin/env python3
"""
Final verification script for Enhanced Fake News Detection System
Comprehensive checks before deployment
"""

import os
import sys
import subprocess
import json
import time
from pathlib import Path

def run_command(cmd, timeout=30):
    """Run a command with timeout"""
    try:
        result = subprocess.run(
            cmd, shell=True, capture_output=True, 
            text=True, timeout=timeout, check=True
        )
        return True, result.stdout, result.stderr
    except subprocess.TimeoutExpired:
        return False, "", f"Command timed out after {timeout}s"
    except subprocess.CalledProcessError as e:
        return False, e.stdout, e.stderr
    except Exception as e:
        return False, "", str(e)

def check_docker_availability():
    """Check if Docker is available and running"""
    print("🐳 Checking Docker availability...")
    
    success, stdout, stderr = run_command("docker --version")
    if not success:
        print("❌ Docker not available")
        return False
    
    print(f"βœ… Docker version: {stdout.strip()}")
    
    # Check if Docker daemon is running
    success, stdout, stderr = run_command("docker ps")
    if not success:
        print("❌ Docker daemon not running")
        return False
    
    print("βœ… Docker daemon is running")
    return True

def check_project_structure():
    """Verify project structure is complete"""
    print("\nπŸ“ Checking project structure...")
    
    required_files = [
        "README.md",
        "requirements.txt", 
        "Dockerfile",
        "Dockerfile.simple",
        "docker-compose.yml",
        "docker-compose.prod.yml",
        "DEPLOYMENT_GUIDE.md",
        "backend/main_application.py",
        "backend/requirements.txt",
        "docs/README.md",
        "docs/BACKEND_ARCHITECTURE.md",
        "docs/ML_MODEL_DOCUMENTATION.md",
    ]
    
    required_dirs = [
        "backend/",
        "frontend/", 
        "docs/",
        "map/",
        "data/",
        "tests/",
        "scripts/"
    ]
    
    all_good = True
    
    for file_path in required_files:
        if os.path.exists(file_path):
            print(f"βœ… {file_path}")
        else:
            print(f"❌ Missing: {file_path}")
            all_good = False
    
    for dir_path in required_dirs:
        if os.path.isdir(dir_path):
            print(f"βœ… {dir_path}")
        else:
            print(f"❌ Missing directory: {dir_path}")
            all_good = False
    
    return all_good

def test_docker_build():
    """Test Docker build process"""
    print("\nπŸ”¨ Testing Docker build...")
    
    # Test simple build first
    print("Building simple Docker image...")
    success, stdout, stderr = run_command(
        "docker build -f Dockerfile.simple -t fake-news-test:simple .", 
        timeout=300
    )
    
    if not success:
        print(f"❌ Simple Docker build failed: {stderr}")
        return False
    
    print("βœ… Simple Docker build successful")
    
    # Clean up test image
    run_command("docker rmi fake-news-test:simple")
    
    return True

def test_docker_compose():
    """Test Docker Compose configuration"""
    print("\nπŸ™ Testing Docker Compose...")
    
    # Validate docker-compose.yml
    success, stdout, stderr = run_command("docker-compose config")
    if not success:
        print(f"❌ Docker Compose validation failed: {stderr}")
        return False
    
    print("βœ… Docker Compose configuration valid")
    
    # Validate production compose
    success, stdout, stderr = run_command("docker-compose -f docker-compose.prod.yml config")
    if not success:
        print(f"❌ Production Docker Compose validation failed: {stderr}")
        return False
    
    print("βœ… Production Docker Compose configuration valid")
    return True

def check_git_status():
    """Check git repository status"""
    print("\nπŸ“¦ Checking Git status...")
    
    # Check if we're in a git repo
    success, stdout, stderr = run_command("git status --porcelain")
    if not success:
        print("⚠️  Not a git repository or git not available")
        return True  # Not critical
    
    if stdout.strip():
        print("πŸ“ Uncommitted changes found:")
        print(stdout)
        print("πŸ’‘ Consider committing changes before deployment")
    else:
        print("βœ… Working directory is clean")
    
    # Check for commits
    success, stdout, stderr = run_command("git log --oneline -1")
    if success and stdout.strip():
        print(f"βœ… Latest commit: {stdout.strip()}")
    
    return True

def check_python_dependencies():
    """Check if Python dependencies can be resolved"""
    print("\n🐍 Checking Python dependencies...")
    
    # Check main requirements
    if os.path.exists("requirements.txt"):
        print("βœ… Main requirements.txt found")
    else:
        print("❌ Main requirements.txt missing")
        return False
    
    # Check backend requirements
    if os.path.exists("backend/requirements.txt"):
        print("βœ… Backend requirements.txt found")
    else:
        print("❌ Backend requirements.txt missing")
        return False
    
    return True

def check_documentation():
    """Verify documentation completeness"""
    print("\nπŸ“š Checking documentation...")
    
    doc_files = [
        "docs/README.md",
        "docs/BACKEND_ARCHITECTURE.md", 
        "docs/ML_MODEL_DOCUMENTATION.md",
        "docs/PROJECT_STRUCTURE.md",
        "DEPLOYMENT_GUIDE.md"
    ]
    
    all_good = True
    for doc_file in doc_files:
        if os.path.exists(doc_file):
            # Check if file has content
            with open(doc_file, 'r', encoding='utf-8') as f:
                content = f.read().strip()
                if len(content) > 100:  # Reasonable minimum
                    print(f"βœ… {doc_file} ({len(content)} chars)")
                else:
                    print(f"⚠️  {doc_file} seems too short")
        else:
            print(f"❌ Missing: {doc_file}")
            all_good = False
    
    return all_good

def generate_deployment_summary():
    """Generate deployment summary"""
    print("\nπŸ“‹ Deployment Summary:")
    print("=" * 50)
    
    # Project info
    if os.path.exists("README.md"):
        with open("README.md", 'r', encoding='utf-8') as f:
            first_line = f.readline().strip()
            print(f"Project: {first_line.replace('#', '').strip()}")
    
    # File counts
    backend_files = len([f for f in Path("backend").rglob("*.py") if f.is_file()])
    doc_files = len([f for f in Path("docs").rglob("*.md") if f.is_file()])
    
    print(f"Backend Python files: {backend_files}")
    print(f"Documentation files: {doc_files}")
    
    # Docker info
    if os.path.exists("Dockerfile"):
        print("βœ… Docker support available")
    if os.path.exists("docker-compose.yml"):
        print("βœ… Docker Compose support available")
    
    print("\nπŸš€ Deployment Options:")
    print("1. docker-compose up --build")
    print("2. docker build -f Dockerfile.simple -t fake-news .")
    print("3. pip install -r requirements.txt && cd backend && python main_application.py")
    
    print("\n🌐 Access URLs (after deployment):")
    print("- Main Dashboard: http://localhost:8080")
    print("- Interactive Map: http://localhost:8080/map/enhanced-india-heatmap.html")
    print("- API Docs: http://localhost:8080/docs")
    print("- Health Check: http://localhost:8080/health")

def main():
    """Main verification function"""
    print("πŸ” Enhanced Fake News Detection System - Final Verification")
    print("=" * 70)
    
    checks = [
        ("Project Structure", check_project_structure),
        ("Python Dependencies", check_python_dependencies),
        ("Documentation", check_documentation),
        ("Docker Availability", check_docker_availability),
        ("Docker Build", test_docker_build),
        ("Docker Compose", test_docker_compose),
        ("Git Status", check_git_status),
    ]
    
    results = []
    
    for check_name, check_func in checks:
        print(f"\n{'='*20} {check_name} {'='*20}")
        try:
            result = check_func()
            results.append((check_name, result))
        except Exception as e:
            print(f"❌ {check_name} failed with error: {e}")
            results.append((check_name, False))
    
    # Summary
    print("\n" + "="*70)
    print("πŸ“Š VERIFICATION RESULTS")
    print("="*70)
    
    passed = 0
    total = len(results)
    
    for check_name, result in results:
        status = "βœ… PASS" if result else "❌ FAIL"
        print(f"{status:<10} {check_name}")
        if result:
            passed += 1
    
    print(f"\nScore: {passed}/{total} checks passed")
    
    if passed == total:
        print("\nπŸŽ‰ ALL CHECKS PASSED!")
        print("βœ… Project is ready for deployment")
        generate_deployment_summary()
        return 0
    else:
        print(f"\n⚠️  {total - passed} checks failed")
        print("πŸ”§ Please fix the issues above before deployment")
        return 1

if __name__ == "__main__":
    sys.exit(main())