mirror of
https://github.com/yweber/lodel2.git
synced 2025-11-12 17:09:16 +01:00
Now lodel_admin.py dyncode seems functionnal on multisite
Only tested for lodelsites instance
This commit is contained in:
parent
63f6143003
commit
8006bfb080
6 changed files with 47 additions and 49 deletions
|
|
@ -25,7 +25,7 @@ from lodel.context import LodelContext
|
|||
#lodelsites.conf.d
|
||||
CONFS_DIRNAMES = [
|
||||
'conf.d',
|
||||
('server_conf.d', 'lodelsites.conf.d')]
|
||||
('server_conf.d', lodel.buildconf.LODELSITE_CONFDIR)]
|
||||
|
||||
##@brief Test if current instance is monosite or multisite
|
||||
#@return if monosite return True else False
|
||||
|
|
|
|||
|
|
@ -14,3 +14,4 @@ MULTISITE_CONTEXTDIR = "[@]MULTISITE_CTX_DIRNAME[@]"
|
|||
MULTISITE_DYNCODE_MODULENAME = 'leapi_dyncode'
|
||||
##@todo to be generated via autotools
|
||||
LODEL_PKG_PATH = '/usr/lib/python3/dist-package/lodel'
|
||||
LODELSITE_CONFDIR = 'lodelsites.conf.d'
|
||||
|
|
|
|||
|
|
@ -311,23 +311,15 @@ class RefreshDyncode(LodelScript):
|
|||
parser.add_argument('-m', '--em',
|
||||
help='Specify the emfile to use for dyncode generation',
|
||||
type=str, default='')
|
||||
parser.add_argument('-o', '--dyncode',
|
||||
help='Specify the filename where the dyncode should be written',
|
||||
type=str, default='')
|
||||
return
|
||||
|
||||
##@todo think of a better method to determine if we are in mono or
|
||||
#multisite instance
|
||||
@classmethod
|
||||
def run(cls, args):
|
||||
"""
|
||||
#
|
||||
# Dirty hack for instance type detection
|
||||
#
|
||||
ctx_type = LodelContext.MULTISITE
|
||||
CONFDIR = os.path.join(os.getcwd(), 'lodelsites.conf.d')
|
||||
if os.path.isdir('./conf.d'):
|
||||
print("MONOSITE DETECTED")
|
||||
ctx_type = LodelContext.MONOSITE
|
||||
CONFDIR = os.path.join(os.getcwd(), 'conf.d')
|
||||
"""
|
||||
LodelContext.expose_modules(globals(), {
|
||||
'lodel.settings': ['Settings'],
|
||||
'lodel.editorial_model.model': ['EditorialModel'],
|
||||
|
|
@ -340,7 +332,10 @@ class RefreshDyncode(LodelScript):
|
|||
#Model loaded
|
||||
model = EditorialModel.load(em_translator, filename = model_file)
|
||||
#Creating dyncode
|
||||
dyncode_file = Settings.editorialmodel.dyncode
|
||||
dyncode_file = args.dyncode
|
||||
if len(args.dyncode.strip()) == 0:
|
||||
#using dyncode filename from conf
|
||||
dyncode_file = Settings.editorialmodel.dyncode
|
||||
dyncode_content = lefactory.dyncode_from_em(model)
|
||||
with open(dyncode_file, 'w+') as dfp:
|
||||
dfp.write(dyncode_content)
|
||||
|
|
|
|||
|
|
@ -22,6 +22,10 @@ import warnings
|
|||
#@note the uwsgi process in started using the execl function when UWSGI
|
||||
#will exit this process will stop too
|
||||
#
|
||||
from lodel import buildconf
|
||||
from lodel import bootstrap
|
||||
bootstrap.bootstrap('__loader__')
|
||||
|
||||
try:
|
||||
from lodel.context import LodelContext
|
||||
except ImportError:
|
||||
|
|
@ -29,22 +33,6 @@ except ImportError:
|
|||
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(), 'server_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('./server_conf.d', multisite_confspecs.LODEL2_CONFSPECS)
|
||||
|
||||
LodelContext.expose_modules(globals(), {
|
||||
'lodel.settings': ['Settings']})
|
||||
|
||||
LodelContext.expose_modules(globals(), {
|
||||
'lodel.plugin.hooks': ['LodelHook'],
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import os
|
||||
import os.path
|
||||
|
||||
|
||||
##@brief basename of multisite process conf folder
|
||||
#@todo find a better place to declare it
|
||||
SERVER_CONFD = 'server_conf.d' #Should be accessible elsewhere
|
||||
|
|
@ -36,7 +37,7 @@ import lodel.buildconf
|
|||
#@todo use the dyncode getter when it will be available (replaced by
|
||||
#the string SUPERDYNCODE_ACCESSOR.Lodelsite for the moment)
|
||||
def main():
|
||||
#Set current context to reserved loader context
|
||||
"""
|
||||
LodelContext.set(None)
|
||||
LodelContext.expose_modules(globals(), {
|
||||
'lodel.logger': 'logger',
|
||||
|
|
@ -55,24 +56,32 @@ find the %s folder' % SERVER_CONFD)
|
|||
settings(CONFDIR, multisite_confspecs.LODEL2_CONFSPECS)
|
||||
#Loading settings
|
||||
del(globals()['settings']) #useless but may be safer
|
||||
#Exposing "real" settings object in loader context
|
||||
"""
|
||||
#Set current context to reserved loader context
|
||||
from lodel import bootstrap
|
||||
bootstrap.bootstrap('__loader__')
|
||||
LodelContext.expose_modules(globals(), {
|
||||
'lodel.settings': ['Settings']})
|
||||
#Fetching lodelsites informations
|
||||
lodelsites_name = Settings.lodelsites.name
|
||||
#Following path construction is kind of dirty ! We should be able
|
||||
#to assume that the lodelsites_datapath == os.getcwd()....
|
||||
lodelsites_datapath = os.path.join(
|
||||
lodel.buildconf.LODEL2VARDIR, lodelsites_name)
|
||||
#loading lodelsites site
|
||||
print("DATAPATH : ", lodelsites_datapath)
|
||||
site_load(lodelsites_datapath, LODELSITES_CONFD)
|
||||
|
||||
#Fetching handled sites list
|
||||
#WARNING ! Here we assert that context name == basename(lodelsites_datapath)
|
||||
lodelsites_name = Settings.sitename
|
||||
del(globals()['Settings'])
|
||||
|
||||
#bootstraping the lodelsites instance
|
||||
LodelContext.new(lodelsites_name)
|
||||
LodelContext.set(lodelsites_name)
|
||||
#in lodelsites context
|
||||
Lodelsite_leo = SUPERDYNCODE_ACCESSOR.Lodelsite #hardcoded leo name
|
||||
LodelContext.expose_modules(globals(), {
|
||||
'lodel.settings.settings': [('Settings', 'settings_loader')],
|
||||
'lodel.plugins.multisite.confspecs': 'multisite_confspecs',
|
||||
'lodel.plugins.multisite.confspecs': 'multisite_confspecs'})
|
||||
|
||||
settings_loader(lodel.buildconf.LODELSITE_CONFDIR,
|
||||
multisite_confspecs.LODEL2_CONFSPECS, True)
|
||||
del(globals()['settings_loader'])
|
||||
LodelContext.expose_modules(globals(), {
|
||||
'lodel.settings': ['Settings']})
|
||||
|
||||
LodelContext.expose_dyncode(globals())
|
||||
lodelsite_leo = leapi_dyncode.Lodelsite #hardcoded leo name
|
||||
LodelContext.expose_modules(globals(), {
|
||||
'lodel.leapi.query': ['LeGetQuery'],
|
||||
})
|
||||
|
|
@ -104,6 +113,8 @@ find the %s folder' % SERVER_CONFD)
|
|||
#lodelsites instance
|
||||
#@param data_path str : path to the datas directory (containing the confdir)
|
||||
#@param confdir_basename str : the basename of the site confdir
|
||||
#@param lodelsites_instance bool : if true we are loading the lodelsites
|
||||
#instance of the multisite (allow to load the good confspecs)
|
||||
#
|
||||
#@todo For now the interface plugin name for sites is hardcoded (set to
|
||||
#webui). It HAS TO be loaded from settings. But it is a bit complicated,
|
||||
|
|
@ -114,7 +125,7 @@ find the %s folder' % SERVER_CONFD)
|
|||
#@todo there is a quick & dirty workarround with comments saying that it
|
||||
#avoid context escape via hooks. We have to understand why and how and then
|
||||
#replace the workarround by a real solution !
|
||||
def site_load(data_path, confdir_basename = 'conf.d'):
|
||||
def site_load(data_path, confdir_basename = 'conf.d', lodelsites_instance = False):
|
||||
#args check
|
||||
if confdir_basename != os.path.basename(confdir_basename):
|
||||
LodelFatalError('Bad argument given to site_load(). This really \
|
||||
|
|
@ -130,7 +141,6 @@ sux !')
|
|||
#Loading settings for current site
|
||||
LodelContext.expose_modules(globals(), {
|
||||
'lodel.settings.settings': [('Settings', 'settings_preloader')]})
|
||||
print(settings_preloader)
|
||||
if settings_preloader.started():
|
||||
msg = 'Settings seems to be allready started for "%s". \
|
||||
This should not append !' % ctx_name
|
||||
|
|
@ -138,7 +148,10 @@ This should not append !' % ctx_name
|
|||
LodelContext.set(None)
|
||||
logger.critical(msg)
|
||||
raise LodelFatalError(msg)
|
||||
settings_preloader(os.path.join('./', confdir_basename))
|
||||
if lodelsites_instance:
|
||||
settings_preloader(os.path.join('./', confdir_basename), )
|
||||
else:
|
||||
settings_preloader(os.path.join('./', confdir_basename))
|
||||
#
|
||||
#Loading hooks & plugins
|
||||
#
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import os.path
|
||||
|
||||
"""
|
||||
try:
|
||||
from lodel.context import LodelContext
|
||||
except ImportError:
|
||||
|
|
@ -7,9 +8,9 @@ except ImportError:
|
|||
os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
from lodel.context import LodelContext, ContextError
|
||||
|
||||
LodelContext.init(LodelContext.MULTISITE)
|
||||
|
||||
import lodel.buildconf #safe even outside contexts
|
||||
"""
|
||||
|
||||
from lodel.plugins.multisite.loader_utils import main, site_load, FAST_APP_EXPOSAL_CACHE
|
||||
|
||||
main() #multisite bootstraping
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue