mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-09 18:54:16 +02:00
[flatpak] fix -> some environment variables are not available during the common operations
This commit is contained in:
@@ -75,6 +75,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://raw.githubusercontent.com/vinifmor/bauh-files/master/pictures/releases/0.9.7/flatpak_refs.png">
|
<img src="https://raw.githubusercontent.com/vinifmor/bauh-files/master/pictures/releases/0.9.7/flatpak_refs.png">
|
||||||
</p>
|
</p>
|
||||||
|
- some environment variables are not available during the common operations (install, upgrade, downgrade, uninstall)
|
||||||
- UI
|
- UI
|
||||||
- crashing when nothing can be upgraded
|
- crashing when nothing can be upgraded
|
||||||
- random C++ wrapper errors with some forms due to missing references
|
- random C++ wrapper errors with some forms due to missing references
|
||||||
|
|||||||
@@ -66,7 +66,8 @@ class SimpleProcess:
|
|||||||
def __init__(self, cmd: List[str], cwd: str = '.', expected_code: int = 0,
|
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,
|
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,
|
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, []
|
pwdin, final_cmd = None, []
|
||||||
|
|
||||||
self.shell = shell
|
self.shell = shell
|
||||||
@@ -80,6 +81,7 @@ class SimpleProcess:
|
|||||||
self.expected_code = expected_code
|
self.expected_code = expected_code
|
||||||
self.error_phrases = error_phrases
|
self.error_phrases = error_phrases
|
||||||
self.wrong_error_phrases = wrong_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:
|
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
|
success = proc.instance.returncode == proc.expected_code
|
||||||
string_output = output.read()
|
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:
|
if not success and proc.wrong_error_phrases:
|
||||||
for phrase in proc.wrong_error_phrases:
|
for phrase in proc.wrong_error_phrases:
|
||||||
if phrase in string_output:
|
if phrase in string_output:
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ from bauh.api.abstract.view import MessageType, FormComponent, SingleSelectCompo
|
|||||||
from bauh.commons import user, internet
|
from bauh.commons import user, internet
|
||||||
from bauh.commons.config import save_config
|
from bauh.commons.config import save_config
|
||||||
from bauh.commons.html import strip_html, bold
|
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 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.config import read_config
|
||||||
from bauh.gems.flatpak.constants import FLATHUB_API_URL
|
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']
|
commit = history.history[history.pkg_status_idx + 1]['commit']
|
||||||
watcher.change_substatus(self.i18n['flatpak.downgrade.reverting'])
|
watcher.change_substatus(self.i18n['flatpak.downgrade.reverting'])
|
||||||
watcher.change_progress(50)
|
watcher.change_progress(50)
|
||||||
success = ProcessHandler(watcher).handle(SystemProcess(subproc=flatpak.downgrade(pkg.ref, commit, pkg.installation, root_password),
|
success, _ = ProcessHandler(watcher).handle_simple(flatpak.downgrade(pkg.ref,
|
||||||
success_phrases=['Changes complete.', 'Updates complete.'],
|
commit,
|
||||||
wrong_error_phrase='Warning'))
|
pkg.installation,
|
||||||
|
root_password))
|
||||||
watcher.change_progress(100)
|
watcher.change_progress(100)
|
||||||
return success
|
return success
|
||||||
|
|
||||||
@@ -212,10 +213,10 @@ class FlatpakManager(SoftwareManager):
|
|||||||
ref = req.pkg.base_ref
|
ref = req.pkg.base_ref
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = ProcessHandler(watcher).handle(SystemProcess(subproc=flatpak.update(app_ref=ref,
|
res, _ = ProcessHandler(watcher).handle_simple(flatpak.update(app_ref=ref,
|
||||||
installation=req.pkg.installation,
|
installation=req.pkg.installation,
|
||||||
related=related,
|
related=related,
|
||||||
deps=deps)))
|
deps=deps))
|
||||||
|
|
||||||
watcher.change_substatus('')
|
watcher.change_substatus('')
|
||||||
if not res:
|
if not res:
|
||||||
@@ -235,7 +236,7 @@ class FlatpakManager(SoftwareManager):
|
|||||||
if not self._make_exports_dir(watcher):
|
if not self._make_exports_dir(watcher):
|
||||||
return TransactionResult.fail()
|
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 uninstalled:
|
||||||
if self.suggestions_cache:
|
if self.suggestions_cache:
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from datetime import datetime
|
|||||||
from typing import List, Dict, Set, Iterable, Optional
|
from typing import List, Dict, Set, Iterable, Optional
|
||||||
|
|
||||||
from bauh.api.exception import NoInternetException
|
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.commons.util import size_to_byte
|
||||||
from bauh.gems.flatpak import EXPORTS_PATH
|
from bauh.gems.flatpak import EXPORTS_PATH
|
||||||
|
|
||||||
@@ -153,12 +153,7 @@ def list_installed(version: str) -> List[dict]:
|
|||||||
return apps
|
return apps
|
||||||
|
|
||||||
|
|
||||||
def update(app_ref: str, installation: str, related: bool = False, deps: bool = False):
|
def update(app_ref: str, installation: str, related: bool = False, deps: bool = False) -> SimpleProcess:
|
||||||
"""
|
|
||||||
Updates the app reference
|
|
||||||
:param app_ref:
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
cmd = ['flatpak', 'update', '-y', app_ref, '--{}'.format(installation)]
|
cmd = ['flatpak', 'update', '-y', app_ref, '--{}'.format(installation)]
|
||||||
|
|
||||||
if not related:
|
if not related:
|
||||||
@@ -167,17 +162,13 @@ def update(app_ref: str, installation: str, related: bool = False, deps: bool =
|
|||||||
if not deps:
|
if not deps:
|
||||||
cmd.append('--no-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):
|
def uninstall(app_ref: str, installation: str) -> SimpleProcess:
|
||||||
"""
|
return SimpleProcess(cmd=['flatpak', 'uninstall', app_ref, '-y', '--{}'.format(installation)],
|
||||||
Removes the app by its reference
|
extra_paths={EXPORTS_PATH},
|
||||||
:param app_ref:
|
shell=True)
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
return new_subprocess(cmd=['flatpak', 'uninstall', app_ref, '-y', '--{}'.format(installation)],
|
|
||||||
extra_paths={EXPORTS_PATH})
|
|
||||||
|
|
||||||
|
|
||||||
def list_updates_as_str(version: str) -> Dict[str, set]:
|
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
|
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)]
|
cmd = ['flatpak', 'update', '--no-related', '--no-deps', '--commit={}'.format(commit), app_ref, '-y', '--{}'.format(installation)]
|
||||||
|
|
||||||
if installation == 'system':
|
return SimpleProcess(cmd=cmd,
|
||||||
return new_root_subprocess(cmd=cmd, root_password=root_password, extra_paths={EXPORTS_PATH})
|
root_password=root_password if installation=='system' else None,
|
||||||
else:
|
extra_paths={EXPORTS_PATH},
|
||||||
return new_subprocess(cmd=cmd, 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]:
|
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:
|
def install(app_id: str, origin: str, installation: str) -> SimpleProcess:
|
||||||
return SimpleProcess(cmd=['flatpak', 'install', origin, app_id, '-y', '--{}'.format(installation)],
|
return SimpleProcess(cmd=['flatpak', 'install', origin, app_id, '-y', '--{}'.format(installation)],
|
||||||
extra_paths={EXPORTS_PATH},
|
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:
|
def set_default_remotes(installation: str, root_password: str = None) -> SimpleProcess:
|
||||||
|
|||||||
Reference in New Issue
Block a user