[flatpak] fix -> some environment variables are not available during the common operations

This commit is contained in:
Vinicius Moreira
2020-08-20 12:37:21 -03:00
parent 4544a46421
commit b99462d0e5
4 changed files with 35 additions and 32 deletions

View File

@@ -75,6 +75,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
<p align="center">
<img src="https://raw.githubusercontent.com/vinifmor/bauh-files/master/pictures/releases/0.9.7/flatpak_refs.png">
</p>
- some environment variables are not available during the common operations (install, upgrade, downgrade, uninstall)
- UI
- crashing when nothing can be upgraded
- random C++ wrapper errors with some forms due to missing references

View File

@@ -66,7 +66,8 @@ class SimpleProcess:
def __init__(self, cmd: List[str], cwd: str = '.', expected_code: int = 0,
global_interpreter: bool = USE_GLOBAL_INTERPRETER, lang: str = DEFAULT_LANG, root_password: str = None,
extra_paths: Set[str] = None, error_phrases: Set[str] = None, wrong_error_phrases: Set[str] = None,
shell: bool = False):
shell: bool = False,
success_phrases: Set[str] = None):
pwdin, final_cmd = None, []
self.shell = shell
@@ -80,6 +81,7 @@ class SimpleProcess:
self.expected_code = expected_code
self.error_phrases = error_phrases
self.wrong_error_phrases = wrong_error_phrases
self.success_phrases = success_phrases
def _new(self, cmd: List[str], cwd: str, global_interpreter: bool, lang: str, stdin = None, extra_paths: Set[str] = None) -> subprocess.Popen:
@@ -186,6 +188,12 @@ class ProcessHandler:
success = proc.instance.returncode == proc.expected_code
string_output = output.read()
if proc.success_phrases:
for phrase in proc.success_phrases:
if phrase in string_output:
success = True
break
if not success and proc.wrong_error_phrases:
for phrase in proc.wrong_error_phrases:
if phrase in string_output:

View File

@@ -18,7 +18,7 @@ from bauh.api.abstract.view import MessageType, FormComponent, SingleSelectCompo
from bauh.commons import user, internet
from bauh.commons.config import save_config
from bauh.commons.html import strip_html, bold
from bauh.commons.system import SystemProcess, ProcessHandler
from bauh.commons.system import ProcessHandler
from bauh.gems.flatpak import flatpak, SUGGESTIONS_FILE, CONFIG_FILE, UPDATES_IGNORED_FILE, CONFIG_DIR, EXPORTS_PATH
from bauh.gems.flatpak.config import read_config
from bauh.gems.flatpak.constants import FLATHUB_API_URL
@@ -186,9 +186,10 @@ class FlatpakManager(SoftwareManager):
commit = history.history[history.pkg_status_idx + 1]['commit']
watcher.change_substatus(self.i18n['flatpak.downgrade.reverting'])
watcher.change_progress(50)
success = ProcessHandler(watcher).handle(SystemProcess(subproc=flatpak.downgrade(pkg.ref, commit, pkg.installation, root_password),
success_phrases=['Changes complete.', 'Updates complete.'],
wrong_error_phrase='Warning'))
success, _ = ProcessHandler(watcher).handle_simple(flatpak.downgrade(pkg.ref,
commit,
pkg.installation,
root_password))
watcher.change_progress(100)
return success
@@ -212,10 +213,10 @@ class FlatpakManager(SoftwareManager):
ref = req.pkg.base_ref
try:
res = ProcessHandler(watcher).handle(SystemProcess(subproc=flatpak.update(app_ref=ref,
installation=req.pkg.installation,
related=related,
deps=deps)))
res, _ = ProcessHandler(watcher).handle_simple(flatpak.update(app_ref=ref,
installation=req.pkg.installation,
related=related,
deps=deps))
watcher.change_substatus('')
if not res:
@@ -235,7 +236,7 @@ class FlatpakManager(SoftwareManager):
if not self._make_exports_dir(watcher):
return TransactionResult.fail()
uninstalled = ProcessHandler(watcher).handle(SystemProcess(subproc=flatpak.uninstall(pkg.ref, pkg.installation)))
uninstalled, _ = ProcessHandler(watcher).handle_simple(flatpak.uninstall(pkg.ref, pkg.installation))
if uninstalled:
if self.suggestions_cache:

View File

@@ -5,7 +5,7 @@ from datetime import datetime
from typing import List, Dict, Set, Iterable, Optional
from bauh.api.exception import NoInternetException
from bauh.commons.system import new_subprocess, run_cmd, new_root_subprocess, SimpleProcess, ProcessHandler
from bauh.commons.system import new_subprocess, run_cmd, SimpleProcess, ProcessHandler
from bauh.commons.util import size_to_byte
from bauh.gems.flatpak import EXPORTS_PATH
@@ -153,12 +153,7 @@ def list_installed(version: str) -> List[dict]:
return apps
def update(app_ref: str, installation: str, related: bool = False, deps: bool = False):
"""
Updates the app reference
:param app_ref:
:return:
"""
def update(app_ref: str, installation: str, related: bool = False, deps: bool = False) -> SimpleProcess:
cmd = ['flatpak', 'update', '-y', app_ref, '--{}'.format(installation)]
if not related:
@@ -167,17 +162,13 @@ def update(app_ref: str, installation: str, related: bool = False, deps: bool =
if not deps:
cmd.append('--no-deps')
return new_subprocess(cmd=cmd, extra_paths={EXPORTS_PATH})
return SimpleProcess(cmd=cmd, extra_paths={EXPORTS_PATH}, shell=True)
def uninstall(app_ref: str, installation: str):
"""
Removes the app by its reference
:param app_ref:
:return:
"""
return new_subprocess(cmd=['flatpak', 'uninstall', app_ref, '-y', '--{}'.format(installation)],
extra_paths={EXPORTS_PATH})
def uninstall(app_ref: str, installation: str) -> SimpleProcess:
return SimpleProcess(cmd=['flatpak', 'uninstall', app_ref, '-y', '--{}'.format(installation)],
extra_paths={EXPORTS_PATH},
shell=True)
def list_updates_as_str(version: str) -> Dict[str, set]:
@@ -231,13 +222,14 @@ def read_updates(version: str, installation: str) -> Dict[str, set]:
return res
def downgrade(app_ref: str, commit: str, installation: str, root_password: str) -> subprocess.Popen:
def downgrade(app_ref: str, commit: str, installation: str, root_password: str) -> SimpleProcess:
cmd = ['flatpak', 'update', '--no-related', '--no-deps', '--commit={}'.format(commit), app_ref, '-y', '--{}'.format(installation)]
if installation == 'system':
return new_root_subprocess(cmd=cmd, root_password=root_password, extra_paths={EXPORTS_PATH})
else:
return new_subprocess(cmd=cmd, extra_paths={EXPORTS_PATH})
return SimpleProcess(cmd=cmd,
root_password=root_password if installation=='system' else None,
extra_paths={EXPORTS_PATH},
success_phrases={'Changes complete.', 'Updates complete.'},
wrong_error_phrases={'Warning'})
def get_app_commits(app_ref: str, origin: str, installation: str, handler: ProcessHandler) -> List[str]:
@@ -360,7 +352,8 @@ def search(version: str, word: str, installation: str, app_id: bool = False) ->
def install(app_id: str, origin: str, installation: str) -> SimpleProcess:
return SimpleProcess(cmd=['flatpak', 'install', origin, app_id, '-y', '--{}'.format(installation)],
extra_paths={EXPORTS_PATH},
wrong_error_phrases={'Warning'})
wrong_error_phrases={'Warning'},
shell=True)
def set_default_remotes(installation: str, root_password: str = None) -> SimpleProcess: