[flatpak] fix -> crashing for version 1.10

This commit is contained in:
Vinicius Moreira
2021-01-19 10:16:53 -03:00
parent 85cbf081ee
commit cd4519d7d9
4 changed files with 37 additions and 26 deletions

View File

@@ -58,6 +58,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- displaying packages removed from AUR as AUR packages - displaying packages removed from AUR as AUR packages
- downloading AUR index during the initialization process when AUR support is disabled - downloading AUR index during the initialization process when AUR support is disabled
- Flatpak - Flatpak
- crashing for version 1.10 [#167](https://github.com/vinifmor/bauh/issues/167)
- crashing when trying to retrieve size of runtimes subcomponents [#164](https://github.com/vinifmor/bauh/issues/164) - crashing when trying to retrieve size of runtimes subcomponents [#164](https://github.com/vinifmor/bauh/issues/164)
- UI - UI
- initialization dialog hanging sometimes (due to thread locking) - initialization dialog hanging sometimes (due to thread locking)

View File

@@ -1,6 +1,8 @@
import os import os
from pathlib import Path from pathlib import Path
from pkg_resources import parse_version
from bauh.api.constants import CONFIG_PATH from bauh.api.constants import CONFIG_PATH
from bauh.commons import resource from bauh.commons import resource
@@ -10,6 +12,10 @@ CONFIG_FILE = '{}/flatpak.yml'.format(CONFIG_PATH)
CONFIG_DIR = '{}/flatpak'.format(CONFIG_PATH) CONFIG_DIR = '{}/flatpak'.format(CONFIG_PATH)
UPDATES_IGNORED_FILE = '{}/updates_ignored.txt'.format(CONFIG_DIR) UPDATES_IGNORED_FILE = '{}/updates_ignored.txt'.format(CONFIG_DIR)
EXPORTS_PATH = '{}/.local/share/flatpak/exports/share'.format(str(Path.home())) EXPORTS_PATH = '{}/.local/share/flatpak/exports/share'.format(str(Path.home()))
VERSION_1_2 = parse_version('1.2')
VERSION_1_3 = parse_version('1.3')
VERSION_1_4 = parse_version('1.4')
VERSION_1_5 = parse_version('1.5')
def get_icon_path() -> str: def get_icon_path() -> str:

View File

@@ -7,6 +7,8 @@ from pathlib import Path
from threading import Thread from threading import Thread
from typing import List, Set, Type, Tuple, Optional from typing import List, Set, Type, Tuple, Optional
from packaging.version import Version
from bauh.api.abstract.controller import SearchResult, SoftwareManager, ApplicationContext, UpgradeRequirements, \ from bauh.api.abstract.controller import SearchResult, SoftwareManager, ApplicationContext, UpgradeRequirements, \
UpgradeRequirement, TransactionResult, SoftwareAction UpgradeRequirement, TransactionResult, SoftwareAction
from bauh.api.abstract.disk import DiskCacheLoader from bauh.api.abstract.disk import DiskCacheLoader
@@ -20,7 +22,7 @@ from bauh.commons.boot import CreateConfigFile
from bauh.commons.html import strip_html, bold from bauh.commons.html import strip_html, bold
from bauh.commons.system import 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, \
get_icon_path get_icon_path, VERSION_1_5, VERSION_1_4
from bauh.gems.flatpak.config import FlatpakConfigManager from bauh.gems.flatpak.config import FlatpakConfigManager
from bauh.gems.flatpak.constants import FLATHUB_API_URL from bauh.gems.flatpak.constants import FLATHUB_API_URL
from bauh.gems.flatpak.model import FlatpakApplication from bauh.gems.flatpak.model import FlatpakApplication
@@ -35,12 +37,12 @@ class FlatpakManager(SoftwareManager):
def __init__(self, context: ApplicationContext): def __init__(self, context: ApplicationContext):
super(FlatpakManager, self).__init__(context=context) super(FlatpakManager, self).__init__(context=context)
self.i18n = context.i18n self.i18n = context.i18n
self.api_cache = context.cache_factory.new() self.api_cache = context.cache_factory.new(None)
self.category_cache = context.cache_factory.new() self.category_cache = context.cache_factory.new(None)
context.disk_loader_factory.map(FlatpakApplication, self.api_cache) context.disk_loader_factory.map(FlatpakApplication, self.api_cache)
self.enabled = True self.enabled = True
self.http_client = context.http_client self.http_client = context.http_client
self.suggestions_cache = context.cache_factory.new() self.suggestions_cache = context.cache_factory.new(None)
self.logger = context.logger self.logger = context.logger
self.configman = FlatpakConfigManager() self.configman = FlatpakConfigManager()
@@ -111,7 +113,7 @@ class FlatpakManager(SoftwareManager):
res.total = len(res.installed) + len(res.new) res.total = len(res.installed) + len(res.new)
return res return res
def _add_updates(self, version: str, output: list): def _add_updates(self, version: Version, output: list):
output.append(flatpak.list_updates_as_str(version)) output.append(flatpak.list_updates_as_str(version))
def read_installed(self, disk_loader: Optional[DiskCacheLoader], limit: int = -1, only_apps: bool = False, pkg_types: Set[Type[SoftwarePackage]] = None, internet_available: bool = None) -> SearchResult: def read_installed(self, disk_loader: Optional[DiskCacheLoader], limit: int = -1, only_apps: bool = False, pkg_types: Set[Type[SoftwarePackage]] = None, internet_available: bool = None) -> SearchResult:
@@ -141,7 +143,7 @@ class FlatpakManager(SoftwareManager):
models.append(model) models.append(model)
if update_map and (update_map['full'] or update_map['partial']): if update_map and (update_map['full'] or update_map['partial']):
if version >= '1.4.0': if version >= VERSION_1_4:
update_id = '{}/{}/{}'.format(app_json['id'], app_json['branch'], app_json['installation']) update_id = '{}/{}/{}'.format(app_json['id'], app_json['branch'], app_json['installation'])
if update_map['full'] and update_id in update_map['full']: if update_map['full'] and update_id in update_map['full']:
@@ -210,7 +212,7 @@ class FlatpakManager(SoftwareManager):
related, deps = False, False related, deps = False, False
ref = req.pkg.ref ref = req.pkg.ref
if req.pkg.partial and flatpak_version < '1.5': if req.pkg.partial and flatpak_version < VERSION_1_5:
related, deps = True, True related, deps = True, True
ref = req.pkg.base_ref ref = req.pkg.base_ref
@@ -252,10 +254,10 @@ class FlatpakManager(SoftwareManager):
def get_info(self, app: FlatpakApplication) -> dict: def get_info(self, app: FlatpakApplication) -> dict:
if app.installed: if app.installed:
version = flatpak.get_version() version = flatpak.get_version()
id_ = app.base_id if app.partial and version < '1.5' else app.id id_ = app.base_id if app.partial and version < VERSION_1_5 else app.id
app_info = flatpak.get_app_info_fields(id_, app.branch, app.installation) app_info = flatpak.get_app_info_fields(id_, app.branch, app.installation)
if app.partial and version < '1.5': if app.partial and version < VERSION_1_5:
app_info['id'] = app.id app_info['id'] = app.id
app_info['ref'] = app.ref app_info['ref'] = app.ref

View File

@@ -5,10 +5,13 @@ import traceback
from datetime import datetime from datetime import datetime
from typing import List, Dict, Set, Iterable, Optional from typing import List, Dict, Set, Iterable, Optional
from packaging.version import Version
from pkg_resources import parse_version
from bauh.api.exception import NoInternetException from bauh.api.exception import NoInternetException
from bauh.commons.system import new_subprocess, run_cmd, 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, VERSION_1_3, VERSION_1_2, VERSION_1_5
RE_SEVERAL_SPACES = re.compile(r'\s+') RE_SEVERAL_SPACES = re.compile(r'\s+')
RE_COMMIT = re.compile(r'(Latest commit|Commit)\s*:\s*(.+)') RE_COMMIT = re.compile(r'(Latest commit|Commit)\s*:\s*(.+)')
@@ -65,9 +68,9 @@ def is_installed():
return False if version is None else True return False if version is None else True
def get_version(): def get_version() -> Optional[Version]:
res = run_cmd('{} --version'.format('flatpak'), print_error=False) res = run_cmd('{} --version'.format('flatpak'), print_error=False)
return res.split(' ')[1].strip() if res else None return parse_version(res.split(' ')[1].strip()) if res else None
def get_app_info(app_id: str, branch: str, installation: str): def get_app_info(app_id: str, branch: str, installation: str):
@@ -87,11 +90,10 @@ def get_commit(app_id: str, branch: str, installation: str) -> Optional[str]:
return commits[0][1].strip() return commits[0][1].strip()
def list_installed(version: str) -> List[dict]: def list_installed(version: Version) -> List[dict]:
apps = [] apps = []
if version < '1.2': if version < VERSION_1_3:
app_list = new_subprocess(['flatpak', 'list', '-d']) app_list = new_subprocess(['flatpak', 'list', '-d'])
for o in app_list.stdout: for o in app_list.stdout:
@@ -114,7 +116,7 @@ def list_installed(version: str) -> List[dict]:
}) })
else: else:
cols = 'application,ref,arch,branch,description,origin,options,{}version'.format('' if version < '1.3' else 'name,') cols = 'application,ref,arch,branch,description,origin,options,{}version'.format('' if version < VERSION_1_3 else 'name,')
app_list = new_subprocess(['flatpak', 'list', '--columns=' + cols]) app_list = new_subprocess(['flatpak', 'list', '--columns=' + cols])
for o in app_list.stdout: for o in app_list.stdout:
@@ -122,7 +124,7 @@ def list_installed(version: str) -> List[dict]:
data = o.decode().strip().split('\t') data = o.decode().strip().split('\t')
runtime = 'runtime' in data[6] runtime = 'runtime' in data[6]
if version < '1.3': if version < VERSION_1_3:
name = data[0].split('.')[-1] name = data[0].split('.')[-1]
if len(data) > 7 and data[7]: if len(data) > 7 and data[7]:
@@ -172,7 +174,7 @@ def uninstall(app_ref: str, installation: str) -> SimpleProcess:
shell=True) shell=True)
def list_updates_as_str(version: str) -> Dict[str, set]: def list_updates_as_str(version: Version) -> Dict[str, set]:
updates = read_updates(version, 'system') updates = read_updates(version, 'system')
user_updates = read_updates(version, 'user') user_updates = read_updates(version, 'user')
@@ -182,9 +184,9 @@ def list_updates_as_str(version: str) -> Dict[str, set]:
return updates return updates
def read_updates(version: str, installation: str) -> Dict[str, set]: def read_updates(version: Version, installation: str) -> Dict[str, set]:
res = {'partial': set(), 'full': set()} res = {'partial': set(), 'full': set()}
if version < '1.2': if version < VERSION_1_2:
try: try:
output = run_cmd('{} update --no-related --no-deps --{}'.format('flatpak', installation), ignore_return_code=True) output = run_cmd('{} update --no-related --no-deps --{}'.format('flatpak', installation), ignore_return_code=True)
@@ -205,7 +207,7 @@ def read_updates(version: str, installation: str) -> Dict[str, set]:
line_split = o.decode().strip().split('\t') line_split = o.decode().strip().split('\t')
if len(line_split) > 2: if len(line_split) > 2:
if version >= '1.5.0': if version >= VERSION_1_5:
update_id = '{}/{}/{}'.format(line_split[2], line_split[3], installation) update_id = '{}/{}/{}'.format(line_split[2], line_split[3], installation)
else: else:
update_id = '{}/{}/{}'.format(line_split[2], line_split[4], installation) update_id = '{}/{}/{}'.format(line_split[2], line_split[4], installation)
@@ -275,7 +277,7 @@ def get_app_commits_data(app_ref: str, origin: str, installation: str, full_str:
return commits return commits
def search(version: str, word: str, installation: str, app_id: bool = False) -> List[dict]: def search(version: Version, word: str, installation: str, app_id: bool = False) -> List[dict]:
res = run_cmd('{} search {} --{}'.format('flatpak', word, installation)) res = run_cmd('{} search {} --{}'.format('flatpak', word, installation))
@@ -287,7 +289,7 @@ def search(version: str, word: str, installation: str, app_id: bool = False) ->
for info in split_res: for info in split_res:
if info: if info:
info_list = info.split('\t') info_list = info.split('\t')
if version >= '1.3.0': if version >= VERSION_1_3:
id_ = info_list[2].strip() id_ = info_list[2].strip()
if app_id and id_ != word: if app_id and id_ != word:
@@ -306,7 +308,7 @@ def search(version: str, word: str, installation: str, app_id: bool = False) ->
'arch': None, # unknown at this moment, 'arch': None, # unknown at this moment,
'ref': None # unknown at this moment 'ref': None # unknown at this moment
} }
elif version >= '1.2.0': elif version >= VERSION_1_2:
id_ = info_list[1].strip() id_ = info_list[1].strip()
if app_id and id_ != word: if app_id and id_ != word:
@@ -392,9 +394,9 @@ def run(app_id: str):
subprocess.Popen(['flatpak run {}'.format(app_id)], shell=True, env={**os.environ}) subprocess.Popen(['flatpak run {}'.format(app_id)], shell=True, env={**os.environ})
def map_update_download_size(app_ids: Iterable[str], installation: str, version: str) -> Dict[str, int]: def map_update_download_size(app_ids: Iterable[str], installation: str, version: Version) -> Dict[str, int]:
success, output = ProcessHandler().handle_simple(SimpleProcess(['flatpak', 'update', '--{}'.format(installation)])) success, output = ProcessHandler().handle_simple(SimpleProcess(['flatpak', 'update', '--{}'.format(installation)]))
if version >= '1.5': if version >= VERSION_1_5:
res = {} res = {}
p = re.compile(r'^\d+.\t') p = re.compile(r'^\d+.\t')
p2 = re.compile(r'\s([0-9.?a-zA-Z]+)\s?') p2 = re.compile(r'\s([0-9.?a-zA-Z]+)\s?')