more crap
This commit is contained in:
@ -1,19 +1,27 @@
|
||||
import os
|
||||
import json
|
||||
import importlib.util
|
||||
import importlib
|
||||
from flask import Flask
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_migrate import Migrate
|
||||
from flask_login import LoginManager
|
||||
from flask_wtf.csrf import CSRFProtect
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Load environment variables from .env
|
||||
load_dotenv()
|
||||
|
||||
db = SQLAlchemy()
|
||||
migrate = Migrate()
|
||||
login_manager = LoginManager()
|
||||
csrf = CSRFProtect()
|
||||
|
||||
|
||||
def create_app():
|
||||
app = Flask(__name__)
|
||||
app.config.from_object('app.config.Config')
|
||||
csrf.init_app(app)
|
||||
|
||||
# Initialize core extensions
|
||||
db.init_app(app)
|
||||
@ -28,7 +36,6 @@ def create_app():
|
||||
# Plugin auto-loader
|
||||
plugin_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'plugins'))
|
||||
for plugin in os.listdir(plugin_path):
|
||||
# Skip folders that end with `.noload`
|
||||
if plugin.endswith('.noload'):
|
||||
print(f"[⏭] Skipping plugin '{plugin}' (marked as .noload)")
|
||||
continue
|
||||
@ -49,13 +56,23 @@ def create_app():
|
||||
except Exception as e:
|
||||
print(f"[⚠️] Failed to load routes from plugin '{plugin}': {e}")
|
||||
|
||||
# Register CLI commands
|
||||
# Register CLI commands and plugin entry points
|
||||
init_file = os.path.join(plugin_dir, '__init__.py')
|
||||
if os.path.isfile(init_file):
|
||||
try:
|
||||
cli_module = importlib.import_module(f"plugins.{plugin}")
|
||||
if hasattr(cli_module, 'register_cli'):
|
||||
cli_module.register_cli(app)
|
||||
|
||||
plugin_json = os.path.join(plugin_dir, 'plugin.json')
|
||||
if os.path.isfile(plugin_json):
|
||||
try:
|
||||
meta = json.load(open(plugin_json, 'r'))
|
||||
entry = meta.get('entry_point')
|
||||
if entry and hasattr(cli_module, entry):
|
||||
getattr(cli_module, entry)(app)
|
||||
except Exception as e:
|
||||
print(f"[⚠️] Failed to run entry_point '{entry}' for plugin '{plugin}': {e}")
|
||||
except Exception as e:
|
||||
print(f"[⚠️] Failed to load CLI from plugin '{plugin}': {e}")
|
||||
|
||||
|
Reference in New Issue
Block a user