diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c1fa1b1..79c2c9cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Snap: - not waiting for the categories file to be retrieved from the cloud during application boot ( reduces boot time ) - caching cloud categories to the disk so they can be used in scenarios when it is not possible to retrieve them ( e.g: internet is off ) + - showing a warning popup when the Snap API is out - minor thread improvements ### UI diff --git a/bauh/gems/snap/controller.py b/bauh/gems/snap/controller.py index 2ecdd7c1..063f5575 100644 --- a/bauh/gems/snap/controller.py +++ b/bauh/gems/snap/controller.py @@ -188,6 +188,12 @@ class SnapManager(SoftwareManager): return [self.i18n['snap.notification.snapd_unavailable'].format(bold('snapd'), snap_bold), self.i18n['snap.notification.snap.disable'].format(snap_bold, bold(self.i18n['manage_window.settings.gems']))] + available, output = snap.is_api_available() + + if not available: + self.logger.warning('It seems Snap API is not available. Search output: {}'.format(output)) + return [self.i18n['snap.notifications.api.unavailable'].format(bold('Snaps'), bold('Snap'))] + def _fill_suggestion(self, pkg_name: str, priority: SuggestionPriority, out: List[PackageSuggestion]): res = self.http_client.get_json(SNAP_API_URL + '/search?q=package_name:{}'.format(pkg_name)) diff --git a/bauh/gems/snap/resources/locale/en b/bauh/gems/snap/resources/locale/en index 354910ca..cfe914b8 100644 --- a/bauh/gems/snap/resources/locale/en +++ b/bauh/gems/snap/resources/locale/en @@ -1,6 +1,7 @@ gem.snap.info=Applications published at https://snapcraft.io/store snap.notification.snapd_unavailable={} seems not to be installed or enabled. {} packages will not be available. snap.notification.snap.disable=If you do not want to use Snap applications, uncheck {} in {} +snap.notifications.api.unavailable=It seems the {} API is unavailable at the moment. It will not be possible to search for new {} applications. snap.action.refresh.status=Refreshing snap.action.refresh.label=Refresh snap.install.available_channels.title=Available channels diff --git a/bauh/gems/snap/resources/locale/es b/bauh/gems/snap/resources/locale/es index 9311ee4a..bf403bdc 100644 --- a/bauh/gems/snap/resources/locale/es +++ b/bauh/gems/snap/resources/locale/es @@ -12,6 +12,7 @@ snap.info.version=versión snap.info.size=tamaño snap.notification.snapd_unavailable={} no parece estar instalado o habilitado. Los paquetes {} estarán indisponibles. snap.notification.snap.disable=Si no desea usar aplicativos Snap, desmarque {} en {} +snap.notifications.api.unavailable = Parece que la API de {} no está disponible en este momento. No será posible buscar nuevos aplicativos {}}. snap.action.refresh.status=Actualizando snap.action.refresh.label=Actualizar snap.install.available_channels.title=Canales disponibles diff --git a/bauh/gems/snap/resources/locale/pt b/bauh/gems/snap/resources/locale/pt index 25b19832..d705e1f3 100644 --- a/bauh/gems/snap/resources/locale/pt +++ b/bauh/gems/snap/resources/locale/pt @@ -12,6 +12,7 @@ snap.info.version=versão snap.info.size=tamanho snap.notification.snapd_unavailable={} não parece estar instalado ou habilitado. Os pacotes {} estarão indisponíveis. snap.notification.snap.disable=Se não deseja usar aplicativos Snap, desmarque {} em {} +snap.notifications.api.unavailable=Parece que a API de {} está indisponível no momento. Não será possível buscar novos aplicativos {}. snap.action.refresh.status=Atualizando snap.action.refresh.label=Atualizar snap.install.available_channels.title=Canais disponíveis diff --git a/bauh/gems/snap/snap.py b/bauh/gems/snap/snap.py index b2c252cc..ad73dcc1 100644 --- a/bauh/gems/snap/snap.py +++ b/bauh/gems/snap/snap.py @@ -1,7 +1,8 @@ import logging import re import subprocess -from typing import List +from io import StringIO +from typing import List, Tuple from bauh.commons.system import new_root_subprocess, run_cmd, new_subprocess, SimpleProcess from bauh.gems.snap.model import SnapApplication @@ -227,3 +228,14 @@ def run(app: SnapApplication, logger: logging.Logger): logger.error("No valid command found for '{}'".format(app_name)) else: logger.error("No command found for '{}'".format(app_name)) + + +def is_api_available() -> Tuple[bool, str]: + output = StringIO() + for o in SimpleProcess(['snap', 'search']).instance.stdout: + if o: + output.write(o.decode()) + + output.seek(0) + output = output.read() + return 'error:' not in output, output