def _verifyPluginFolder( self, folder: str) -> typing.List[typing.Type[PluginMixin]]: self._logger.info("Verify plugin in folder: %s", folder) oldClasses = [x.clazz for x in self._app.getConfig().plugins] root = Path(folder) if not (root / "__init__.py").exists(): raise RuntimeError("Plugin folder must contains __init__.py") targetPath = Path(f"IceSpringMusicPlayer/plugins/{root.name}") if targetPath.exists(): self._logger.info("Plugin already exists.") raise RuntimeError("Plugin Already Exists") self._logger.info("Copy plugin folder to plugins dir %s", targetPath) root.copytree(targetPath) try: classes = self.findPluginClassesInFolder(str(targetPath)) classes = [x for x in classes if x not in oldClasses] except Exception as e: self._logger.info("Exception occurred: %s", e, e) self._logger.info("Remove folder: %s", targetPath) targetPath.rmtree() raise e if len(classes) == 0: self._logger.info("No plugin found in folder, remove folder") targetPath.rmtree() raise RuntimeError("No plugin found") return classes
def removePlugin(self, plugin: Plugin) -> None: self._logger.info("Remove plugin: %s", plugin.clazz) assert not plugin.clazz.isSystemPlugin() assert not self.isPluginUsedInMainWindow( plugin), "Plugin used in main window" stem = plugin.clazz.__module__.split(".")[0] path = Path(f"IceSpringMusicPlayer/plugins/{stem}") self._logger.info("Remove plugin folder: %s", path) now = datetime.now().strftime("%Y-%m-%d-%H-%M-%S") targetPath = Path(f"IceSpringMusicPlayer/recycles/{now}/{stem}") self._logger.info("Plugin is backup to %s", targetPath) targetPath.parent.mkdir(parents=True, exist_ok=True) path.copytree(targetPath) path.rmtree() self._logger.info("Remove plugin from registry") self._app.getConfig().plugins.remove(plugin) self._logger.info("> Signal pluginRemoved emitting...") self.pluginsRemoved.emit([plugin]) self._logger.info("< Signal pluginRemoved emitted.")