From 4931cf590ae83bbd9d89f6da87938c50b57f6e96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Moreira?= Date: Wed, 22 Jan 2020 17:34:24 -0300 Subject: [PATCH] [fix][flatpak] displaying a wrong popup message when an error happens during commits reading within the downgrade process --- CHANGELOG.md | 2 ++ bauh/gems/flatpak/controller.py | 12 ++++++++---- bauh/gems/flatpak/flatpak.py | 26 ++++++++++---------------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ad7d1d9..741e80d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - not pre-downloading some source files ( e.g: from **anbox-image** ) - not able to install packages based on other packages ( package name != package base ) - downgrade: pre-downloading sources from the latest version instead of the older +- Flatpak: + - displaying "No Internet connection" when an error happens during commits reading within the downgrade process - UI: - **About** window icons scaling diff --git a/bauh/gems/flatpak/controller.py b/bauh/gems/flatpak/controller.py index c88d7023..cf53dc30 100644 --- a/bauh/gems/flatpak/controller.py +++ b/bauh/gems/flatpak/controller.py @@ -151,11 +151,15 @@ class FlatpakManager(SoftwareManager): return SearchResult(models, None, len(models)) def downgrade(self, pkg: FlatpakApplication, root_password: str, watcher: ProcessWatcher) -> bool: + handler = ProcessHandler(watcher) pkg.commit = flatpak.get_commit(pkg.id, pkg.branch, pkg.installation) watcher.change_progress(10) watcher.change_substatus(self.i18n['flatpak.downgrade.commits']) - commits = flatpak.get_app_commits(pkg.ref, pkg.origin, pkg.installation) + commits = flatpak.get_app_commits(pkg.ref, pkg.origin, pkg.installation, handler) + + if commits is None: + return False commit_idx = commits.index(pkg.commit) @@ -167,9 +171,9 @@ class FlatpakManager(SoftwareManager): commit = commits[commit_idx + 1] 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 = handler.handle(SystemProcess(subproc=flatpak.downgrade(pkg.ref, commit, pkg.installation, root_password), + success_phrases=['Changes complete.', 'Updates complete.'], + wrong_error_phrase='Warning')) watcher.change_progress(100) return success diff --git a/bauh/gems/flatpak/flatpak.py b/bauh/gems/flatpak/flatpak.py index 471898de..5158a620 100755 --- a/bauh/gems/flatpak/flatpak.py +++ b/bauh/gems/flatpak/flatpak.py @@ -5,7 +5,7 @@ from datetime import datetime from typing import List, Dict, Set from bauh.api.exception import NoInternetException -from bauh.commons.system import new_subprocess, run_cmd, new_root_subprocess, SimpleProcess +from bauh.commons.system import new_subprocess, run_cmd, new_root_subprocess, SimpleProcess, ProcessHandler BASE_CMD = 'flatpak' RE_SEVERAL_SPACES = re.compile(r'\s+') @@ -150,15 +150,6 @@ def update(app_ref: str, installation: str): return new_subprocess([BASE_CMD, 'update', '--no-related', '--no-deps', '-y', app_ref, '--{}'.format(installation)]) -def register_flathub(installation: str) -> SimpleProcess: - return SimpleProcess([BASE_CMD, - 'remote-add', - '--if-not-exists', - 'flathub', - 'https://flathub.org/repo/flathub.flatpakrepo', - '--{}'.format(installation)]) - - def uninstall(app_ref: str, installation: str): """ Removes the app by its reference @@ -228,12 +219,15 @@ def downgrade(app_ref: str, commit: str, installation: str, root_password: str) return new_subprocess(cmd) -def get_app_commits(app_ref: str, origin: str, installation: str) -> List[str]: - log = run_cmd('{} remote-info --log {} {} --{}'.format(BASE_CMD, origin, app_ref, installation)) - - if log: - return re.findall(r'Commit+:\s(.+)', log) - else: +def get_app_commits(app_ref: str, origin: str, installation: str, handler: ProcessHandler) -> List[str]: + try: + p = SimpleProcess(['flatpak', 'remote-info', '--log', origin, app_ref, '--{}'.format(installation)]) + success, output = handler.handle_simple(p) + if output.startswith('error:'): + return + else: + return re.findall(r'Commit+:\s(.+)', output) + except: raise NoInternetException()