mirror of
https://github.com/yweber/lodel2.git
synced 2026-10-30 08:11:33 +01:00
First version of lodel2 instance creation script
This commit is contained in:
parent
0bdcd36740
commit
a312cbc4d9
17 changed files with 180 additions and 8 deletions
0
__init__.py
Normal file
0
__init__.py
Normal file
|
|
@ -1,6 +1,8 @@
|
|||
#-*- coding: utf-8 -*-
|
||||
|
||||
import loader
|
||||
from lodel.settings.settings import Settings as SettingsHandler
|
||||
SettingsHandler('globconf.d')
|
||||
|
||||
from lodel.editorial_model.components import *
|
||||
from lodel.editorial_model.exceptions import *
|
||||
from lodel.editorial_model.model import EditorialModel
|
||||
|
|
|
|||
Binary file not shown.
4
install/Makefile
Normal file
4
install/Makefile
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
all: dyncode
|
||||
|
||||
dyncode:
|
||||
python -c 'import lodel_admin; lodel_admin.refresh_dyncode()'
|
||||
2
install/conf.d/dummy_plugin.ini
Normal file
2
install/conf.d/dummy_plugin.ini
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
[lodel2.section1]
|
||||
key1 = 42
|
||||
15
install/conf.d/lodel2.ini
Normal file
15
install/conf.d/lodel2.ini
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
[lodel2]
|
||||
debug = False
|
||||
plugins = dummy
|
||||
sitename = noname
|
||||
|
||||
[lodel2.logging.stderr]
|
||||
level = DEBUG
|
||||
filename = -
|
||||
context = True
|
||||
|
||||
[lodel2.editorialmodel]
|
||||
groups =
|
||||
emfile = editorial_model.pickle
|
||||
dyncode = leapi_dyncode.py
|
||||
|
||||
BIN
install/editorial_model.pickle
Normal file
BIN
install/editorial_model.pickle
Normal file
Binary file not shown.
32
install/loader.py
Normal file
32
install/loader.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#-*- coding: utf-8 -*-
|
||||
|
||||
import sys, os
|
||||
#
|
||||
# Bootstraping
|
||||
#
|
||||
LODEL2_LIB_ABS_PATH = None
|
||||
if LODEL2_LIB_ABS_PATH is not None:
|
||||
sys.path.append(os.path.dirname(LODEL2_LIB_ABS_PATH))
|
||||
|
||||
try:
|
||||
import lodel
|
||||
except ImportError:
|
||||
print("Unable to load lodel module. exiting...", file = sys.stderr)
|
||||
exit(1)
|
||||
|
||||
|
||||
#
|
||||
# Loading settings
|
||||
#
|
||||
from lodel.settings.settings import Settings as settings
|
||||
settings('conf.d')
|
||||
from lodel.settings import Settings
|
||||
|
||||
|
||||
if __name__ == '__main__': # To allow running interactive python
|
||||
import code
|
||||
print("""
|
||||
Running interactive python in Lodel2 %s instance environment
|
||||
|
||||
"""%Settings.sitename)
|
||||
code.interact(local=locals())
|
||||
46
install/lodel_admin.py
Normal file
46
install/lodel_admin.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#-*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
import os, os.path
|
||||
import loader
|
||||
|
||||
from lodel.settings import Settings
|
||||
from lodel import logger
|
||||
|
||||
## @brief Utility method to generate python code given an emfile and a
|
||||
# translator
|
||||
# @param model_file str : An em file
|
||||
# @param translator str : a translator name
|
||||
# @return python code as string
|
||||
def generate_dyncode(model_file, translator):
|
||||
from lodel.editorial_model.model import EditorialModel
|
||||
from lodel.leapi import lefactory
|
||||
|
||||
model = EditorialModel.load(translator, filename = model_file)
|
||||
dyncode = lefactory.dyncode_from_em(model)
|
||||
return dyncode
|
||||
|
||||
## @brief Utility method to generate a python file representing leapi dyncode
|
||||
# given an em file and the associated translator name
|
||||
#
|
||||
# @param model_file str : An em file
|
||||
# @param translator str : a translator name
|
||||
# @param output_filename str : the output file
|
||||
def create_dyncode(model_file, translator, output_filename):
|
||||
dyncode = generate_dyncode(model_file, translator)
|
||||
with open(output_filename, 'w+') as out_fd:
|
||||
out_fd.write(dyncode)
|
||||
out_fd.close()
|
||||
logger.info("Dynamic leapi code written in %s", output_filename)
|
||||
|
||||
|
||||
## @brief Refresh dynamic leapi code from settings
|
||||
def refresh_dyncode():
|
||||
# EditorialModel update/refresh
|
||||
|
||||
# TODO
|
||||
|
||||
# Dyncode refresh
|
||||
create_dyncode( Settings.editorialmodel.emfile,
|
||||
Settings.editorialmodel.emtranslator,
|
||||
Settings.editorialmodel.dyncode)
|
||||
|
|
@ -28,6 +28,7 @@ class EditorialModel(object):
|
|||
self.__active_groups = dict()
|
||||
## @brief Stores all activated classes indexed by id
|
||||
self.__active_classes = dict()
|
||||
self.__set_actives()
|
||||
|
||||
##@brief EmClass accessor
|
||||
#@param uid None | str : give this argument to get a specific EmClass
|
||||
|
|
@ -158,7 +159,9 @@ class EditorialModel(object):
|
|||
def load(cls, translator, **translator_kwargs):
|
||||
if isinstance(translator, str):
|
||||
translator = cls.translator_from_name(translator)
|
||||
return translator.load(**translator_kwargs)
|
||||
res = translator.load(**translator_kwargs)
|
||||
res.__set_actives()
|
||||
return res
|
||||
|
||||
##@brief Return a translator module given a translator name
|
||||
# @param translator_name str : The translator name
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ class DataHandler(object):
|
|||
self.uniq = False
|
||||
self.immutable = False
|
||||
self.primary_key = False
|
||||
self.internal = False
|
||||
if 'defaults' in kwargs:
|
||||
self.default, error = self.check_data_value(kwargs['default'])
|
||||
if error:
|
||||
|
|
|
|||
|
|
@ -88,7 +88,21 @@ class Plugins(object):
|
|||
##@brief Bootstrap the Plugins class
|
||||
@classmethod
|
||||
def bootstrap(cls, plugins_directories):
|
||||
cls._plugin_directories = plugins_directories
|
||||
from lodel.settings import Settings
|
||||
cls.start(Settings.plugins_path)
|
||||
|
||||
##@brief Start the Plugins class by explicitly giving a plugin directory path
|
||||
# @param plugins_directories list : List of path
|
||||
@classmethod
|
||||
def start(cls, plugins_directories):
|
||||
import inspect
|
||||
self_path = inspect.getsourcefile(Plugins)
|
||||
default_plugin_path = os.path.abspath(self_path + '../../../../plugins')
|
||||
if plugins_directories is None:
|
||||
plugins_directories = list()
|
||||
plugins_directories += [ default_plugin_path ]
|
||||
cls._plugin_directories = list(set(plugins_directories))
|
||||
|
||||
|
||||
@classmethod
|
||||
def started(cls, raise_if_not = True):
|
||||
|
|
|
|||
|
|
@ -33,6 +33,5 @@
|
|||
# print("DEBUG MODE !")
|
||||
# </pre>
|
||||
#
|
||||
|
||||
from lodel.settings.settings import SettingsRO as Settings
|
||||
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ class Settings(object, metaclass=MetaSettings):
|
|||
plugins_path_opt_specs[0],
|
||||
False)
|
||||
# Starting the Plugins class
|
||||
Plugins.bootstrap(plugins_path)
|
||||
Plugins.start(plugins_path)
|
||||
# Fetching conf specs from plugins
|
||||
specs = [lodel2_specs]
|
||||
errors = list()
|
||||
|
|
|
|||
|
|
@ -74,7 +74,9 @@ class SettingValidator(object):
|
|||
res = list()
|
||||
errors = list()
|
||||
for elt in value.split(separator):
|
||||
res.append(elt_validator(elt))
|
||||
elt = elt_validator(elt)
|
||||
if len(elt) > 0:
|
||||
res.append(elt)
|
||||
return res
|
||||
description = "Convert value to an array" if description is None else description
|
||||
cls.register_validator(
|
||||
|
|
@ -153,10 +155,17 @@ def path_val(value):
|
|||
raise SettingsValidationError("The value '%s' is not a valid path")
|
||||
return value
|
||||
|
||||
def dummy_val(value): return value
|
||||
|
||||
#
|
||||
# Default validators registration
|
||||
#
|
||||
|
||||
SettingValidator.register_validator(
|
||||
'dummy',
|
||||
dummy_val,
|
||||
'Validate anything')
|
||||
|
||||
SettingValidator.register_validator(
|
||||
'strip',
|
||||
str.strip,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
#-*- coding: utf-8 -*-
|
||||
|
||||
from lodel.settings.validator import SettingValidator
|
||||
|
||||
CONFSPEC = {
|
||||
'section1': {
|
||||
'key1': None
|
||||
'lodel2.section1': {
|
||||
'key1': ( None,
|
||||
SettingValidator('dummy'))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
42
scripts/create_instance.sh
Executable file
42
scripts/create_instance.sh
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
#!/bin/bash
|
||||
|
||||
usage() {
|
||||
echo "Usage : $0 instance_name instance_dir [lodel_libdir]" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ $# -lt 2 ]
|
||||
then
|
||||
echo "Not enough arguments" 1>&2
|
||||
usage
|
||||
fi
|
||||
|
||||
|
||||
name="$1"
|
||||
instdir="$2"
|
||||
|
||||
libdir="$3"
|
||||
libdir="${libdir:=$(realpath $(dirname $0)/..)}/"
|
||||
|
||||
loader="$instdir/loader.py"
|
||||
conf="$instdir/conf.d/lodel2.ini"
|
||||
|
||||
if [ -e "$instdir" ]
|
||||
then
|
||||
echo "Abording... "$instdir" exists" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Creating lodel instance directory '$instdir'"
|
||||
mkdir -pv "$instdir"
|
||||
|
||||
cp -Rv $libdir/install/* $instdir
|
||||
|
||||
# Adding lib path to loader
|
||||
sed -i -E "s#^(LODEL2_LIB_ABS_PATH = )None#\1'$libdir'#" "$loader"
|
||||
# Adding instance name to conf
|
||||
sed -i -E "s#^sitename = noname#sitename = $name#" "$conf"
|
||||
|
||||
echo -e "\nInstance successfully created in $instdir"
|
||||
echo -e "============================\n"
|
||||
echo "Now you should edit '$settings' and then run : cd $instdir && make dbinit"
|
||||
Loading…
Add table
Add a link
Reference in a new issue