def application(env, start_response): #Attempt to load a context site_id = site_id_from_url(env['PATH_INFO']) if site_id is None: #It can be nice to provide a list of instances here return http_error(env, start_response, '404 Not Found') try: LodelContext.set(site_id) #We are in the good context except ContextError as e: print(e) return http_error(env, start_response, '404 Not found', "No site named '%s'" % site_id) #Calling webui return FAST_APP_EXPOSAL_CACHE[site_id].application(env, start_response)
#Here we have to bootstrap a minimal __loader__ context in order #to be able to load the settings # #This file (once bootstraped) start a new process for uWSGI. uWSGI then #run lodel.plugins.multisite.run.application function try: from lodel.context import LodelContext except ImportError: LODEL_BASE_DIR = os.path.dirname( os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from lodel.context import LodelContext from lodel import buildconf LodelContext.init(LodelContext.MULTISITE) LodelContext.set(None) #Loading context creation #Multisite instance settings loading CONFDIR = os.path.join(os.getcwd(), 'conf.d') if not os.path.isdir(CONFDIR): warnings.warn('%s do not exists, default settings used' % CONFDIR) LodelContext.expose_modules( globals(), { 'lodel.settings.settings': [('Settings', 'settings')], 'lodel.plugins.multisite.confspecs': 'multisite_confspecs' }) if not settings.started(): settings('./conf.d', multisite_confspecs.LODEL2_CONFSPECS) LodelContext.expose_modules(globals(), {'lodel.settings': ['Settings']})
#preloading all instances FAST_APP_EXPOSAL_CACHE = dict() LODEL2_INSTANCES_DIR = '.' EXCLUDE_DIR = {'conf.d', '__pycache__'} try: from lodel.context import LodelContext except ImportError: LODEL_BASE_DIR = os.path.dirname( os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from lodel.context import LodelContext, ContextError LodelContext.init(LodelContext.MULTISITE) LodelContext.set(None) #Loading context creation #Multisite instance settings loading CONFDIR = os.path.join(os.getcwd(), 'conf.d') if not os.path.isdir(CONFDIR): warnings.warn('%s do not exists, default settings used' % CONFDIR) LodelContext.expose_modules( globals(), { 'lodel.settings.settings': [('Settings', 'settings')], 'lodel.plugins.multisite.confspecs': 'multisite_confspecs' }) if not settings.started(): settings('./conf.d', multisite_confspecs.LODEL2_CONFSPECS) #Fetching insrtance list from subdirectories lodelsites_list = [