Support dynamically loaded modules.

This commit is contained in:
Dave Page 2015-01-20 12:32:06 +00:00
parent bb3efff063
commit 7b8cb207ab
3 changed files with 24 additions and 11 deletions

View File

@ -31,9 +31,9 @@ APP_SUFFIX = 'dev'
# The application version string, constructed from the components
APP_VERSION = '%s.%s.%s-%s' % (APP_MAJOR, APP_MINOR, APP_REVISION, APP_SUFFIX)
# DO NOT CHANGE!
# List of modules to enable
MODULES = [ 'utils' ]
# DO NOT CHANGE UNLESS YOU KNOW WHAT YOU ARE DOING!
# List of modules to skip when dynamically loading
MODULE_BLACKLIST = [ ]
##########################################################################
# Log settings

View File

@ -13,8 +13,7 @@ import os, sys
# We need to include the root directory in sys.path to ensure that we can
# find everything we need when running in the standalone runtime.
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'pgadmin'))
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
import config
from pgadmin import create_app

View File

@ -9,7 +9,7 @@
#
##########################################################################
import logging
import inspect, logging, os
from flask import Flask
# Configuration settings
@ -56,9 +56,23 @@ def create_app(app_name=config.APP_NAME):
app.logger.info('################################################################################')
# Register all the modules
for m in config.MODULES:
app.logger.debug('Loading module %s' % m)
module = __import__(m, globals(), locals(), ['views'], -1)
path = os.path.dirname(os.path.realpath(__file__))
files = os.listdir(path)
for f in files:
d = os.path.join(path, f)
if os.path.isdir(d) and os.path.isfile(os.path.join(d, '__init__.py')):
if f in config.MODULE_BLACKLIST:
app.logger.info('Skipping blacklisted module: %s' % f)
continue
# Looks like a module, so import it, and register the blueprint if present
# We rely on the ordering of syspath to ensure we actually get the right
# module here.
app.logger.info('Examining potential module: %s' % d)
module = __import__(f, globals(), locals(), ['views'], -1)
if hasattr(module.views, 'blueprint'):
app.logger.info('Registering blueprint module: %s' % f)
app.register_blueprint(module.views.blueprint)
app.logger.debug('URL map: %s' % app.url_map)