Support dynamically loaded modules.
parent
bb3efff063
commit
7b8cb207ab
|
@ -31,9 +31,9 @@ APP_SUFFIX = 'dev'
|
||||||
# The application version string, constructed from the components
|
# The application version string, constructed from the components
|
||||||
APP_VERSION = '%s.%s.%s-%s' % (APP_MAJOR, APP_MINOR, APP_REVISION, APP_SUFFIX)
|
APP_VERSION = '%s.%s.%s-%s' % (APP_MAJOR, APP_MINOR, APP_REVISION, APP_SUFFIX)
|
||||||
|
|
||||||
# DO NOT CHANGE!
|
# DO NOT CHANGE UNLESS YOU KNOW WHAT YOU ARE DOING!
|
||||||
# List of modules to enable
|
# List of modules to skip when dynamically loading
|
||||||
MODULES = [ 'utils' ]
|
MODULE_BLACKLIST = [ ]
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# Log settings
|
# Log settings
|
||||||
|
|
|
@ -13,8 +13,7 @@ import os, sys
|
||||||
|
|
||||||
# We need to include the root directory in sys.path to ensure that we can
|
# 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.
|
# find everything we need when running in the standalone runtime.
|
||||||
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
|
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
||||||
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'pgadmin'))
|
|
||||||
|
|
||||||
import config
|
import config
|
||||||
from pgadmin import create_app
|
from pgadmin import create_app
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#
|
#
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
import logging
|
import inspect, logging, os
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
|
|
||||||
# Configuration settings
|
# Configuration settings
|
||||||
|
@ -54,12 +54,26 @@ def create_app(app_name=config.APP_NAME):
|
||||||
app.logger.info('################################################################################')
|
app.logger.info('################################################################################')
|
||||||
app.logger.info('Starting %s v%s...', config.APP_NAME, config.APP_VERSION)
|
app.logger.info('Starting %s v%s...', config.APP_NAME, config.APP_VERSION)
|
||||||
app.logger.info('################################################################################')
|
app.logger.info('################################################################################')
|
||||||
|
|
||||||
# Register all the modules
|
# Register all the modules
|
||||||
for m in config.MODULES:
|
path = os.path.dirname(os.path.realpath(__file__))
|
||||||
app.logger.debug('Loading module %s' % m)
|
files = os.listdir(path)
|
||||||
module = __import__(m, globals(), locals(), ['views'], -1)
|
for f in files:
|
||||||
app.register_blueprint(module.views.blueprint)
|
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)
|
app.logger.debug('URL map: %s' % app.url_map)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue