:return: all plugins instances (enabled or not)
()
| 174 | |
| 175 | plugins = None |
| 176 | def get_plugins(): |
| 177 | """ |
| 178 | :return: all plugins instances (enabled or not) |
| 179 | """ |
| 180 | # Cache plugins search |
| 181 | global plugins |
| 182 | if plugins != None: return plugins |
| 183 | |
| 184 | plugins_paths = get_plugins_paths() |
| 185 | plugins = [] |
| 186 | |
| 187 | for plugins_path in plugins_paths: |
| 188 | if not os.path.isdir(plugins_path): |
| 189 | continue |
| 190 | |
| 191 | for dir in os.listdir(plugins_path): |
| 192 | # Each plugin must have a manifest.json and a plugin.py |
| 193 | plugin_path = os.path.join(plugins_path, dir) |
| 194 | |
| 195 | # Do not load test plugin unless we're in test mode |
| 196 | if os.path.basename(plugin_path).endswith('test') and not settings.TESTING: |
| 197 | continue |
| 198 | |
| 199 | # Ignore .gitignore |
| 200 | if os.path.basename(plugin_path) == '.gitignore': |
| 201 | continue |
| 202 | |
| 203 | # Check plugin required files |
| 204 | if not valid_plugin(plugin_path): |
| 205 | continue |
| 206 | |
| 207 | # Instantiate the plugin |
| 208 | try: |
| 209 | try: |
| 210 | if settings.TESTING: |
| 211 | module = importlib.import_module("app.media_test.plugins.{}".format(dir)) |
| 212 | else: |
| 213 | module = importlib.import_module("plugins.{}".format(dir)) |
| 214 | |
| 215 | plugin = (getattr(module, "Plugin"))() |
| 216 | except (ImportError, AttributeError) as plugin_error: |
| 217 | try: |
| 218 | module = importlib.import_module("coreplugins.{}".format(dir)) |
| 219 | plugin = (getattr(module, "Plugin"))() |
| 220 | except (ImportError, AttributeError) as coreplugin_error: |
| 221 | raise coreplugin_error from plugin_error |
| 222 | |
| 223 | # Check version |
| 224 | manifest = plugin.get_manifest() |
| 225 | if 'webodmMinVersion' in manifest: |
| 226 | min_version = manifest['webodmMinVersion'] |
| 227 | manifest_path = os.path.join(plugin_path, "manifest.json") |
| 228 | |
| 229 | if versionToInt(min_version) > versionToInt(settings.VERSION): |
| 230 | logger.warning( |
| 231 | "In {} webodmMinVersion is set to {} but WebODM version is {}. Plugin will not be loaded. Update WebODM.".format( |
| 232 | manifest_path, min_version, settings.VERSION)) |
| 233 | continue |
no test coverage detected