def _install_archive_list(archive, archive_list, force): """Install plugin from archive list""" # Get the plugin cache path and create if needed plugins_path = os.path.join(Config.get('path/plugin_cache'), 'local') os.makedirs(plugins_path, exist_ok=True) # Extract found plugins from archive to install retval = True for plugin_name, plugin_list in archive_list: # Get the plugin path plugin_path = os.path.join(plugins_path, plugin_name) try: # Remove the previous plugin path, if necessary if Config.remove_path(plugin_path): # Log caching plugin Logger.debug(f'MEG Plugins: Locally caching plugin <{plugin_path}>') # Extract each plugin from archive to install archive.extractall(plugin_path, plugin_list) # Install cached plugin retval = PluginManager.install_path(plugin_path, force) and retval else: retval = False except Exception as e: # Log that caching plugin locally failed Logger.warning(f'MEG Plugins: {e}') Logger.warning(f'MEG Plugins: Failed to locally cache plugin <{plugin_path}>') retval = False return retval
def install(name, force=False): """Install plugin by name""" # Log installing plugin Logger.debug(f'MEG Plugins: Installing plugin <{name}>') # Get the available plugin by name available_plugin = PluginManager.get_available(name) if available_plugin is None: # Log failed to install plugin Logger.warning(f'MEG Plugins: Failed to install plugin <{name}>') return False # Log updating plugin cache information Logger.debug( f'MEG Plugins: Found plugin cache information <{available_plugin.path()}>' ) PluginManager._log_plugin(available_plugin) # Get installed plugin by name, if present plugin = PluginManager.get(name) if plugin is not None: # Check plugin is up to date or forcing installation if available_plugin.compare_versions(plugin) <= 0 and not force: return True # Get the plugins cache path plugins_path = Config.get('path/plugins') # Get the plugin installation path plugin_basename = os.path.basename(available_plugin.path()) plugin_path = os.path.join(plugins_path, plugin_basename) try: # Remove the previous plugin path, if necessary if not Config.remove_path(plugin_path): return False # Open the local plugin cache repository cache_path = os.path.join(Config.get('path/plugin_cache'), 'remote', PluginManager.DEFAULT_BARE_REPO_PATH) cache = GitManager.open(cache_path, bare=True) if cache is None: raise GitException( f'Could not open local plugin cache <{cache_path}>') # Log installing plugin Logger.debug(f'MEG Plugins: Installing plugin <{plugin_path}>') # Install plugin by checking out cache.checkout_head(directory=plugins_path, paths=[plugin_basename + '/*']) # Load (or update) plugin information plugin = PluginManager._update(plugin_path, force) if plugin is not None: # Log plugin information PluginManager._log_plugin(plugin) # Setup plugin dependencies plugin.setup().check_returncode() # Add the plugin PluginManager.__instance['plugins'][plugin.name()] = plugin except Exception as e: # Log that loading the plugin cache information failed Logger.warning(f'MEG Plugins: {e}') Logger.warning( f'MEG Plugins: Could not load information for plugin <{plugin_path}>' ) return False return True
def install_path(path, force=False): """Install plugin from local path""" # Check there is plugin manager instance if PluginManager.__instance is None: PluginManager() if PluginManager.__instance is not None: # Check if path does not exist if os.path.exists(path) and os.path.isdir(path): # Log trying to load plugin information from path Logger.debug( f'MEG Plugins: Installing plugin from path <{path}>') try: # Get the plugin information for the path if no other version is installed plugin = PluginManager._update(path, force) if plugin is not None: # Log plugin information PluginManager._log_plugin(plugin) # Log trying to load plugin information from path Logger.debug( f'MEG Plugins: Installing plugin <{plugin.name()}>' ) elif not force: # The same version exists and no force so this is installed return True # Get the installed plugin path plugin_path = os.path.join(Config.get('path/plugins'), os.path.basename(path)) # Remove the previous plugin path, if necessary if not Config.remove_path(plugin_path): return False # Copy the path to the plugins directory shutil.copytree(path, plugin_path) # Load (or update) plugin information plugin = Plugin(plugin_path) if plugin is not None: # Log plugin information PluginManager._log_plugin(plugin) # Setup plugin dependencies plugin.setup().check_returncode() # Add the plugin PluginManager.__instance['plugins'][ plugin.name()] = plugin return True except Exception as e: # Log that installing the plugin from the path failed Logger.warning(f'MEG Plugins: {e}') Logger.warning( f'MEG Plugins: Failed to install plugin from path <{path}>' ) return False
def uninstall(name): """Uninstall plugin by name""" # Log uninstalling plugin Logger.debug(f'MEG Plugins: Uninstalling plugin <{name}>') # Get the plugin by name plugin = PluginManager.get(name) if plugin is not None: try: # Disable (and unload) the plugin, if needed plugin.disable() # Remove the plugin instance PluginManager.__instance['plugins'].pop(name) # Remove the plugin directory return Config.remove_path(plugin.path()) except Exception as e: # Log uninstalling plugin failed Logger.warning(f'MEG Plugins: {e}') Logger.warning(f'MEG Plugins: Failed to uninstall plugin <{name}>') return False return True
def clean_plugin_cache(): """Clean plugin cache""" # Remove the plugin cache directory or the block file return Config.remove_path(Config.get('path/plugin_cache'))
def clean_plugins(): """Clean plugins""" # Remove the plugins directory or the block file return Config.remove_path(Config.get('path/plugins'))
def clean_cache(): """Clean dependency cache""" # Remove the cache directory or the block file return Config.remove_path(Config.get('path/cache'))