-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanage.py
More file actions
144 lines (127 loc) · 4.67 KB
/
manage.py
File metadata and controls
144 lines (127 loc) · 4.67 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
import os
import sys
import shutil
import subprocess
import venv
from pathlib import Path
class FinGeniusManager:
def __init__(self):
self.base_dir = Path(__file__).parent
self.venv_dir = self.base_dir / "venv"
self.requirements_file = self.base_dir / "requirements.txt"
self.uploads_dir = self.base_dir / "uploads"
self.sample_data_dir = self.base_dir / "sample_data"
self.db_file = self.base_dir / "app.db"
self.env_file = self.base_dir / ".env"
self.python_exe = self.venv_dir / "Scripts" / "python.exe"
def create_venv(self):
"""Create virtual environment if it doesn't exist"""
print("Setting up virtual environment...")
if not self.venv_dir.exists():
venv.create(self.venv_dir, with_pip=True)
return self.python_exe.exists()
def install_requirements(self):
"""Install required packages"""
print("Installing dependencies...")
subprocess.run([
str(self.python_exe), "-m", "pip", "install",
"--no-cache-dir", "-r", str(self.requirements_file)
], check=True)
def setup_directories(self):
"""Create necessary directories"""
print("Creating directories...")
self.uploads_dir.mkdir(exist_ok=True)
self.sample_data_dir.mkdir(exist_ok=True)
def create_env_file(self):
"""Create .env file if it doesn't exist"""
if not self.env_file.exists():
print("Creating .env file...")
env_content = """FLASK_APP=run.py
FLASK_DEBUG=1
SECRET_KEY=dev-key-change-this-in-production
CLAUDE_API_KEY=your-claude-api-key-here
"""
self.env_file.write_text(env_content)
def init_database(self):
"""Initialize the database"""
print("Initializing database...")
if self.db_file.exists():
self.db_file.unlink()
subprocess.run([
str(self.python_exe), "-c",
"from app import create_app, db; "
"from app.core.models import User; "
"app = create_app(); "
"app.app_context().push(); "
"db.create_all(); "
"admin = User(username='admin', email='admin@fingenius.com', role='admin'); "
"admin.set_password('adminpass'); "
"db.session.add(admin); "
"db.session.commit()"
], check=True)
def run_app(self):
"""Run the Flask application"""
print("\nStarting FinGenius...")
subprocess.run([str(self.python_exe), "run.py"])
def clean(self):
"""Clean installation files"""
print("Cleaning installation...")
dirs_to_clean = ["__pycache__", "migrations", "venv"]
files_to_clean = ["app.db"]
for d in dirs_to_clean:
path = self.base_dir / d
if path.exists():
shutil.rmtree(path)
for f in files_to_clean:
path = self.base_dir / f
if path.exists():
path.unlink()
def install(self):
"""Full installation process"""
try:
print("Starting FinGenius installation...")
self.create_venv()
self.install_requirements()
self.setup_directories()
self.create_env_file()
self.init_database()
print("\nInstallation completed successfully!")
print("You can now run the application with: python manage.py run")
print("\nDefault login:")
print("Username: admin")
print("Password: adminpass")
except Exception as e:
print(f"Error during installation: {e}")
sys.exit(1)
def main():
manager = FinGeniusManager()
if len(sys.argv) < 2:
print("Usage: python manage.py [command]")
print("\nCommands:")
print(" install - Install FinGenius and dependencies")
print(" run - Run the application")
print(" clean - Remove all generated files")
print(" update - Update dependencies and database")
sys.exit(1)
command = sys.argv[1]
try:
if command == "install":
manager.install()
elif command == "run":
manager.run_app()
elif command == "clean":
manager.clean()
elif command == "update":
manager.install_requirements()
manager.init_database()
else:
print(f"Unknown command: {command}")
sys.exit(1)
except KeyboardInterrupt:
print("\nOperation cancelled by user")
sys.exit(1)
except Exception as e:
print(f"Error: {e}")
sys.exit(1)
if __name__ == "__main__":
main()