Browse Source

Updated instance admin script and Makefile to be able to run plugins discover + webui upgrade

Yann Weber 7 years ago
parent
commit
3395f76238
5 changed files with 57 additions and 16 deletions
  1. 3
    0
      install/Makefile
  2. 22
    11
      install/loader.py
  3. 25
    3
      install/lodel_admin.py
  4. 4
    2
      lodel/plugin/plugins.py
  5. 3
    0
      plugins/webui/__init__.py

+ 3
- 0
install/Makefile View File

@@ -10,3 +10,6 @@ init_db: dyncode
10 10
 
11 11
 list_hooks: dyncode
12 12
 	$(python) -c 'import lodel_admin; lodel_admin.list_registered_hooks()'
13
+
14
+discover_plugins:
15
+	$(python) -c 'import lodel_admin; lodel_admin.update_plugin_discover_cache()'

+ 22
- 11
install/loader.py View File

@@ -1,30 +1,41 @@
1 1
 #-*- coding: utf-8 -*-
2 2
 
3
+##@brief Lodel2 loader script
4
+#
5
+#@note If you want to avoid settings loading you can set the environment
6
+#variable LODEL2_NO_SETTINGS_LOAD (see @ref install.lodel_admin.update_plugin_discover_cache()
7
+#
8
+
3 9
 import sys, os, os.path
4 10
 #
5 11
 # Bootstraping
6 12
 #
7 13
 LODEL2_LIB_ABS_PATH = None
8 14
 if LODEL2_LIB_ABS_PATH is not None:
15
+    if not os.path.isdir(LODEL2_LIB_ABS_PATH):
16
+        print("FATAL ERROR : the LODEL2_LIB_ABS_PATH variable in loader.py is \
17
+not correct : '%s'" % LODEL2_LIB_ABS_PATH, file=sys.stderr)
9 18
     sys.path.append(os.path.dirname(LODEL2_LIB_ABS_PATH))
10 19
 
11 20
 try:
12 21
     import lodel
13
-except ImportError:
22
+except ImportError as e:
14 23
     print("Unable to load lodel module. exiting...")
24
+    print(e)
15 25
     exit(1)
16 26
 
17
-#
18
-# Loading settings
19
-#
20
-from lodel.settings.settings import Settings as settings
21
-if not settings.started():
22
-    settings('conf.d')
23
-from lodel.settings import Settings
27
+if 'LODEL2_NO_SETTINGS_LOAD' not in os.environ:
28
+    #
29
+    # Loading settings
30
+    #
31
+    from lodel.settings.settings import Settings as settings
32
+    if not settings.started():
33
+        settings('conf.d')
34
+    from lodel.settings import Settings
24 35
 
25
-#Starts hooks
26
-from lodel.plugin import LodelHook
27
-from lodel.plugin import core_hooks
36
+    #Starts hooks
37
+    from lodel.plugin import LodelHook
38
+    from lodel.plugin import core_hooks
28 39
 
29 40
 def start():
30 41
     #Load plugins

+ 25
- 3
install/lodel_admin.py View File

@@ -2,10 +2,16 @@
2 2
 
3 3
 import sys
4 4
 import os, os.path
5
-import loader
5
+import argparse
6 6
 
7
-from lodel.settings import Settings
8
-from lodel import logger
7
+"""
8
+#Dirty hack to solve symlinks problems :
9
+#   When loader was imported the original one (LODEL_LIBDIR/install/loader)
10
+#   because lodel_admin.py is a symlink from this folder
11
+#Another solution can be delete loader from install folder
12
+sys.path[0] = os.getcwd()
13
+import loader
14
+"""
9 15
 
10 16
 ## @brief Utility method to generate python code given an emfile and a
11 17
 # translator
@@ -27,6 +33,7 @@ def generate_dyncode(model_file, translator):
27 33
 # @param translator str : a translator name
28 34
 # @param output_filename str : the output file
29 35
 def create_dyncode(model_file, translator, output_filename):
36
+    from lodel import logger
30 37
     dyncode = generate_dyncode(model_file, translator)
31 38
     with open(output_filename, 'w+') as out_fd:
32 39
         out_fd.write(dyncode)
@@ -36,6 +43,8 @@ def create_dyncode(model_file, translator, output_filename):
36 43
 
37 44
 ## @brief Refresh dynamic leapi code from settings
38 45
 def refresh_dyncode():
46
+    import loader
47
+    from lodel.settings import Settings
39 48
     # EditorialModel update/refresh
40 49
     
41 50
     # TODO
@@ -120,3 +129,16 @@ def list_registered_hooks():
120 129
             print(msg)
121 130
         print("\n")
122 131
 
132
+##@brief update plugin's discover cache
133
+#@note impossible to give arguments from a Makefile...
134
+#@todo write a __main__ to be able to run ./lodel_admin
135
+def update_plugin_discover_cache(path_list = None):
136
+    os.environ['LODEL2_NO_SETTINGS_LOAD'] = 'True'
137
+    import loader
138
+    from lodel.plugin.plugins import Plugin
139
+    res = Plugin.discover(path_list)
140
+    print("Plugin discover result in %s :\n" % res['path_list'])
141
+    for pname, pinfos in res['plugins'].items():
142
+        print("\t- %s %s -> %s" % (
143
+            pname, pinfos['version'], pinfos['path']))
144
+    

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

@@ -41,7 +41,7 @@ MANDATORY_VARNAMES = [PLUGIN_NAME_VARNAME, LOADER_FILENAME_VARNAME,
41 41
     PLUGIN_VERSION_VARNAME]
42 42
 
43 43
 PLUGIN_DEFAULT_TYPE = 'default'
44
-PLUGINS_TYPES = [PLUGIN_DEFAULT_TYPE, 'datasource', 'session_handler']
44
+PLUGINS_TYPES = [PLUGIN_DEFAULT_TYPE, 'datasource', 'session_handler', 'ui']
45 45
 
46 46
 
47 47
 ##@brief Describe and handle version numbers
@@ -529,7 +529,9 @@ name differ from the one found in plugin's init file"
529 529
     #found plugin in a file...
530 530
     #@return a dict {'path_list': [...], 'plugins': { see @ref _discover }}
531 531
     @classmethod
532
-    def discover(cls, paths):
532
+    def discover(cls, paths = None):
533
+        if paths is None:
534
+            paths = DEFAULT_PLUGINS_PATH_LIST
533 535
         tmp_res = []
534 536
         for path in paths:
535 537
             tmp_res += cls._discover(path)

+ 3
- 0
plugins/webui/__init__.py View File

@@ -1,2 +1,5 @@
1
+__plugin_name__ = 'webui'
2
+__version__ = '0.0.1'
3
+__type__ = 'ui'
1 4
 __loader__ = 'main.py'
2 5
 __confspec__ = 'confspec.py'

Loading…
Cancel
Save