diff --git a/CHANGELOG.md b/CHANGELOG.md index 9884dcce..bfa8a59d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Arch - regression: not displaying ignored updates +- Flatpak: + - executed commands are not displayed on the system default language and encoding (requires Flatpak >= 1.12) [#242](https://github.com/vinifmor/bauh/issues/242) + - applications and runtimes descriptions are not displayed on the system default language (when available) [#242](https://github.com/vinifmor/bauh/issues/242) + - UI: - fix: rare crash when updating table items diff --git a/bauh/gems/flatpak/__init__.py b/bauh/gems/flatpak/__init__.py index 0f6ec4c3..a775678b 100644 --- a/bauh/gems/flatpak/__init__.py +++ b/bauh/gems/flatpak/__init__.py @@ -18,6 +18,7 @@ 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') +VERSION_1_12 = parse_version('1.12') def get_icon_path() -> str: diff --git a/bauh/gems/flatpak/controller.py b/bauh/gems/flatpak/controller.py index 3a11f1a5..7cda8b2e 100644 --- a/bauh/gems/flatpak/controller.py +++ b/bauh/gems/flatpak/controller.py @@ -224,10 +224,11 @@ 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_simple(flatpak.downgrade(pkg.ref, - commit, - pkg.installation, - root_password)) + success, _ = ProcessHandler(watcher).handle_simple(flatpak.downgrade(app_ref=pkg.ref, + commit=commit, + installation=pkg.installation, + root_password=root_password, + version=flatpak.get_version())) watcher.change_progress(100) return success @@ -254,13 +255,15 @@ class FlatpakManager(SoftwareManager): if req.pkg.update_component: res, _ = ProcessHandler(watcher).handle_simple(flatpak.install(app_id=ref, installation=req.pkg.installation, - origin=req.pkg.origin)) + origin=req.pkg.origin, + version=flatpak_version)) else: res, _ = ProcessHandler(watcher).handle_simple(flatpak.update(app_ref=ref, installation=req.pkg.installation, related=related, - deps=deps)) + deps=deps, + version=flatpak_version)) watcher.change_substatus('') if not res: @@ -280,7 +283,9 @@ class FlatpakManager(SoftwareManager): if not self._make_exports_dir(watcher): return TransactionResult.fail() - uninstalled, _ = ProcessHandler(watcher).handle_simple(flatpak.uninstall(pkg.ref, pkg.installation)) + flatpak_version = flatpak.get_version() + uninstalled, _ = ProcessHandler(watcher).handle_simple(flatpak.uninstall(pkg.ref, pkg.installation, + flatpak_version)) if uninstalled: if self.suggestions_cache: @@ -445,7 +450,8 @@ class FlatpakManager(SoftwareManager): if not self._make_exports_dir(handler.watcher): return TransactionResult(success=False, installed=[], removed=[]) - installed, output = handler.handle_simple(flatpak.install(str(pkg.id), pkg.origin, pkg.installation)) + installed, output = handler.handle_simple(flatpak.install(str(pkg.id), pkg.origin, pkg.installation, + flatpak_version)) if not installed and 'error: No ref chosen to resolve matches' in output: ref_opts = RE_INSTALL_REFS.findall(output) @@ -459,7 +465,8 @@ class FlatpakManager(SoftwareManager): confirmation_label=self.i18n['proceed'].capitalize(), deny_label=self.i18n['cancel'].capitalize()): ref = ref_select.get_selected() - installed, output = handler.handle_simple(flatpak.install(ref, pkg.origin, pkg.installation)) + installed, output = handler.handle_simple(flatpak.install(ref, pkg.origin, pkg.installation, + flatpak_version)) pkg.ref = ref pkg.runtime = 'runtime' in ref else: diff --git a/bauh/gems/flatpak/flatpak.py b/bauh/gems/flatpak/flatpak.py index 1882e7f9..7d781cce 100755 --- a/bauh/gems/flatpak/flatpak.py +++ b/bauh/gems/flatpak/flatpak.py @@ -9,9 +9,9 @@ from packaging.version import Version from packaging.version import parse as parse_version 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, DEFAULT_LANG from bauh.commons.util import size_to_byte -from bauh.gems.flatpak import EXPORTS_PATH, VERSION_1_3, VERSION_1_2, VERSION_1_5 +from bauh.gems.flatpak import EXPORTS_PATH, VERSION_1_3, VERSION_1_2, VERSION_1_5, VERSION_1_12 RE_SEVERAL_SPACES = re.compile(r'\s+') RE_COMMIT = re.compile(r'(Latest commit|Commit)\s*:\s*(.+)') @@ -95,7 +95,7 @@ def list_installed(version: Version) -> List[dict]: apps = [] if version < VERSION_1_2: - app_list = new_subprocess(['flatpak', 'list', '-d']) + app_list = new_subprocess(['flatpak', 'list', '-d'], lang=None) for o in app_list.stdout: if o: @@ -118,7 +118,7 @@ def list_installed(version: Version) -> List[dict]: else: 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], lang=None) for o in app_list.stdout: if o: @@ -157,7 +157,7 @@ def list_installed(version: Version) -> List[dict]: return apps -def update(app_ref: str, installation: str, related: bool = False, deps: bool = False) -> SimpleProcess: +def update(app_ref: str, installation: str, version: Version, related: bool = False, deps: bool = False) -> SimpleProcess: cmd = ['flatpak', 'update', '-y', app_ref, '--{}'.format(installation)] if not related: @@ -166,12 +166,14 @@ def update(app_ref: str, installation: str, related: bool = False, deps: bool = if not deps: cmd.append('--no-deps') - return SimpleProcess(cmd=cmd, extra_paths={EXPORTS_PATH}, shell=True) + return SimpleProcess(cmd=cmd, extra_paths={EXPORTS_PATH}, shell=True, + lang=DEFAULT_LANG if version < VERSION_1_12 else None) -def uninstall(app_ref: str, installation: str) -> SimpleProcess: +def uninstall(app_ref: str, installation: str, version: Version) -> SimpleProcess: return SimpleProcess(cmd=['flatpak', 'uninstall', app_ref, '-y', '--{}'.format(installation)], extra_paths={EXPORTS_PATH}, + lang=DEFAULT_LANG if version < VERSION_1_12 else None, shell=True) @@ -229,14 +231,15 @@ def read_updates(version: Version, installation: str) -> Dict[str, set]: return res -def downgrade(app_ref: str, commit: str, installation: str, root_password: Optional[str]) -> SimpleProcess: +def downgrade(app_ref: str, commit: str, installation: str, root_password: Optional[str], version: Version) -> SimpleProcess: cmd = ['flatpak', 'update', '--no-related', '--no-deps', '--commit={}'.format(commit), app_ref, '-y', '--{}'.format(installation)] return SimpleProcess(cmd=cmd, - root_password=root_password if installation=='system' else None, + root_password=root_password if installation == 'system' else None, extra_paths={EXPORTS_PATH}, - success_phrases={'Changes complete.', 'Updates complete.'}, - wrong_error_phrases={'Warning'}) + lang=DEFAULT_LANG if version < VERSION_1_12 else None, + success_phrases={'Changes complete.', 'Updates complete.'} if version < VERSION_1_12 else None, + wrong_error_phrases={'Warning'} if version < VERSION_1_12 else None) def get_app_commits(app_ref: str, origin: str, installation: str, handler: ProcessHandler) -> Optional[List[str]]: @@ -282,13 +285,13 @@ def get_app_commits_data(app_ref: str, origin: str, installation: str, full_str: 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), lang=None) found = [] - split_res = res.split('\n') + split_res = res.strip().split('\n') - if split_res and split_res[0].lower() != 'no matches found': + if split_res and '\t' in split_res[0]: for info in split_res: if info: info_list = info.split('\t') @@ -359,10 +362,11 @@ def search(version: Version, word: str, installation: str, app_id: bool = False) return found -def install(app_id: str, origin: str, installation: str) -> SimpleProcess: +def install(app_id: str, origin: str, installation: str, version: Version) -> SimpleProcess: return SimpleProcess(cmd=['flatpak', 'install', origin, app_id, '-y', '--{}'.format(installation)], extra_paths={EXPORTS_PATH}, - wrong_error_phrases={'Warning'}, + lang=DEFAULT_LANG if version < VERSION_1_12 else None, + wrong_error_phrases={'Warning'} if version < VERSION_1_12 else None, shell=True) diff --git a/bauh/gems/flatpak/worker.py b/bauh/gems/flatpak/worker.py index 529c4afc..e16df1bb 100644 --- a/bauh/gems/flatpak/worker.py +++ b/bauh/gems/flatpak/worker.py @@ -55,7 +55,9 @@ class FlatpakAsyncDataLoader(Thread): if not self.app.name: self.app.name = data.get('name') - self.app.description = data.get('description', data.get('summary', None)) + if not self.app.description: + self.app.description = data.get('description', data.get('summary', None)) + self.app.icon_url = data.get('iconMobileUrl', None) self.app.latest_version = data.get('currentReleaseVersion', self.app.version)