Bug: Fixed Imports of Consumption Sheets Module
This commit is contained in:
77
app.py
77
app.py
@@ -162,43 +162,8 @@ def install_module(module_key):
|
||||
|
||||
result = module_manager.install_module(module_key)
|
||||
|
||||
# Hot-reload: Register the blueprint immediately if installation succeeded
|
||||
if result['success']:
|
||||
try:
|
||||
from pathlib import Path
|
||||
import importlib.util
|
||||
import sys
|
||||
|
||||
module = module_manager.get_module_by_key(module_key)
|
||||
if module:
|
||||
init_path = Path(module['path']) / '__init__.py'
|
||||
|
||||
# Import the module
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
f"modules.{module_key}",
|
||||
init_path
|
||||
)
|
||||
module_package = importlib.util.module_from_spec(spec)
|
||||
sys.modules[spec.name] = module_package
|
||||
spec.loader.exec_module(module_package)
|
||||
|
||||
# Create and register blueprint
|
||||
if hasattr(module_package, 'create_blueprint'):
|
||||
blueprint = module_package.create_blueprint()
|
||||
app.register_blueprint(blueprint)
|
||||
print(f"🔥 Hot-loaded: {module['name']} at {module.get('routes_prefix')}")
|
||||
result['message'] += ' (Module loaded - no restart needed!)'
|
||||
else:
|
||||
print(f"⚠️ Module {module_key} missing create_blueprint()")
|
||||
result['message'] += ' (Restart required - missing create_blueprint)'
|
||||
else:
|
||||
print(f"⚠️ Could not find module {module_key} after installation")
|
||||
result['message'] += ' (Restart required - module not found)'
|
||||
except Exception as e:
|
||||
print(f"❌ Hot-reload failed for {module_key}: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
result['message'] += f' (Restart required - hot-reload failed)'
|
||||
result['restart_required'] = True
|
||||
|
||||
return jsonify(result)
|
||||
|
||||
@@ -209,7 +174,11 @@ def uninstall_module(module_key):
|
||||
if session.get('role') not in ['owner', 'admin']:
|
||||
return jsonify({'success': False, 'message': 'Access denied'}), 403
|
||||
|
||||
result = module_manager.uninstall_module(module_key, drop_tables=True)
|
||||
# Check if user wants to keep data
|
||||
keep_data = request.args.get('keep_data') == 'true'
|
||||
drop_tables = not keep_data
|
||||
|
||||
result = module_manager.uninstall_module(module_key, drop_tables=drop_tables)
|
||||
return jsonify(result)
|
||||
|
||||
|
||||
@@ -234,7 +203,39 @@ def deactivate_module(module_key):
|
||||
result = module_manager.deactivate_module(module_key)
|
||||
return jsonify(result)
|
||||
|
||||
|
||||
@app.route('/admin/restart', methods=['POST'])
|
||||
@login_required
|
||||
def restart_server():
|
||||
"""Restart the Flask server"""
|
||||
if session.get('role') not in ['owner', 'admin']:
|
||||
return jsonify({'success': False, 'message': 'Access denied'}), 403
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
try:
|
||||
print("\n🔄 Server restart requested by admin...")
|
||||
|
||||
# Return response first
|
||||
response = jsonify({'success': True, 'message': 'Server restarting...'})
|
||||
|
||||
# Schedule restart after response is sent
|
||||
def restart():
|
||||
import time
|
||||
time.sleep(0.5) # Give time for response to send
|
||||
|
||||
if os.name == 'nt': # Windows
|
||||
os.execv(sys.executable, ['python'] + sys.argv)
|
||||
else: # Linux/Mac
|
||||
os.execv(sys.executable, [sys.executable] + sys.argv)
|
||||
|
||||
from threading import Thread
|
||||
Thread(target=restart).start()
|
||||
|
||||
return response
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({'success': False, 'message': f'Restart failed: {str(e)}'})
|
||||
# ==================== PWA SUPPORT ROUTES ====================
|
||||
|
||||
@app.route('/manifest.json')
|
||||
|
||||
Reference in New Issue
Block a user