Пример #1
0
 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
Пример #2
0
 def open_repo_panel():
     """Open a repository."""
     dialog = QtWidgets.QFileDialog()
     # Only allow directories
     dialog.setFileMode(QtWidgets.QFileDialog.Directory)
     dialog.setOption(QtWidgets.QFileDialog.ShowDirsOnly, True)
     if dialog.exec_():
         repo = GitManager.open(dialog.selectedFiles()[0])
         App.get_window().push_view(ui.RepoPanel(repo))
         App.save_repo_entry(repo.path)
Пример #3
0
 def update_cache():
     """Update cached plugin information"""
     # Check there is plugin manager instance
     update = False
     if PluginManager.__instance is None:
         PluginManager(False)
         update = True
     if PluginManager.__instance is None:
         return False
     # Log updating plugin information
     Logger.debug(f'MEG Plugins: Updating plugin cache')
     # Clear previous plugin cache information
     if 'plugin_cache' not in PluginManager.__instance or not isinstance(
             PluginManager.__instance['plugin_cache'], dict):
         PluginManager.__instance['plugin_cache'] = {}
     # Get the plugin cache path and create if needed
     cache_path = os.path.join(Config.get('path/plugin_cache'), 'remote')
     os.makedirs(cache_path, exist_ok=True)
     # Open or clone the plugins repository with the plugin cache path
     cache = GitManager.open_or_clone(
         os.path.join(cache_path, PluginManager.DEFAULT_BARE_REPO_PATH),
         Config.get('plugins/url', PluginManager.DEFAULT_CACHE_URL),
         bare=True)
     if cache is None:
         # Log that loading the plugin cache information failed
         Logger.warning(
             f'MEG Plugins: Could not update plugin cache information')
         return False
     try:
         # Log updating plugin cache information
         Logger.debug(f'MEG Plugins: Fetching plugin cache information')
         # Fetch and update the plugin cache
         cache.fetch_all()
         fetch_head = cache.lookup_reference('FETCH_HEAD')
         if fetch_head is not None:
             cache.head.set_target(fetch_head.target)
         # Checkout the plugin information files
         cache.checkout_head(
             directory=cache_path,
             paths=['*/' + PluginInformation.DEFAULT_PLUGIN_INFO_PATH])
     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 update plugin cache information')
         return False
     # Log updating plugin cache information
     return PluginManager._update_cache(cache_path, update)
Пример #4
0
 def clone(self):
     """Clone the repository."""
     # Setup repository
     username = None
     password = None
     if self.enter_credentials_radio.isChecked():
         (username, password) = App.open_credential_dialog()
     elif self.use_stored_credentials_radio.isChecked():
         pass
         # TODO
     repo_url = self.server_text_edit.text()
     repo_path = self.directory
     # TODO: Handle username+password
     # Set the config
     repo = GitManager.clone(repo_url, repo_path)
     if repo is not None:
         App.save_repo_entry(repo_path, repo_url)
         App.get_window().push_view(RepoPanel(repo))
     else:
         Logger.warning(f'MEG UIManager: Could not clone repo "{repo_url}"')
         QtWidgets.QMessageBox.warning(
             App.get_window(), App.get_name(),
             f'Could not clone the repo "{repo_url}"')