Przeglądaj źródła

Update in plugins.py

Yann Weber 8 lat temu
rodzic
commit
2436d397f8
1 zmienionych plików z 11 dodań i 9 usunięć
  1. 11
    9
      lodel/plugin/plugins.py

+ 11
- 9
lodel/plugin/plugins.py Wyświetl plik

@@ -7,6 +7,7 @@ import copy
7 7
 from importlib.machinery import SourceFileLoader, SourcelessFileLoader
8 8
 
9 9
 import plugins
10
+from .exceptions import *
10 11
 
11 12
 ## @package lodel.plugins Lodel2 plugins management
12 13
 #
@@ -25,8 +26,6 @@ LOADER_FILENAME_VARNAME = '__loader__'
25 26
 PLUGIN_DEPS_VARNAME = '__plugin_deps__'
26 27
 ACTIVATE_METHOD_NAME = '_activate'
27 28
 
28
-class PluginError(Exception):
29
-    pass
30 29
 
31 30
 ##@brief Handle plugins
32 31
 #
@@ -119,7 +118,14 @@ class Plugin(object):
119 118
     #@throw PluginError if the filename was not valid
120 119
     def _import_from_init_var(self, varname):
121 120
         # Read varname
122
-        filename = getattr(self.module, varname)
121
+        try:
122
+            filename = getattr(self.module, varname)
123
+        except AttributeError:
124
+            msg = "Malformed plugin {plugin}. No {varname} found in __init__.py"
125
+            msg = msg.format(
126
+                plugin = self.name,
127
+                varname = LOADER_FILENAME_VARNAME)
128
+            raise PluginError(msg)
123 129
         #Path are not allowed
124 130
         if filename != os.path.basename(filename):
125 131
             msg = "Invalid {varname} content : '{fname}' for plugin {name}"
@@ -213,12 +219,8 @@ class Plugin(object):
213 219
         #Loading the plugin
214 220
         try:
215 221
             self.__loader_module = self._import_from_init_var(LOADER_FILENAME_VARNAME)
216
-        except AttributeError:
217
-            msg = "Malformed plugin {plugin}. No {varname} found in __init__.py"
218
-            msg = msg.format(
219
-                plugin = self.name,
220
-                varname = LOADER_FILENAME_VARNAME)
221
-            raise PluginError(msg)
222
+        except PluginError as e:
223
+            raise e
222 224
         except ImportError as e:
223 225
             msg = "Broken plugin {plugin} : {expt}"
224 226
             msg = msg.format(

Loading…
Anuluj
Zapisz