Browse Source

Multiple bugfixes + create_instance.sh script update

- Add an update feature to create_instance.sh script
- Updated webui plugin load instruction (running loader.start() in run)
- Updated the way EmCmponents handles EmGroup
- Updated the way EmFields handles EmClass
- Updated xmlfile translator according to EmComponent modification
Yann Weber 8 years ago
parent
commit
557d277186

BIN
examples/em_test.pickle View File


+ 5
- 2
install/loader.py View File

@@ -14,7 +14,6 @@ except ImportError:
14 14
     print("Unable to load lodel module. exiting...")
15 15
     exit(1)
16 16
 
17
-
18 17
 #
19 18
 # Loading settings
20 19
 #
@@ -29,16 +28,19 @@ from lodel.plugin import core_hooks
29 28
 
30 29
 def start():
31 30
     #Load plugins
31
+    from lodel import logger
32 32
     from lodel.plugin import Plugin
33
+    logger.debug("Loader.start() called")
33 34
     Plugin.load_all()
34 35
 
35 36
     LodelHook.call_hook('lodel2_bootstraped', '__main__', None)
36 37
 
37 38
 
38 39
 if __name__ == '__main__':
39
-    start()
40 40
 
41
+    start()
41 42
     if Settings.runtest:
43
+        start()
42 44
         import unittest
43 45
         import tests
44 46
         loader = unittest.TestLoader()
@@ -52,6 +54,7 @@ if __name__ == '__main__':
52 54
         exit()
53 55
 
54 56
     LodelHook.call_hook('lodel2_loader_main', '__main__', None)
57
+
55 58
     #Run interative python
56 59
     import code
57 60
     print("""

+ 9
- 6
lodel/editorial_model/components.py View File

@@ -170,7 +170,6 @@ class EmClass(EmComponent):
170 170
             if not emfield.data_handler_instance.can_override(parent_field.data_handler_instance):
171 171
                 raise AttributeError("'%s' field override a parent field, but data_handles are not compatible" % emfield.uid)
172 172
         self.__fields[emfield.uid] = emfield
173
-        emfield._emclass = self
174 173
         return emfield
175 174
     
176 175
     ##@brief Create a new EmField and add it to the EmClass
@@ -179,7 +178,7 @@ class EmClass(EmComponent):
179 178
     # @param **field_kwargs :  EmField constructor parameters ( see @ref EmField.__init__() ) 
180 179
     def new_field(self, uid, data_handler, **field_kwargs):
181 180
         assert_edit()
182
-        return self.add_field(EmField(uid, data_handler, **field_kwargs))
181
+        return self.add_field(EmField(uid, data_handler, self, **field_kwargs))
183 182
 
184 183
     def d_hash(self):
185 184
         m = hashlib.md5()
@@ -216,7 +215,7 @@ class EmField(EmComponent):
216 215
     # @param help_text MlString|str|dict : help text
217 216
     # @param group EmGroup :
218 217
     # @param **handler_kwargs : data handler arguments
219
-    def __init__(self, uid, data_handler, display_name = None, help_text = None, group = None, **handler_kwargs):
218
+    def __init__(self, uid, data_handler, em_class = None, display_name = None, help_text = None, group = None, **handler_kwargs):
220 219
         from lodel.leapi.datahandlers.base_classes import DataHandler
221 220
         super().__init__(uid, display_name, help_text, group)
222 221
         ##@brief The data handler name
@@ -228,9 +227,11 @@ class EmField(EmComponent):
228 227
         ##@brief Stores data handler instanciation options
229 228
         self.data_handler_options = handler_kwargs
230 229
         ##@brief Stores the emclass that contains this field (set by EmClass.add_field() method)
231
-        self._emclass = None
230
+        self._emclass = em_class
231
+        if self._emclass is None:
232
+            warnings.warn("No EmClass for field %s" %uid)
232 233
         if group is None:
233
-            warnings.warn("NO GROUP FOR FIELD %s" % uid)
234
+            warnings.warn("No EmGroup for field  %s" % uid)
234 235
         else:
235 236
             group.add_components([self])
236 237
 
@@ -343,7 +344,9 @@ class EmGroup(object):
343 344
         for component in components:
344 345
             if isinstance(component, EmField):
345 346
                 if component._emclass is None:
346
-                    warnings.warn("Adding an orphan EmField to an EmGroup")
347
+                    msg = "Adding an orphan EmField '%s' to EmGroup '%s'"
348
+                    msg %= (component, self)
349
+                    warnings.warn(msg)
347 350
             elif not isinstance(component, EmClass):
348 351
                 raise EditorialModelError("Expecting components to be a list of EmComponent, but %s found in the list" % type(component))
349 352
         self.__components |= set(components)

+ 9
- 11
lodel/editorial_model/translator/xmlfile.py View File

@@ -316,7 +316,7 @@ def load_class_xml(model, elem):
316 316
         
317 317
     fields = elem.find('fields')
318 318
     for field in fields:
319
-        emfield = load_field_xml(model, field)
319
+        emfield = load_field_xml(model, field, emclass)
320 320
         l_emfields = emclass.fields()
321 321
         incls = False
322 322
         for emf in l_emfields:
@@ -329,10 +329,11 @@ def load_class_xml(model, elem):
329 329
     return emclass
330 330
     
331 331
 ##@brief Creates a EmField from a xml description
332
-# @param elem : the element which represents the EmField
333
-# @param model  : the model which will contain the new field
334
-# @return a new EmField object
335
-def load_field_xml(model, elem):
332
+#@param elem : the element which represents the EmField
333
+#@param model  : the model which will contain the new field
334
+#@param emclass EmClass : the EmClass of the field
335
+#@return a new EmField object
336
+def load_field_xml(model, elem, emclass):
336 337
     uid = elem.find('uid').text
337 338
     if elem.find('display_name').text is None:
338 339
         name = None
@@ -354,16 +355,13 @@ def load_field_xml(model, elem):
354 355
         group = None
355 356
         
356 357
     dhdl = elem.find('datahandler_name')
358
+    dhdl_opts = {}
357 359
     if dhdl.text is not None:
358 360
         dhdl_opts = elem.find('datahandler_options')
359
-
360 361
         if dhdl_opts is not None:
361 362
             dhdl_options = load_dhdl_options_xml(model, dhdl_opts) 
362
-            emfield = EmField(uid, dhdl.text, name, help_text, group, **dhdl_options)
363
-        else:
364
-            emfield = EmField(uid, dhdl.text, name, help_text, group)
365
-    else:
366
-        emfield = EmField(uid, dhdl.text, name, help_text, group)
363
+    emfield = EmField(
364
+        uid, dhdl.text, emclass, name, help_text, group, **dhdl_options)
367 365
     
368 366
     return emfield
369 367
 

+ 16
- 6
lodel/leapi/leobject.py View File

@@ -242,14 +242,24 @@ class LeObject(object):
242 242
             ro_ds, rw_ds = cls._datasource_name
243 243
         #Read only datasource initialisation
244 244
         cls._ro_datasource = cls._init_datasource(ro_ds, True)
245
-        log_msg = "Read only datasource %s initialized for LeObject %s"
246
-        log_msg %= (ro_ds, cls.__name__)
247
-        logger.debug(log_msg)
245
+        if cls._ro_datasource is None:
246
+            log_msg = "No read only datasource set for LeObject %s"
247
+            log_msg %= cls.__name__
248
+            logger.debug(log_msg)
249
+        else:
250
+            log_msg = "Read only datasource '%s' initialized for LeObject %s"
251
+            log_msg %= (ro_ds, cls.__name__)
252
+            logger.debug(log_msg)
248 253
         #Read write datasource initialisation
249 254
         cls._rw_datasource = cls._init_datasource(rw_ds, False)
250
-        log_msg = "Read&write only datasource %s initialized for LeObject %s"
251
-        log_msg %= (rw_ds, cls.__name__)
252
-        logger.debug(log_msg)
255
+        if cls._ro_datasource is None:
256
+            log_msg = "No read/write datasource set for LeObject %s"
257
+            log_msg %= cls.__name__
258
+            logger.debug(log_msg)
259
+        else:
260
+            log_msg = "Read/write datasource '%s' initialized for LeObject %s"
261
+            log_msg %= (ro_ds, cls.__name__)
262
+            logger.debug(log_msg)
253 263
         
254 264
 
255 265
     ##@brief Replace the _datasource attribute value by a datasource instance

+ 1
- 1
lodel/leapi/query.py View File

@@ -333,7 +333,7 @@ field to use for the relational filter"
333 333
                 res_filters.append((field,operator, value))
334 334
         
335 335
         if len(err_l) > 0:
336
-            raise LeApiDataCheckError(
336
+            raise LeApiDataCheckErrors(
337 337
                                         "Error while preparing filters : ",
338 338
                                         err_l)
339 339
         return (res_filters, rel_filters)

+ 19
- 7
scripts/create_instance.sh View File

@@ -1,10 +1,18 @@
1 1
 #!/bin/bash
2 2
 
3 3
 usage() {
4
-	echo "Usage : $0 instance_name instance_dir [lodel_libdir]" 1>&2
4
+	echo -e "Usage : $0 instance_name (instance_dir|-u) [lodel_libdir]" 1>&2
5
+	echo -e "\n\tIf -u given as first argument update instance's loader.py" 1>&2
5 6
 	exit 1
6 7
 }
7 8
 
9
+cp_loader() {
10
+	cp -Rv $libdir/install/loader.py $instdir/
11
+	# Adding lib path to loader
12
+	sed -i -E "s#^(LODEL2_LIB_ABS_PATH = )None#\1'$libdir'#" "$loader"
13
+}
14
+
15
+
8 16
 if [ $# -lt 2 ]
9 17
 then
10 18
 	echo "Not enough arguments" 1>&2
@@ -12,6 +20,7 @@ then
12 20
 fi
13 21
 
14 22
 
23
+
15 24
 name="$1"
16 25
 instdir="$2"
17 26
 
@@ -21,6 +30,13 @@ libdir="${libdir:=$(realpath $(dirname $0)/..)}/"
21 30
 loader="$instdir/loader.py"
22 31
 conf="$instdir/conf.d/lodel2.ini"
23 32
 
33
+if [ $1 = '-u' ]
34
+then
35
+	#Update instance
36
+	cp_loader
37
+	exit 0
38
+fi
39
+
24 40
 if [ -e "$instdir" ]
25 41
 then
26 42
 	echo "Abording... "$instdir" exists" 1>&2
@@ -34,19 +50,15 @@ chmod 700 "$instdir/sessions"
34 50
 
35 51
 #cp -Rv $libdir/install/* $instdir
36 52
 cp -Rv $libdir/install/conf.d $instdir/
37
-cp -Rv $libdir/install/loader.py $instdir/
38 53
 cp -Rv $libdir/examples/em_test.pickle $instdir/editorial_model.pickle
39 54
 ln -sv $libdir/install/Makefile $instdir/Makefile
40 55
 ln -sv $libdir/install/lodel_admin.py $instdir/lodel_admin.py
41 56
 ln -sv $libdir/plugins $instdir/plugins
42
-
43
-
44
-
45
-# Adding lib path to loader
46
-sed -i -E "s#^(LODEL2_LIB_ABS_PATH = )None#\1'$libdir'#" "$loader"
57
+cp_loader
47 58
 # Adding instance name to conf
48 59
 sed -i -E "s#^sitename = noname#sitename = $name#" "$conf"
49 60
 
61
+
50 62
 echo -e "\nInstance successfully created in $instdir"
51 63
 echo -e "============================\n"
52 64
 echo "Now you should edit files in '${instdir}/conf.d/' and then run : cd $instdir && make dyncode"

BIN
tests/editorial_model.pickle View File


+ 2
- 2
tests/leapi/query/test_filtered.py View File

@@ -3,7 +3,7 @@ import unittest
3 3
 import tests.loader_utils
4 4
 from tests.leapi.query.utils import dyncode_module as dyncode
5 5
 
6
-from lodel.leapi.exceptions import LeApiDataCheckError
6
+from lodel.leapi.exceptions import *
7 7
 from lodel.leapi.query import LeDeleteQuery, LeUpdateQuery, LeGetQuery
8 8
 
9 9
 class LeFilteredQueryTestCase(unittest.TestCase):
@@ -53,7 +53,7 @@ class LeFilteredQueryTestCase(unittest.TestCase):
53 53
         )
54 54
         for invalid_filter in invalid_filters:
55 55
             for q_class in self.q_classes:
56
-                with self.assertRaises( LeApiDataCheckError,
56
+                with self.assertRaises( LeApiDataCheckErrors,
57 57
                                         msg="for filter '%s'" % (invalid_filter,)):
58 58
                     q_class(dyncode.Publication, invalid_filter)
59 59
             

Loading…
Cancel
Save