Browse Source

Deleted datasources plugins and add a settings for datasources declaration

- now datasources are declared with two conf keys : read_only and identifier
- the old datasources plugin hook is now declared in lodel/plugin/core_hooks.py. This file is imported after lodel/plugin/hooks.py in the loader.py
Yann Weber 8 years ago
parent
commit
83afc6b6dd

+ 2
- 3
install/loader.py View File

22
 settings('conf.d')
22
 settings('conf.d')
23
 from lodel.settings import Settings
23
 from lodel.settings import Settings
24
 
24
 
25
-
26
-
27
-
25
+#Starts hooks
28
 from lodel.plugin import LodelHook
26
 from lodel.plugin import LodelHook
27
+from lodel.plugin import core_hooks
29
 
28
 
30
 def start():
29
 def start():
31
     #Load plugins
30
     #Load plugins

plugins/datasources/main.py → lodel/plugin/core_hooks.py View File

4
 from lodel.settings import Settings
4
 from lodel.settings import Settings
5
 from lodel import logger
5
 from lodel import logger
6
 
6
 
7
+##@package lodel.plugin.core_hooks
8
+#@brief Lodel2 internal hooks declaration
7
 
9
 
8
 ##@brief Bootstrap hook to check datasources configuration
10
 ##@brief Bootstrap hook to check datasources configuration
9
 @LodelHook('lodel2_bootstraped')
11
 @LodelHook('lodel2_bootstraped')

+ 1
- 0
lodel/plugin/hooks.py View File

83
     @classmethod
83
     @classmethod
84
     def __reset__(cls):
84
     def __reset__(cls):
85
         cls._hooks = dict()
85
         cls._hooks = dict()
86
+

+ 2
- 2
lodel/plugin/plugins.py View File

73
         try:
73
         try:
74
             loader = SourceFileLoader(plugin_module, init_source)
74
             loader = SourceFileLoader(plugin_module, init_source)
75
             self.module = loader.load_module()
75
             self.module = loader.load_module()
76
-        except ImportError as e:
77
-             raise PluginError("Failed to load plugin '%s'. It seems that the plugin name is not valid" % plugin_name)
76
+        except (ImportError,FileNotFoundError) as e:
77
+             raise PluginError("Failed to load plugin '%s'. It seems that the plugin name is not valid or the plugin do not exists" % plugin_name)
78
 
78
 
79
         # loading confspecs
79
         # loading confspecs
80
         try:
80
         try:

+ 8
- 10
lodel/settings/validator.py View File

322
                         SettingValidator('int', none_is_valid = True)),
322
                         SettingValidator('int', none_is_valid = True)),
323
     },
323
     },
324
     'lodel2.editorialmodel': {
324
     'lodel2.editorialmodel': {
325
-        'emfile': ( 'em.pickle',
326
-                    SettingValidator('strip')),
327
-        'emtranslator': (   'picklefile',
328
-                            SettingValidator('strip')),
329
-        'dyncode': (    'leapi_dyncode.py',
330
-                        SettingValidator('strip')),
331
-        'groups': ( '',
332
-                    SettingValidator('list')),
333
-        'editormode': ( False,
334
-                        SettingValidator('bool')),
325
+        'emfile': ( 'em.pickle', SettingValidator('strip')),
326
+        'emtranslator': ( 'picklefile', SettingValidator('strip')),
327
+        'dyncode': ( 'leapi_dyncode.py', SettingValidator('strip')),
328
+        'groups': ( '', SettingValidator('list')),
329
+        'editormode': ( False, SettingValidator('bool')),
335
     },
330
     },
331
+    'lodel2.datasources.*': {
332
+        'read_only': (True, SettingValidator('bool')),
333
+        'identifier': ( None, SettingValidator('string'))}
336
 }
334
 }

+ 0
- 8
plugins/datasources/__init__.py View File

1
-from lodel.settings.validator import SettingValidator
2
-
3
-__loader__ = 'main.py'
4
-
5
-CONFSPEC = {
6
-                'lodel2.datasources.*': {
7
-                        'identifier': ( None,
8
-                                        SettingValidator('string'))}}

+ 1
- 1
plugins/dummy_datasource/__init__.py View File

2
 from .main import DummyDatasource as Datasource
2
 from .main import DummyDatasource as Datasource
3
 
3
 
4
 __loader__ = 'main.py'
4
 __loader__ = 'main.py'
5
-__plugin_deps__ = ['datasources']
5
+__plugin_deps__ = []
6
 
6
 
7
 CONFSPEC = {
7
 CONFSPEC = {
8
     'lodel2.datasource.dummy_datasource.*' : {
8
     'lodel2.datasource.dummy_datasource.*' : {

+ 20
- 18
plugins/dummy_datasource/main.py View File

21
                instanciate=True):
21
                instanciate=True):
22
         pass
22
         pass
23
 
23
 
24
-    ## @brief Deletes one record defined by its uid
25
-    # @param target_cls Emclass : class of the record to delete
26
-    # @param uid dict|list : a dictionary of fields and values composing the unique identifier of the record or a list of several dictionaries
27
-    # @return int : number of deleted records
28
-    def delete(self, target_cls, uid):
24
+    ##@brief Deletes records according to given filters
25
+    #@param target Emclass : class of the record to delete
26
+    #@param filters list : List of filters
27
+    #@param relational_filters list : List of relational filters
28
+    #@return int : number of deleted records
29
+    def delete(self, target, filters, relational_filters):
29
         pass
30
         pass
30
 
31
 
31
-    ## @brief updates one or a list of records
32
-    # @param target_cls Emclass : class of the object to insert
33
-    # @param uids list : list of uids to update
34
-    # @param datas dict : datas to update (new values)
35
-    # @return int : Number of updated records
36
-    def update(self, target_cls, uids, **datas):
32
+    ## @brief updates records according to given filters
33
+    #@param target Emclass : class of the object to insert
34
+    #@param filters list : List of filters
35
+    #@param rel_filters list : List of relational filters
36
+    #@param upd_datas dict : datas to update (new values)
37
+    #@return int : Number of updated records
38
+    def update(self, target, filters, relational_filters, upd_datas):
37
         pass
39
         pass
38
 
40
 
39
     ## @brief Inserts a record in a given collection
41
     ## @brief Inserts a record in a given collection
40
-    # @param target_cls Emclass : class of the object to insert
41
-    # @param datas dict : datas to insert
42
-    # @return bool
43
-    def insert(self, target_cls, **datas):
42
+    # @param target Emclass : class of the object to insert
43
+    # @param new_datas dict : datas to insert
44
+    # @return the inserted uid
45
+    def insert(self, target, new_datas):
44
         pass
46
         pass
45
 
47
 
46
     ## @brief Inserts a list of records in a given collection
48
     ## @brief Inserts a list of records in a given collection
47
-    # @param target_cls Emclass : class of the objects inserted
48
-    # @param datas_list
49
+    # @param target Emclass : class of the objects inserted
50
+    # @param datas_list list : list of dict
49
     # @return list : list of the inserted records' ids
51
     # @return list : list of the inserted records' ids
50
-    def insert_multi(self, target_cls, datas_list):
52
+    def insert_multi(self, target, datas_list):
51
         pass
53
         pass

+ 2
- 2
plugins/mongodb_datasource/main.py View File

126
 
126
 
127
         return results
127
         return results
128
 
128
 
129
-    ##@brief Deletes one record defined by its uid
129
+    ##@brief Deletes records according to given filters
130
     #@param target Emclass : class of the record to delete
130
     #@param target Emclass : class of the record to delete
131
     #@param filters list : List of filters
131
     #@param filters list : List of filters
132
     #@param relational_filters list : List of relational filters
132
     #@param relational_filters list : List of relational filters
137
         res = self.__collection(target).delete_many(mongo_filters)
137
         res = self.__collection(target).delete_many(mongo_filters)
138
         return res.deleted_count
138
         return res.deleted_count
139
 
139
 
140
-    ## @brief updates one or a list of records
140
+    ## @brief updates records according to given filters
141
     #@param target Emclass : class of the object to insert
141
     #@param target Emclass : class of the object to insert
142
     #@param filters list : List of filters
142
     #@param filters list : List of filters
143
     #@param rel_filters list : List of relational filters
143
     #@param rel_filters list : List of relational filters

+ 1
- 1
tests/tests_conf.d/lodel2.ini View File

2
 debug = False
2
 debug = False
3
 sitename = noname
3
 sitename = noname
4
 plugins_path = /foo/plugins
4
 plugins_path = /foo/plugins
5
-plugins = dummy, datasources, dummy_datasource
5
+plugins = dummy, dummy_datasource
6
 
6
 
7
 [lodel2.logging.stderr]
7
 [lodel2.logging.stderr]
8
 level = Error
8
 level = Error

Loading…
Cancel
Save