Kaynağa Gözat

First version of lodel2 instance creation script

Yann Weber 8 yıl önce
ebeveyn
işleme
a312cbc4d9

+ 0
- 0
__init__.py Dosyayı Görüntüle


+ 3
- 1
em_test.py Dosyayı Görüntüle

@@ -1,6 +1,8 @@
1 1
 #-*- coding: utf-8 -*-
2 2
 
3
-import loader
3
+from lodel.settings.settings import Settings as SettingsHandler
4
+SettingsHandler('globconf.d')
5
+
4 6
 from lodel.editorial_model.components import *
5 7
 from lodel.editorial_model.exceptions import *
6 8
 from lodel.editorial_model.model import EditorialModel

BIN
examples/em_test.pickle Dosyayı Görüntüle


+ 4
- 0
install/Makefile Dosyayı Görüntüle

@@ -0,0 +1,4 @@
1
+all: dyncode
2
+
3
+dyncode:
4
+	python -c 'import lodel_admin; lodel_admin.refresh_dyncode()'

+ 2
- 0
install/conf.d/dummy_plugin.ini Dosyayı Görüntüle

@@ -0,0 +1,2 @@
1
+[lodel2.section1]
2
+key1 = 42

+ 15
- 0
install/conf.d/lodel2.ini Dosyayı Görüntüle

@@ -0,0 +1,15 @@
1
+[lodel2]
2
+debug = False
3
+plugins = dummy
4
+sitename = noname
5
+
6
+[lodel2.logging.stderr]
7
+level = DEBUG
8
+filename = -
9
+context = True
10
+
11
+[lodel2.editorialmodel]
12
+groups = 
13
+emfile = editorial_model.pickle
14
+dyncode = leapi_dyncode.py
15
+

BIN
install/editorial_model.pickle Dosyayı Görüntüle


+ 32
- 0
install/loader.py Dosyayı Görüntüle

@@ -0,0 +1,32 @@
1
+#-*- coding: utf-8 -*-
2
+
3
+import sys, os
4
+#
5
+# Bootstraping
6
+#
7
+LODEL2_LIB_ABS_PATH = None
8
+if LODEL2_LIB_ABS_PATH is not None:
9
+    sys.path.append(os.path.dirname(LODEL2_LIB_ABS_PATH))
10
+
11
+try:
12
+    import lodel
13
+except ImportError:
14
+    print("Unable to load lodel module. exiting...", file = sys.stderr)
15
+    exit(1)
16
+
17
+
18
+#
19
+# Loading settings
20
+#
21
+from lodel.settings.settings import Settings as settings
22
+settings('conf.d')
23
+from lodel.settings import Settings
24
+
25
+
26
+if __name__ == '__main__': # To allow running interactive python
27
+    import code
28
+    print("""
29
+     Running interactive python in Lodel2 %s instance environment
30
+
31
+"""%Settings.sitename)
32
+    code.interact(local=locals())

+ 46
- 0
install/lodel_admin.py Dosyayı Görüntüle

@@ -0,0 +1,46 @@
1
+#-*- coding: utf-8 -*-
2
+
3
+import sys
4
+import os, os.path
5
+import loader
6
+
7
+from lodel.settings import Settings
8
+from lodel import logger
9
+
10
+## @brief Utility method to generate python code given an emfile and a
11
+# translator
12
+# @param model_file str : An em file
13
+# @param translator str : a translator name
14
+# @return python code as string
15
+def generate_dyncode(model_file, translator):
16
+    from lodel.editorial_model.model import EditorialModel
17
+    from lodel.leapi import lefactory
18
+
19
+    model = EditorialModel.load(translator, filename  = model_file)
20
+    dyncode = lefactory.dyncode_from_em(model)
21
+    return dyncode
22
+
23
+## @brief Utility method to generate a python file representing leapi dyncode
24
+# given an em file and the associated translator name
25
+#
26
+# @param model_file str : An em file
27
+# @param translator str : a translator name
28
+# @param output_filename str : the output file
29
+def create_dyncode(model_file, translator, output_filename):
30
+    dyncode = generate_dyncode(model_file, translator)
31
+    with open(output_filename, 'w+') as out_fd:
32
+        out_fd.write(dyncode)
33
+    out_fd.close()
34
+    logger.info("Dynamic leapi code written in %s", output_filename)
35
+
36
+
37
+## @brief Refresh dynamic leapi code from settings
38
+def refresh_dyncode():
39
+    # EditorialModel update/refresh
40
+    
41
+    # TODO
42
+
43
+    # Dyncode refresh
44
+    create_dyncode( Settings.editorialmodel.emfile,
45
+                    Settings.editorialmodel.emtranslator,
46
+                    Settings.editorialmodel.dyncode)

+ 4
- 1
lodel/editorial_model/model.py Dosyayı Görüntüle

@@ -28,6 +28,7 @@ class EditorialModel(object):
28 28
         self.__active_groups = dict()
29 29
         ## @brief Stores all activated classes indexed by id
30 30
         self.__active_classes = dict()
31
+        self.__set_actives()
31 32
     
32 33
     ##@brief EmClass accessor
33 34
     #@param uid None | str : give this argument to get a specific EmClass
@@ -158,7 +159,9 @@ class EditorialModel(object):
158 159
     def load(cls, translator, **translator_kwargs):
159 160
         if isinstance(translator, str):
160 161
             translator = cls.translator_from_name(translator)
161
-        return translator.load(**translator_kwargs)
162
+        res = translator.load(**translator_kwargs)
163
+        res.__set_actives()
164
+        return res
162 165
 
163 166
     ##@brief Return a translator module given a translator name
164 167
     # @param translator_name str : The translator name

+ 1
- 0
lodel/leapi/datahandlers/base_classes.py Dosyayı Görüntüle

@@ -45,6 +45,7 @@ class DataHandler(object):
45 45
         self.uniq = False
46 46
         self.immutable = False
47 47
         self.primary_key = False
48
+        self.internal = False
48 49
         if 'defaults' in kwargs:
49 50
             self.default, error = self.check_data_value(kwargs['default'])
50 51
             if error:

+ 15
- 1
lodel/plugin/plugins.py Dosyayı Görüntüle

@@ -88,7 +88,21 @@ class Plugins(object):
88 88
     ##@brief Bootstrap the Plugins class
89 89
     @classmethod
90 90
     def bootstrap(cls, plugins_directories):
91
-        cls._plugin_directories = plugins_directories
91
+        from lodel.settings import Settings
92
+        cls.start(Settings.plugins_path)
93
+    
94
+    ##@brief Start the Plugins class by explicitly giving a plugin directory path
95
+    # @param plugins_directories list : List of path
96
+    @classmethod
97
+    def start(cls, plugins_directories):
98
+        import inspect
99
+        self_path = inspect.getsourcefile(Plugins)
100
+        default_plugin_path = os.path.abspath(self_path + '../../../../plugins')
101
+        if plugins_directories is None:
102
+            plugins_directories = list()
103
+        plugins_directories += [ default_plugin_path ]
104
+        cls._plugin_directories = list(set(plugins_directories))
105
+        
92 106
 
93 107
     @classmethod
94 108
     def started(cls, raise_if_not = True):

+ 0
- 1
lodel/settings/__init__.py Dosyayı Görüntüle

@@ -33,6 +33,5 @@
33 33
 #   print("DEBUG MODE !")
34 34
 # </pre>
35 35
 #
36
-
37 36
 from lodel.settings.settings import SettingsRO as Settings
38 37
 

+ 1
- 1
lodel/settings/settings.py Dosyayı Görüntüle

@@ -146,7 +146,7 @@ class Settings(object, metaclass=MetaSettings):
146 146
                                             plugins_path_opt_specs[0],
147 147
                                             False)
148 148
         # Starting the Plugins class
149
-        Plugins.bootstrap(plugins_path)
149
+        Plugins.start(plugins_path)
150 150
         # Fetching conf specs from plugins
151 151
         specs = [lodel2_specs]
152 152
         errors = list()

+ 10
- 1
lodel/settings/validator.py Dosyayı Görüntüle

@@ -74,7 +74,9 @@ class SettingValidator(object):
74 74
             res = list()
75 75
             errors = list()
76 76
             for elt in value.split(separator):
77
-                res.append(elt_validator(elt))
77
+                elt = elt_validator(elt)
78
+                if len(elt) > 0:
79
+                    res.append(elt)
78 80
             return res
79 81
         description = "Convert value to an array" if description is None else description
80 82
         cls.register_validator(
@@ -153,10 +155,17 @@ def path_val(value):
153 155
         raise SettingsValidationError("The value '%s' is not a valid path")
154 156
     return value
155 157
 
158
+def dummy_val(value): return value
159
+
156 160
 #
157 161
 #   Default validators registration
158 162
 #
159 163
 
164
+SettingValidator.register_validator(
165
+                                        'dummy',
166
+                                        dummy_val,
167
+                                        'Validate anything')
168
+
160 169
 SettingValidator.register_validator(
161 170
                                         'strip',
162 171
                                         str.strip,

+ 5
- 2
plugins/dummy/confspec.py Dosyayı Görüntüle

@@ -1,7 +1,10 @@
1 1
 #-*- coding: utf-8 -*-
2 2
 
3
+from lodel.settings.validator import SettingValidator
4
+
3 5
 CONFSPEC = {
4
-    'section1': {
5
-        'key1': None
6
+    'lodel2.section1': {
7
+        'key1': (   None,
8
+                    SettingValidator('dummy'))
6 9
     }
7 10
 }

+ 42
- 0
scripts/create_instance.sh Dosyayı Görüntüle

@@ -0,0 +1,42 @@
1
+#!/bin/bash
2
+
3
+usage() {
4
+	echo "Usage : $0 instance_name instance_dir [lodel_libdir]" 1>&2
5
+	exit 1
6
+}
7
+
8
+if [ $# -lt 2 ]
9
+then
10
+	echo "Not enough arguments" 1>&2
11
+	usage
12
+fi
13
+
14
+
15
+name="$1"
16
+instdir="$2"
17
+
18
+libdir="$3"
19
+libdir="${libdir:=$(realpath $(dirname $0)/..)}/"
20
+
21
+loader="$instdir/loader.py"
22
+conf="$instdir/conf.d/lodel2.ini"
23
+
24
+if [ -e "$instdir" ]
25
+then
26
+	echo "Abording... "$instdir" exists" 1>&2
27
+	exit 1
28
+fi
29
+
30
+echo "Creating lodel instance directory '$instdir'"
31
+mkdir -pv "$instdir"
32
+
33
+cp -Rv $libdir/install/* $instdir
34
+
35
+# Adding lib path to loader
36
+sed -i -E "s#^(LODEL2_LIB_ABS_PATH = )None#\1'$libdir'#" "$loader"
37
+# Adding instance name to conf
38
+sed -i -E "s#^sitename = noname#sitename = $name#" "$conf"
39
+
40
+echo -e "\nInstance successfully created in $instdir"
41
+echo -e "============================\n"
42
+echo "Now you should edit '$settings' and then run : cd $instdir && make dbinit"

Loading…
İptal
Kaydet