File size: 6,906 Bytes
95e10ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""

Verification script for HealthGuard-AI deployment.

This script checks if all components are working correctly.

"""

import os
import sys
import importlib
from datetime import datetime

def check_python_version():
    """Check if Python version is compatible."""
    print("=== Python Version Check ===")
    version = sys.version
    print(f"Python version: {version}")
    
    # Check if it's Python 3.7 or higher
    if sys.version_info >= (3, 7):
        print("βœ“ Python version is compatible")
        return True
    else:
        print("βœ— Python version is not compatible (requires 3.7+)")
        return False

def check_environment_variables():
    """Check if required environment variables are set."""
    print("\n=== Environment Variables Check ===")
    
    required_vars = ['MONGODB_URI']
    optional_vars = ['SECRET_KEY', 'MONGODB_DB']
    
    for var in required_vars:
        value = os.getenv(var)
        if value:
            print(f"βœ“ {var}: Set")
        else:
            print(f"βœ— {var}: Not set (REQUIRED)")
    
    for var in optional_vars:
        value = os.getenv(var)
        if value:
            print(f"βœ“ {var}: Set")
        else:
            print(f"⚠ {var}: Not set (optional)")
    
    return all(os.getenv(var) for var in required_vars)

def check_required_packages():
    """Check if all required packages are installed."""
    print("\n=== Required Packages Check ===")
    
    required_packages = [
        'flask',
        'pymongo',
        'bcrypt',
        'pandas',
        'reportlab',
        'flask_pymongo',
        'flask_session',
        'python-dotenv',
        'certifi'
    ]
    
    missing_packages = []
    
    for package in required_packages:
        try:
            importlib.import_module(package)
            print(f"βœ“ {package}: Installed")
        except ImportError:
            print(f"βœ— {package}: Not installed")
            missing_packages.append(package)
    
    if missing_packages:
        print(f"\nMissing packages: {', '.join(missing_packages)}")
        print("Install them with: pip install " + " ".join(missing_packages))
        return False
    else:
        print("βœ“ All required packages are installed")
        return True

def check_file_structure():
    """Check if required files and directories exist."""
    print("\n=== File Structure Check ===")
    
    required_files = [
        'app.py',
        'requirements.txt',
        'debug_routes.py',
        'logging_config.py'
    ]
    
    required_dirs = [
        'templates',
        'static',
        'saved models'
    ]
    
    missing_files = []
    missing_dirs = []
    
    for file in required_files:
        if os.path.isfile(file):
            print(f"βœ“ {file}: Exists")
        else:
            print(f"βœ— {file}: Missing")
            missing_files.append(file)
    
    for directory in required_dirs:
        if os.path.isdir(directory):
            print(f"βœ“ {directory}: Exists")
        else:
            print(f"βœ— {directory}: Missing")
            missing_dirs.append(directory)
    
    if missing_files or missing_dirs:
        print(f"\nMissing items: {', '.join(missing_files + missing_dirs)}")
        return False
    else:
        print("βœ“ All required files and directories exist")
        return True

def check_model_files():
    """Check if model files exist."""
    print("\n=== Model Files Check ===")
    
    model_dir = 'saved models'
    required_models = [
        'diabetes_model.sav',
        'heart_disease_model.sav',
        'parkinsons_model.sav'
    ]
    
    if not os.path.isdir(model_dir):
        print(f"βœ— {model_dir}: Directory not found")
        return False
    
    missing_models = []
    
    for model in required_models:
        model_path = os.path.join(model_dir, model)
        if os.path.isfile(model_path):
            print(f"βœ“ {model}: Exists")
        else:
            print(f"βœ— {model}: Missing")
            missing_models.append(model)
    
    if missing_models:
        print(f"\nMissing models: {', '.join(missing_models)}")
        return False
    else:
        print("βœ“ All model files exist")
        return True

def check_template_files():
    """Check if template files exist."""
    print("\n=== Template Files Check ===")
    
    template_dir = 'templates'
    required_templates = [
        'index.html',
        'auth/login.html',
        'auth/register.html',
        'user/dashboard.html'
    ]
    
    if not os.path.isdir(template_dir):
        print(f"βœ— {template_dir}: Directory not found")
        return False
    
    missing_templates = []
    
    for template in required_templates:
        template_path = os.path.join(template_dir, template)
        if os.path.isfile(template_path):
            print(f"βœ“ {template}: Exists")
        else:
            # Check in subdirectories
            found = False
            for root, dirs, files in os.walk(template_dir):
                if template in files:
                    print(f"βœ“ {template}: Exists (in {root})")
                    found = True
                    break
            if not found:
                print(f"βœ— {template}: Missing")
                missing_templates.append(template)
    
    if missing_templates:
        print(f"\nMissing templates: {', '.join(missing_templates)}")
        return False
    else:
        print("βœ“ All required template files exist")
        return True

def main():
    """Main verification function."""
    print("HealthGuard-AI Deployment Verification")
    print("=" * 40)
    print(f"Time: {datetime.now()}")
    print(f"Working directory: {os.getcwd()}")
    print()
    
    checks = [
        check_python_version,
        check_environment_variables,
        check_required_packages,
        check_file_structure,
        check_model_files,
        check_template_files
    ]
    
    results = []
    for check in checks:
        try:
            result = check()
            results.append(result)
            print()
        except Exception as e:
            print(f"Error during {check.__name__}: {e}")
            results.append(False)
            print()
    
    # Summary
    print("=" * 40)
    print("Verification Summary:")
    passed = sum(results)
    total = len(results)
    print(f"Checks passed: {passed}/{total}")
    
    if all(results):
        print("βœ“ All checks passed! Deployment should work correctly.")
        return True
    else:
        print("βœ— Some checks failed. Please fix the issues before deployment.")
        return False

if __name__ == "__main__":
    success = main()
    sys.exit(0 if success else 1)