showing a warning dialog when the application starts and **snapd** is unavailable

This commit is contained in:
Vinicius Moreira
2019-07-27 21:48:28 -03:00
parent 8f9f8d04db
commit 6b8ee68463
10 changed files with 67 additions and 14 deletions

View File

@@ -9,8 +9,9 @@ from fpakman.core.system import FpakmanProcess
class ApplicationManager(ABC):
def __init__(self, app_args):
def __init__(self, app_args, locale_keys: dict):
self.app_args = app_args
self.locale_keys = locale_keys
@abstractmethod
def search(self, word: str, disk_loader: DiskCacheLoader) -> Dict[str, List[Application]]:
@@ -84,6 +85,10 @@ class ApplicationManager(ABC):
def list_updates(self) -> List[ApplicationUpdate]:
pass
@abstractmethod
def list_warnings(self) -> List[str]:
pass
class GenericApplicationManager(ApplicationManager):
@@ -266,3 +271,18 @@ class GenericApplicationManager(ApplicationManager):
updates.extend(man.list_updates())
return updates
def list_warnings(self) -> List[str]:
if self.managers:
warnings = None
for man in self.managers:
man_warnings = man.list_warnings()
if man_warnings:
if warnings is None:
warnings = []
warnings.extend(man_warnings)
return warnings

View File

@@ -17,8 +17,8 @@ from fpakman.util.cache import Cache
class FlatpakManager(ApplicationManager):
def __init__(self, app_args: Namespace, api_cache: Cache, disk_cache: bool, http_session):
super(FlatpakManager, self).__init__(app_args=app_args)
def __init__(self, app_args: Namespace, api_cache: Cache, disk_cache: bool, http_session, locale_keys: dict):
super(FlatpakManager, self).__init__(app_args=app_args, locale_keys=locale_keys)
self.api_cache = api_cache
self.http_session = http_session
self.disk_cache = disk_cache
@@ -176,5 +176,7 @@ class FlatpakManager(ApplicationManager):
updates.append(ApplicationUpdate(app_id='{}:{}'.format(app['id'], app['branch']),
app_type='flatpak',
version=app.get('version')))
return updates
def list_warnings(self) -> List[str]:
return None

View File

@@ -17,8 +17,8 @@ from fpakman.util.cache import Cache
class SnapManager(ApplicationManager):
def __init__(self, app_args: Namespace, api_cache: Cache, disk_cache: bool, http_session):
super(SnapManager, self).__init__(app_args=app_args)
def __init__(self, app_args: Namespace, api_cache: Cache, disk_cache: bool, http_session, locale_keys: dict):
super(SnapManager, self).__init__(app_args=app_args, locale_keys=locale_keys)
self.api_cache = api_cache
self.http_session = http_session
self.disk_cache = disk_cache
@@ -133,3 +133,7 @@ class SnapManager(ApplicationManager):
def list_updates(self) -> List[ApplicationUpdate]:
return []
def list_warnings(self) -> List[str]:
if snap.get_snapd_version() == 'unavailable':
return [self.locale_keys['snap.notification.snapd_unavailable']]

View File

@@ -9,7 +9,7 @@ BASE_CMD = 'snap'
def is_installed():
version = get_snapd_version()
return False if version is None else True
return False if version is None or version == 'unavailable' else True
def get_version():
@@ -27,7 +27,7 @@ def get_snapd_version():
if lines and len(lines) >= 2:
version = lines[1].split(' ')[-1].strip()
return version if version and version.lower() != 'unavailable' else None
return version.lower() if version else None
else:
return None