diff --git a/web/config.py b/web/config.py index 36ea7c2bb..2535d3396 100644 --- a/web/config.py +++ b/web/config.py @@ -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 diff --git a/web/pgAdmin4.py b/web/pgAdmin4.py index bd593cc5b..bf751582e 100644 --- a/web/pgAdmin4.py +++ b/web/pgAdmin4.py @@ -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 diff --git a/web/pgadmin/__init__.py b/web/pgadmin/__init__.py index 6bcfa2748..718628f4b 100644 --- a/web/pgadmin/__init__.py +++ b/web/pgadmin/__init__.py @@ -9,7 +9,7 @@ # ########################################################################## -import logging +import inspect, logging, os from flask import Flask # Configuration settings @@ -54,12 +54,26 @@ def create_app(app_name=config.APP_NAME): app.logger.info('################################################################################') app.logger.info('Starting %s v%s...', config.APP_NAME, config.APP_VERSION) 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) - app.register_blueprint(module.views.blueprint) + 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)