From edc3785e42198a92a1cf3ecf9d5fd029aa77e0a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Moreira?= Date: Thu, 9 Jan 2020 19:20:57 -0300 Subject: [PATCH] [flatpak] initial partial update support | [ui] trying to fix resize issues --- bauh/gems/flatpak/controller.py | 23 +++++++++++++++++----- bauh/gems/flatpak/flatpak.py | 23 +++++++++++++++------- bauh/gems/flatpak/model.py | 24 ++++++++++++++++++++--- bauh/view/qt/window.py | 34 +++++++++++++++++---------------- 4 files changed, 73 insertions(+), 31 deletions(-) diff --git a/bauh/gems/flatpak/controller.py b/bauh/gems/flatpak/controller.py index f4a367aa..e435b591 100644 --- a/bauh/gems/flatpak/controller.py +++ b/bauh/gems/flatpak/controller.py @@ -104,16 +104,29 @@ class FlatpakManager(SoftwareManager): if thread_updates: thread_updates.join() + update_map = updates[0] for app_json in installed: model = self._map_to_model(app_json=app_json, installed=True, disk_loader=disk_loader, internet=internet_available) - if version >= '1.5.0': - model.update = '{}/{}'.format(app_json['id'], app_json['branch']) in updates[0] if updates else None - else: - model.update = app_json['ref'] in updates[0] if updates else None - + model.update = None models.append(model) + if update_map['full'] or update_map['partial']: + if version >= '1.5.0': + update_id = '{}/{}'.format(app_json['id'], app_json['branch']) + + if update_map['full'] and update_id in update_map['full']: + model.update = True + + if update_map['partial']: + for partial in update_map['partial']: + if app_json['id'] in partial and '/' + app_json['branch'] in partial: + partial_model = model.gen_partial(partial.split('/')[0]) + partial_model.update = True + models.append(partial_model) + else: + model.update = app_json['ref'] in updates[0] if updates else None + return SearchResult(models, None, len(models)) def downgrade(self, pkg: FlatpakApplication, root_password: str, watcher: ProcessWatcher) -> bool: diff --git a/bauh/gems/flatpak/flatpak.py b/bauh/gems/flatpak/flatpak.py index ba9d40a4..99bfb256 100755 --- a/bauh/gems/flatpak/flatpak.py +++ b/bauh/gems/flatpak/flatpak.py @@ -2,7 +2,7 @@ import re import subprocess from datetime import datetime from io import StringIO -from typing import List +from typing import List, Dict from bauh.api.exception import NoInternetException from bauh.commons.system import new_subprocess, run_cmd, new_root_subprocess @@ -157,22 +157,31 @@ def uninstall(app_ref: str): return new_subprocess([BASE_CMD, 'uninstall', app_ref, '-y']) -def list_updates_as_str(version: str): +def list_updates_as_str(version: str) -> Dict[str, set]: if version < '1.2': + # TODO return run_cmd('{} update --no-related'.format(BASE_CMD), ignore_return_code=True) else: updates = new_subprocess([BASE_CMD, 'update']).stdout - out = StringIO() + reg = r'[0-9]+\.\s+.+' if version >= '1.5.0' else r'[0-9]+\.\s+(\w+|\.)+\s+\w+\s+(\w|\.)+' - reg = r'[0-9]+\.\s+(\w+|\.)+\s+(\w|\.)+' if version >= '1.5.0' else r'[0-9]+\.\s+(\w+|\.)+\s+\w+\s+(\w|\.)+' + res = {'partial': set(), 'full': set()} for o in new_subprocess(['grep', '-E', reg, '-o', '--color=never'], stdin=updates).stdout: if o: - out.write('/'.join(o.decode().strip().split('\t')[2:]) + '\n') + line_split = o.decode().strip().split('\t') + update_id = line_split[2] + '/' + line_split[3] - out.seek(0) - return out.read() + if len(line_split) == 7: + if line_split[4] != 'i': + if '(partial)' in line_split[6]: + res['partial'].add(update_id) + else: + res['full'].add(update_id) + else: + res['full'].add(update_id) + return res def downgrade(app_ref: str, commit: str, root_password: str) -> subprocess.Popen: diff --git a/bauh/gems/flatpak/model.py b/bauh/gems/flatpak/model.py index 4a95c7ff..0d8d900a 100644 --- a/bauh/gems/flatpak/model.py +++ b/bauh/gems/flatpak/model.py @@ -1,3 +1,6 @@ +import copy +from typing import Set + from bauh.api.abstract.model import SoftwarePackage from bauh.commons import resource @@ -16,6 +19,7 @@ class FlatpakApplication(SoftwarePackage): self.origin = origin self.runtime = runtime self.commit = commit + self.partial = False if runtime: self.categories = ['runtime'] @@ -24,13 +28,13 @@ class FlatpakApplication(SoftwarePackage): return self.description is None and self.icon_url def has_history(self): - return self.installed and self.ref + return not self.partial and self.installed and self.ref def has_info(self): return bool(self.id) def can_be_downgraded(self): - return self.installed and self.ref + return not self.partial and self.installed and self.ref def get_type(self): return 'flatpak' @@ -63,7 +67,21 @@ class FlatpakApplication(SoftwarePackage): setattr(self, attr, data[attr]) def can_be_run(self) -> bool: - return self.installed and not self.runtime + return self.installed and not self.runtime and not self.partial def get_publisher(self): return self.origin + + def can_be_uninstalled(self): + return self.installed and not self.partial + + def gen_partial(self, partial_id: str) -> "FlatpakApplication": + partial = copy.deepcopy(self) + partial.id = partial_id + + if self.ref: + ref_split = self.ref.split('/') + partial.ref = '/'.join((ref_split[0], partial_id, *ref_split[2:])) + + partial.partial = True + return partial diff --git a/bauh/view/qt/window.py b/bauh/view/qt/window.py index c0860394..f453ac6b 100755 --- a/bauh/view/qt/window.py +++ b/bauh/view/qt/window.py @@ -6,9 +6,10 @@ from pathlib import Path from typing import List, Type, Set from PyQt5.QtCore import QEvent, Qt, QSize, pyqtSignal -from PyQt5.QtGui import QIcon, QWindowStateChangeEvent, QPixmap, QCursor +from PyQt5.QtGui import QIcon, QWindowStateChangeEvent, QCursor from PyQt5.QtWidgets import QWidget, QVBoxLayout, QCheckBox, QHeaderView, QToolBar, \ - QLabel, QPlainTextEdit, QLineEdit, QProgressBar, QPushButton, QComboBox, QMenu, QAction, QApplication, QListView + QLabel, QPlainTextEdit, QLineEdit, QProgressBar, QPushButton, QComboBox, QMenu, QAction, QApplication, QListView, \ + QSizePolicy from bauh.api.abstract.cache import MemoryCache from bauh.api.abstract.context import ApplicationContext @@ -33,7 +34,7 @@ from bauh.view.qt.thread import UpdateSelectedApps, RefreshApps, UninstallApp, D GetAppHistory, SearchPackages, InstallPackage, AnimateProgress, VerifyModels, FindSuggestions, ListWarnings, \ AsyncAction, LaunchApp, ApplyFilters, CustomAction, GetScreenshots from bauh.view.qt.view_model import PackageView -from bauh.view.qt.view_utils import load_icon, load_resource_icon +from bauh.view.qt.view_utils import load_icon from bauh.view.util import util, resource from bauh.view.util.translation import I18n @@ -829,19 +830,20 @@ class ManageWindow(QWidget): self.ref_combo_categories.setVisible(False) def resize_and_center(self, accept_lower_width: bool = True): - if self.pkgs: - new_width = reduce(operator.add, [self.table_apps.columnWidth(i) for i in range(self.table_apps.columnCount())]) - - if self.ref_bt_upgrade.isVisible() or self.ref_bt_settings.isVisible(): - new_width *= 1.07 - else: - new_width = self.toolbar_top.width() - - if accept_lower_width or new_width > self.width(): - self.resize(new_width, self.height()) - - if self.ref_bt_upgrade.isVisible() and self.bt_upgrade.visibleRegion().isEmpty(): - self.adjustSize() + self.setMinimumWidth(self.layout.sizeHint().width()) + # if self.pkgs: + # new_width = reduce(operator.add, [self.table_apps.columnWidth(i) for i in range(self.table_apps.columnCount())]) + # + # if self.ref_bt_upgrade.isVisible() or self.ref_bt_settings.isVisible(): + # new_width *= 1.07 + # else: + # new_width = self.toolbar_top.width() + # + # if accept_lower_width or new_width > self.width(): + # self.resize(new_width, self.height()) + # + # if self.ref_bt_upgrade.isVisible() and self.bt_upgrade.visibleRegion().isEmpty(): + # self.adjustSize() if self.first_refresh: qt_utils.centralize(self)