()
| 273 | |
| 274 | |
| 275 | def load_server_plugins(): |
| 276 | if not os.path.exists(USER_SERVER_PLUGINS_DIR): |
| 277 | return |
| 278 | |
| 279 | import importlib |
| 280 | |
| 281 | def load_plugin(file): |
| 282 | mod_path = file.replace(".py", "") |
| 283 | return importlib.import_module(mod_path) |
| 284 | |
| 285 | def apply_plugin(file, plugin): |
| 286 | if hasattr(plugin, "get_cond_and_uncond"): |
| 287 | import sdkit.generate.image_generator |
| 288 | |
| 289 | sdkit.generate.image_generator.get_cond_and_uncond = plugin.get_cond_and_uncond |
| 290 | log.info(f"Overridden get_cond_and_uncond with the one in the server plugin: {file}") |
| 291 | |
| 292 | for file in os.listdir(USER_SERVER_PLUGINS_DIR): |
| 293 | file_path = os.path.join(USER_SERVER_PLUGINS_DIR, file) |
| 294 | if (not os.path.isdir(file_path) and not file_path.endswith("_plugin.py")) or ( |
| 295 | os.path.isdir(file_path) and not file_path.endswith("_plugin") |
| 296 | ): |
| 297 | continue |
| 298 | |
| 299 | try: |
| 300 | log.info(f"Loading server plugin: {file}") |
| 301 | mod = load_plugin(file) |
| 302 | |
| 303 | log.info(f"Applying server plugin: {file}") |
| 304 | apply_plugin(file, mod) |
| 305 | except: |
| 306 | log.warn(f"Error while loading a server plugin") |
| 307 | log.warn(traceback.format_exc()) |
| 308 | |
| 309 | |
| 310 | def getIPConfig(): |
no test coverage detected