[fix][snap] not returning installed runtimes after an installation succeeds

This commit is contained in:
Vinicius Moreira
2020-06-16 16:03:40 -03:00
parent 26ae332778
commit 328f987507
2 changed files with 37 additions and 4 deletions

View File

@@ -11,7 +11,7 @@ from bauh.api.abstract.handler import ProcessWatcher, TaskManager
from bauh.api.abstract.model import SoftwarePackage, PackageHistory, PackageUpdate, PackageSuggestion, \
SuggestionPriority, CustomSoftwareAction
from bauh.api.abstract.view import SingleSelectComponent, SelectViewType, InputOption
from bauh.commons import resource
from bauh.commons import resource, internet
from bauh.commons.category import CategoriesDownloader
from bauh.commons.html import bold
from bauh.commons.system import SystemProcess, ProcessHandler, new_root_subprocess
@@ -184,6 +184,9 @@ class SnapManager(SoftwareManager):
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')
# retrieving all installed so it will be possible to know the additional installed runtimes after the operation succeeds
installed_names = snap.list_installed_names()
res, output = ProcessHandler(watcher).handle_simple(snap.install_and_stream(pkg.name, pkg.confinement, root_password))
if 'error:' in output:
@@ -208,14 +211,34 @@ class SnapManager(SoftwareManager):
if res and info_path:
pkg.has_apps_field = snap.has_apps_field(pkg.name, info_path)
return TransactionResult(success=res, installed=[pkg] if res else [], removed=[])
return self._gen_installation_response(success=res, pkg=pkg,
installed=installed_names, disk_loader=disk_loader)
else:
self.logger.error("Could not find available channels in the installation output: {}".format(output))
else:
if info_path:
pkg.has_apps_field = snap.has_apps_field(pkg.name, info_path)
return TransactionResult(success=res, installed=[pkg] if res else [], removed=[])
return self._gen_installation_response(success=res, pkg=pkg, installed=installed_names, disk_loader=disk_loader)
def _gen_installation_response(self, success: bool, pkg: SnapApplication, installed: Set[str], disk_loader: DiskCacheLoader):
if success:
new_installed = [pkg]
if installed:
try:
current_installed = self.read_installed(disk_loader=disk_loader, internet_available=internet.is_available()).installed
except:
current_installed = None
if current_installed and (not installed or len(current_installed) > len(installed) + 1):
for p in current_installed:
if p.name != pkg.name and (not installed or p.name not in installed):
new_installed.append(p)
return TransactionResult(success=success, installed=new_installed, removed=[])
else:
return TransactionResult.fail()
def is_enabled(self) -> bool:
return self.enabled

View File

@@ -3,7 +3,7 @@ import os
import re
import subprocess
from io import StringIO
from typing import List, Tuple
from typing import List, Tuple, Set
from bauh.commons.system import new_root_subprocess, run_cmd, new_subprocess, SimpleProcess
from bauh.gems.snap.model import SnapApplication
@@ -237,3 +237,13 @@ def is_api_available() -> Tuple[bool, str]:
output.seek(0)
output = output.read()
return 'error:' not in output, output
def list_installed_names() -> Set[str]:
res = run_cmd('{} list'.format(BASE_CMD), print_error=False)
if res:
lines = res.split('\n')
if not lines[0].startswith('error'):
return {l.split(' ')[0].strip() for l in lines[1:] if l}