Update to v2.1.1 - Clean Design
This commit is contained in:
parent
de25b3e19c
commit
709f362194
20 changed files with 8127 additions and 191 deletions
94
fix_db_path.py
Normal file
94
fix_db_path.py
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
Quick fix script for database path issue
|
||||
Fixes the main.py file to use absolute paths
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
def fix_main_py():
|
||||
"""Fix main.py to use absolute database path"""
|
||||
|
||||
main_file = 'main.py'
|
||||
|
||||
if not os.path.exists(main_file):
|
||||
print("❌ main.py not found in current directory")
|
||||
print(" Run this script from the urio folder")
|
||||
sys.exit(1)
|
||||
|
||||
print("🔧 Fixing database path in main.py...")
|
||||
|
||||
# Read the file
|
||||
with open(main_file, 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
# Check if already fixed
|
||||
if 'BASE_DIR = os.path.abspath(os.path.dirname(__file__))' in content:
|
||||
print("✅ main.py is already fixed!")
|
||||
return
|
||||
|
||||
# Fix 1: Update Config class
|
||||
old_config = '''class Config:
|
||||
"""Flask configuration."""
|
||||
SCHEDULER_API_ENABLED = True
|
||||
SQLALCHEMY_DATABASE_URI = os.getenv("DATABASE_URL", "sqlite:///instance/transfer_stats.db")'''
|
||||
|
||||
new_config = '''class Config:
|
||||
"""Flask configuration."""
|
||||
SCHEDULER_API_ENABLED = True
|
||||
# Use absolute path for database
|
||||
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
|
||||
INSTANCE_DIR = os.path.join(BASE_DIR, 'instance')
|
||||
SQLALCHEMY_DATABASE_URI = os.getenv("DATABASE_URL", f"sqlite:///{os.path.join(INSTANCE_DIR, 'transfer_stats.db')}")'''
|
||||
|
||||
if old_config in content:
|
||||
content = content.replace(old_config, new_config)
|
||||
print("✅ Updated Config class with absolute paths")
|
||||
|
||||
# Fix 2: Ensure instance folder creation happens before app init
|
||||
old_init = '''# --- Flask App Initialization ---
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(Config)
|
||||
|
||||
# Ensure instance folder exists
|
||||
instance_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'instance')
|
||||
if not os.path.exists(instance_path):
|
||||
os.makedirs(instance_path)'''
|
||||
|
||||
new_init = '''# --- Flask App Initialization ---
|
||||
|
||||
# Ensure instance folder exists BEFORE creating the app
|
||||
instance_path = Config.INSTANCE_DIR
|
||||
if not os.path.exists(instance_path):
|
||||
os.makedirs(instance_path)
|
||||
logging.info(f"Created instance directory: {instance_path}")
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(Config)'''
|
||||
|
||||
if old_init in content:
|
||||
content = content.replace(old_init, new_init)
|
||||
print("✅ Updated instance folder creation")
|
||||
|
||||
# Write the fixed content
|
||||
with open(main_file, 'w') as f:
|
||||
f.write(content)
|
||||
|
||||
print("\n✅ main.py has been fixed!")
|
||||
print("\nYou can now run:")
|
||||
print(" python3 main.py")
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("""
|
||||
╔════════════════════════════════════════════════════════════╗
|
||||
║ UrNetwork Stats Dashboard - Database Path Fix ║
|
||||
╚════════════════════════════════════════════════════════════╝
|
||||
""")
|
||||
|
||||
try:
|
||||
fix_main_py()
|
||||
except Exception as e:
|
||||
print(f"\n❌ Error: {e}")
|
||||
sys.exit(1)
|
||||
Loading…
Add table
Add a link
Reference in a new issue