mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-08 19:04: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/).
|
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
|
## [0.8.3] - 2020-02-13
|
||||||
### Improvements
|
### Improvements
|
||||||
- New update lifecycle:
|
- New update lifecycle:
|
||||||
|
|||||||
@@ -36,6 +36,13 @@ class SnapManager(SoftwareManager):
|
|||||||
self.categories_downloader = CategoriesDownloader('snap', self.http_client, self.logger, self, context.disk_cache,
|
self.categories_downloader = CategoriesDownloader('snap', self.http_client, self.logger, self, context.disk_cache,
|
||||||
URL_CATEGORIES_FILE, SNAP_CACHE_PATH, CATEGORIES_FILE_PATH)
|
URL_CATEGORIES_FILE, SNAP_CACHE_PATH, CATEGORIES_FILE_PATH)
|
||||||
self.suggestions_cache = context.cache_factory.new()
|
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:
|
def map_json(self, app_json: dict, installed: bool, disk_loader: DiskCacheLoader, internet: bool = True) -> SnapApplication:
|
||||||
app = SnapApplication(publisher=app_json.get('publisher'),
|
app = SnapApplication(publisher=app_json.get('publisher'),
|
||||||
@@ -112,9 +119,11 @@ class SnapManager(SoftwareManager):
|
|||||||
return SearchResult([], [], 0)
|
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:
|
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()
|
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))
|
return SearchResult(installed, None, len(installed))
|
||||||
else:
|
else:
|
||||||
return SearchResult([], None, 0)
|
return SearchResult([], None, 0)
|
||||||
@@ -159,6 +168,11 @@ class SnapManager(SoftwareManager):
|
|||||||
raise Exception("'get_history' is not supported by {}".format(pkg.__class__.__name__))
|
raise Exception("'get_history' is not supported by {}".format(pkg.__class__.__name__))
|
||||||
|
|
||||||
def install(self, pkg: SnapApplication, root_password: str, watcher: ProcessWatcher) -> bool:
|
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))
|
res, output = ProcessHandler(watcher).handle_simple(snap.install_and_stream(pkg.name, pkg.confinement, root_password))
|
||||||
|
|
||||||
if 'error:' in output:
|
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))
|
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)))
|
res = ProcessHandler(watcher).handle(SystemProcess(new_root_subprocess(channel_select.value.value.split(' '), root_password=root_password)))
|
||||||
|
|
||||||
if res:
|
if res and info_path:
|
||||||
pkg.has_apps_field = snap.has_apps_field(pkg.name, self.ubuntu_distro)
|
pkg.has_apps_field = snap.has_apps_field(pkg.name, info_path)
|
||||||
|
|
||||||
return res
|
return res
|
||||||
else:
|
else:
|
||||||
self.logger.error("Could not find available channels in the installation output: {}".format(output))
|
self.logger.error("Could not find available channels in the installation output: {}".format(output))
|
||||||
else:
|
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
|
return res
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
@@ -85,7 +86,7 @@ def get_info(app_name: str, attrs: tuple = None):
|
|||||||
return data
|
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)
|
res = run_cmd('{} list'.format(BASE_CMD), print_error=False)
|
||||||
|
|
||||||
apps = []
|
apps = []
|
||||||
@@ -98,8 +99,6 @@ def read_installed(ubuntu_distro: bool) -> List[dict]:
|
|||||||
if idx > 0 and app_str:
|
if idx > 0 and app_str:
|
||||||
apps.append(app_str_to_json(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
|
info_out = new_subprocess(['cat', *[info_path.format(a['name']) for a in apps]]).stdout
|
||||||
|
|
||||||
idx = -1
|
idx = -1
|
||||||
@@ -116,16 +115,16 @@ def read_installed(ubuntu_distro: bool) -> List[dict]:
|
|||||||
return apps
|
return apps
|
||||||
|
|
||||||
|
|
||||||
def _get_app_info_path(ubuntu_distro: bool) -> str:
|
def get_app_info_path() -> str:
|
||||||
if ubuntu_distro:
|
if os.path.exists('/snap'):
|
||||||
return '/snap/{}/current/meta/snap.yaml'
|
return '/snap/{}/current/meta/snap.yaml'
|
||||||
else:
|
elif os.path.exists('/var/lib/snapd/snap'):
|
||||||
return '/var/lib/snapd/snap/{}/current/meta/snap.yaml'
|
return '/var/lib/snapd/snap/{}/current/meta/snap.yaml'
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def has_apps_field(name: str, ubuntu_distro: bool) -> bool:
|
def has_apps_field(name: str, info_path: str) -> bool:
|
||||||
info_path = _get_app_info_path(ubuntu_distro)
|
|
||||||
|
|
||||||
info_out = new_subprocess(['cat', info_path.format(name)]).stdout
|
info_out = new_subprocess(['cat', info_path.format(name)]).stdout
|
||||||
|
|
||||||
res = False
|
res = False
|
||||||
|
|||||||
Reference in New Issue
Block a user