-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_check.py
More file actions
183 lines (152 loc) · 5.41 KB
/
setup_check.py
File metadata and controls
183 lines (152 loc) · 5.41 KB
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
#!/usr/bin/env python3
"""
Quick setup and verification script for CSV to SQL Converter
"""
import os
import sys
import subprocess
from pathlib import Path
def print_status(message, status="info"):
"""Print colored status messages."""
colors = {
"info": "\033[34m", # Blue
"success": "\033[32m", # Green
"warning": "\033[33m", # Yellow
"error": "\033[31m", # Red
"reset": "\033[0m" # Reset
}
symbols = {
"info": "ℹ",
"success": "✅",
"warning": "⚠",
"error": "❌"
}
color = colors.get(status, colors["info"])
symbol = symbols.get(status, "•")
print(f"{color}{symbol} {message}{colors['reset']}")
def check_python_version():
"""Check if Python version is compatible."""
version = sys.version_info
if version.major >= 3 and version.minor >= 8:
print_status(f"Python {version.major}.{version.minor}.{version.micro} - Compatible", "success")
return True
else:
print_status(f"Python {version.major}.{version.minor}.{version.micro} - Requires Python 3.8+", "error")
return False
def check_virtual_environment():
"""Check if virtual environment exists and is activated."""
venv_path = Path("venv")
if not venv_path.exists():
print_status("Virtual environment not found", "warning")
return False
# Check if we're in a virtual environment
if hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix):
print_status("Virtual environment is active", "success")
return True
else:
print_status("Virtual environment exists but not activated", "warning")
return False
def check_dependencies():
"""Check if required packages are installed."""
required_packages = [
"pandas", "sqlalchemy", "click", "colorama",
"tabulate", "tqdm", "pyyaml", "pymysql"
]
missing_packages = []
for package in required_packages:
try:
__import__(package.replace("-", "_"))
print_status(f"{package} - Installed", "success")
except ImportError:
print_status(f"{package} - Missing", "error")
missing_packages.append(package)
return len(missing_packages) == 0, missing_packages
def create_sample_config():
"""Create sample configuration files if they don't exist."""
config_files = {
".env": """# Database Configuration
DB_TYPE=mysql
DB_HOST=localhost
DB_PORT=3306
DB_USER=root
DB_PASSWORD=your_password_here
DB_NAME=csv_converter
# Logging
LOG_LEVEL=INFO""",
"config.yaml": """# CSV to SQL Converter Configuration
database:
type: "mysql" # mysql, postgresql, sqlite
host: "localhost"
port: 3306
username: "root"
password: "" # Set your password here or use environment variables
database: "csv_converter"
csv:
encoding: "utf-8"
chunk_size: 10000
max_varchar_length: 255
logging:
level: "INFO"
file: "csv_converter.log" """
}
for filename, content in config_files.items():
if not Path(filename).exists():
with open(filename, 'w') as f:
f.write(content)
print_status(f"Created {filename}", "success")
else:
print_status(f"{filename} already exists", "info")
def run_quick_test():
"""Run a quick functionality test."""
try:
# Test import of main modules
from csv_converter_pro import CSVConverter, DatabaseConfig
print_status("Core modules import successfully", "success")
# Test basic functionality
config = DatabaseConfig()
print_status("Configuration loading works", "success")
return True
except Exception as e:
print_status(f"Test failed: {e}", "error")
return False
def main():
"""Main setup function."""
print("🚀 CSV to SQL Converter - Setup & Verification")
print("=" * 50)
# Check Python version
if not check_python_version():
print_status("Please upgrade to Python 3.8 or higher", "error")
return False
# Check virtual environment
venv_active = check_virtual_environment()
if not venv_active:
print_status("To activate virtual environment, run:", "info")
print(" source venv/bin/activate")
print(" # or on Windows: venv\\Scripts\\activate")
# Check dependencies
deps_ok, missing = check_dependencies()
if not deps_ok:
print_status("Missing dependencies detected", "warning")
print_status("To install missing packages, run:", "info")
print(f" pip install {' '.join(missing)}")
return False
# Create sample configuration
print_status("Setting up configuration files...", "info")
create_sample_config()
# Run quick test
print_status("Running functionality test...", "info")
if run_quick_test():
print_status("All tests passed!", "success")
else:
print_status("Some tests failed", "warning")
# Provide next steps
print("\n🎯 Next Steps:")
print("1. Edit config.yaml or .env with your database credentials")
print("2. Run: python csv_converter_pro.py --help")
print("3. Try: python csv_converter_pro.py import-csv sample_employees.csv --analyze-only")
print("4. Or: python csv_converter_pro.py interactive")
print_status("Setup complete!", "success")
return True
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)