Browse Source

Now plugins can check EM and invalidate activation

They have to implement a _activate() method in their __init__.py file
Yann Weber 8 years ago
parent
commit
3adad7bb02
4 changed files with 12 additions and 18 deletions
  1. 3
    8
      install/loader.py
  2. 4
    4
      lodel/plugin/plugins.py
  3. 5
    0
      plugins/dummy/__init__.py
  4. 0
    6
      plugins/dummy/main.py

+ 3
- 8
install/loader.py View File

@@ -23,19 +23,14 @@ settings('conf.d')
23 23
 from lodel.settings import Settings
24 24
 
25 25
 
26
-#Load plugins
27
-from lodel.plugin import Plugin
28
-Plugin.load_all()
29 26
 
30 27
 
31 28
 from lodel.plugin import LodelHook
32 29
 
33 30
 def start():
34
-    #Importing dynamic code classes in lodel.leapi
35
-    import leapi_dyncode
36
-    import lodel.leapi
37
-    for cls in leapi_dyncode.dynclasses:
38
-        setattr(lodel.leapi, cls.__name__, cls)
31
+    #Load plugins
32
+    from lodel.plugin import Plugin
33
+    Plugin.load_all()
39 34
 
40 35
     LodelHook.call_hook('lodel2_bootstraped', '__main__', None)
41 36
 

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

@@ -125,11 +125,11 @@ class Plugin(object):
125 125
     def load(self):
126 126
         from lodel import logger
127 127
         try:
128
-            res = self.module._activate()
128
+            test_fun = self.module._activate
129 129
         except AttributeError:
130
-            logger.debug("No _activate method found for plugin %s. Assuming plugin is ready to be loaded")
131
-            res = True
132
-
130
+            logger.debug("No _activate method found for plugin %s. Assuming plugin is ready to be loaded" % self.name)
131
+            test_fun = lambda:True
132
+        res = test_fun()
133 133
         if not(res is True):
134 134
             raise PluginError(res)
135 135
 

+ 5
- 0
plugins/dummy/__init__.py View File

@@ -10,4 +10,9 @@ __fullname__ = "Dummy plugin"
10 10
 #
11 11
 #@return True if checks are OK else return a string with a reason
12 12
 def _activate():
13
+    import leapi_dyncode
14
+    print("Testing dynamic objects : ")
15
+    print("Object : ", leapi_dyncode.Object)
16
+    print("Publication : ", leapi_dyncode.Publication)
17
+    print("Publication fields : ", leapi_dyncode.Publication.fieldnames())
13 18
     return True

+ 0
- 6
plugins/dummy/main.py View File

@@ -2,12 +2,6 @@
2 2
 
3 3
 from lodel.plugin import LodelHook
4 4
 
5
-def _activate():
6
-    return True
7
-    
8
-
9
-##@brief Hook's callback example
10
-@LodelHook('leapi_get_pre')
11 5
 @LodelHook('leapi_get_post')
12 6
 @LodelHook('leapi_update_pre')
13 7
 @LodelHook('leapi_update_post')

Loading…
Cancel
Save