mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 05:54:15 +02:00
[fix][snap] not able to launch applications on some distros
This commit is contained in:
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
|
||||
## [0.8.4] - 2020-02
|
||||
### Fixes
|
||||
- Snap
|
||||
- not able to launch applications on some distros ( e.g: OpenSuse )
|
||||
|
||||
## [0.8.3] - 2020-02-13
|
||||
### Improvements
|
||||
- New update lifecycle:
|
||||
|
||||
@@ -36,6 +36,13 @@ class SnapManager(SoftwareManager):
|
||||
self.categories_downloader = CategoriesDownloader('snap', self.http_client, self.logger, self, context.disk_cache,
|
||||
URL_CATEGORIES_FILE, SNAP_CACHE_PATH, CATEGORIES_FILE_PATH)
|
||||
self.suggestions_cache = context.cache_factory.new()
|
||||
self.info_path = None
|
||||
|
||||
def get_info_path(self) -> str:
|
||||
if self.info_path is None:
|
||||
self.info_path = snap.get_app_info_path()
|
||||
|
||||
return self.info_path
|
||||
|
||||
def map_json(self, app_json: dict, installed: bool, disk_loader: DiskCacheLoader, internet: bool = True) -> SnapApplication:
|
||||
app = SnapApplication(publisher=app_json.get('publisher'),
|
||||
@@ -112,9 +119,11 @@ class SnapManager(SoftwareManager):
|
||||
return SearchResult([], [], 0)
|
||||
|
||||
def read_installed(self, disk_loader: DiskCacheLoader, limit: int = -1, only_apps: bool = False, pkg_types: Set[Type[SoftwarePackage]] = None, internet_available: bool = None) -> SearchResult:
|
||||
if snap.is_snapd_running():
|
||||
info_path = self.get_info_path()
|
||||
|
||||
if snap.is_snapd_running() and info_path:
|
||||
self.categories_downloader.join()
|
||||
installed = [self.map_json(app_json, installed=True, disk_loader=disk_loader, internet=internet_available) for app_json in snap.read_installed(self.ubuntu_distro)]
|
||||
installed = [self.map_json(app_json, installed=True, disk_loader=disk_loader, internet=internet_available) for app_json in snap.read_installed(info_path)]
|
||||
return SearchResult(installed, None, len(installed))
|
||||
else:
|
||||
return SearchResult([], None, 0)
|
||||
@@ -159,6 +168,11 @@ class SnapManager(SoftwareManager):
|
||||
raise Exception("'get_history' is not supported by {}".format(pkg.__class__.__name__))
|
||||
|
||||
def install(self, pkg: SnapApplication, root_password: str, watcher: ProcessWatcher) -> bool:
|
||||
info_path = self.get_info_path()
|
||||
|
||||
if not info_path:
|
||||
self.logger.warning('Information directory was not found. It will not be possible to determine if the installed application can be launched')
|
||||
|
||||
res, output = ProcessHandler(watcher).handle_simple(snap.install_and_stream(pkg.name, pkg.confinement, root_password))
|
||||
|
||||
if 'error:' in output:
|
||||
@@ -180,14 +194,15 @@ class SnapManager(SoftwareManager):
|
||||
self.logger.info("Installing '{}' with the custom command '{}'".format(pkg.name, channel_select.value))
|
||||
res = ProcessHandler(watcher).handle(SystemProcess(new_root_subprocess(channel_select.value.value.split(' '), root_password=root_password)))
|
||||
|
||||
if res:
|
||||
pkg.has_apps_field = snap.has_apps_field(pkg.name, self.ubuntu_distro)
|
||||
if res and info_path:
|
||||
pkg.has_apps_field = snap.has_apps_field(pkg.name, info_path)
|
||||
|
||||
return res
|
||||
else:
|
||||
self.logger.error("Could not find available channels in the installation output: {}".format(output))
|
||||
else:
|
||||
pkg.has_apps_field = snap.has_apps_field(pkg.name, self.ubuntu_distro)
|
||||
if info_path:
|
||||
pkg.has_apps_field = snap.has_apps_field(pkg.name, info_path)
|
||||
|
||||
return res
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
from io import StringIO
|
||||
@@ -85,7 +86,7 @@ def get_info(app_name: str, attrs: tuple = None):
|
||||
return data
|
||||
|
||||
|
||||
def read_installed(ubuntu_distro: bool) -> List[dict]:
|
||||
def read_installed(info_path: str) -> List[dict]:
|
||||
res = run_cmd('{} list'.format(BASE_CMD), print_error=False)
|
||||
|
||||
apps = []
|
||||
@@ -98,8 +99,6 @@ def read_installed(ubuntu_distro: bool) -> List[dict]:
|
||||
if idx > 0 and app_str:
|
||||
apps.append(app_str_to_json(app_str))
|
||||
|
||||
info_path = _get_app_info_path(ubuntu_distro)
|
||||
|
||||
info_out = new_subprocess(['cat', *[info_path.format(a['name']) for a in apps]]).stdout
|
||||
|
||||
idx = -1
|
||||
@@ -116,16 +115,16 @@ def read_installed(ubuntu_distro: bool) -> List[dict]:
|
||||
return apps
|
||||
|
||||
|
||||
def _get_app_info_path(ubuntu_distro: bool) -> str:
|
||||
if ubuntu_distro:
|
||||
def get_app_info_path() -> str:
|
||||
if os.path.exists('/snap'):
|
||||
return '/snap/{}/current/meta/snap.yaml'
|
||||
else:
|
||||
elif os.path.exists('/var/lib/snapd/snap'):
|
||||
return '/var/lib/snapd/snap/{}/current/meta/snap.yaml'
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def has_apps_field(name: str, ubuntu_distro: bool) -> bool:
|
||||
info_path = _get_app_info_path(ubuntu_distro)
|
||||
|
||||
def has_apps_field(name: str, info_path: str) -> bool:
|
||||
info_out = new_subprocess(['cat', info_path.format(name)]).stdout
|
||||
|
||||
res = False
|
||||
|
||||
Reference in New Issue
Block a user