From 57c88f9589d513c950332c4dc9af388cb187aef0 Mon Sep 17 00:00:00 2001
From: Vinicius Moreira
Date: Tue, 11 Aug 2020 11:08:09 -0300
Subject: [PATCH 1/2] [flatpak] improvement -> Creating the exports path
'~/.local/share/flatpak/exports/share' (if it does not exist) and adding it
to install/upgrade/downgrade/remove commands path to prevent warning messages
---
CHANGELOG.md | 2 ++
bauh/commons/system.py | 10 ++++++----
bauh/gems/flatpak/__init__.py | 2 ++
bauh/gems/flatpak/controller.py | 29 ++++++++++++++++++++++++++++-
bauh/gems/flatpak/flatpak.py | 13 ++++++++-----
5 files changed, 46 insertions(+), 10 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7aaf7b59..2c77f449 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- upgrade: only removing packages after downloading the required ones (when multi-threaded download is enabled)
+- Flatpak
+ - Creating the exports path **~/.local/share/flatpak/exports/share** (if it does not exist) and adding it to install/upgrade/downgrade/remove commands path to prevent warning messages.
### Fixes
- Arch
diff --git a/bauh/commons/system.py b/bauh/commons/system.py
index 5655ec7c..4624578e 100644
--- a/bauh/commons/system.py
+++ b/bauh/commons/system.py
@@ -216,13 +216,14 @@ def run_cmd(cmd: str, expected_code: int = 0, ignore_return_code: bool = False,
def new_subprocess(cmd: List[str], cwd: str = '.', shell: bool = False, stdin = None,
- global_interpreter: bool = USE_GLOBAL_INTERPRETER, lang: str = DEFAULT_LANG) -> subprocess.Popen:
+ global_interpreter: bool = USE_GLOBAL_INTERPRETER, lang: str = DEFAULT_LANG,
+ extra_paths: Set[str] = None) -> subprocess.Popen:
args = {
"stdout": PIPE,
"stderr": PIPE,
"cwd": cwd,
"shell": shell,
- "env": gen_env(global_interpreter, lang)
+ "env": gen_env(global_interpreter, lang, extra_paths)
}
if input:
@@ -232,7 +233,8 @@ def new_subprocess(cmd: List[str], cwd: str = '.', shell: bool = False, stdin =
def new_root_subprocess(cmd: List[str], root_password: str, cwd: str = '.',
- global_interpreter: bool = USE_GLOBAL_INTERPRETER, lang: str = DEFAULT_LANG) -> subprocess.Popen:
+ global_interpreter: bool = USE_GLOBAL_INTERPRETER, lang: str = DEFAULT_LANG,
+ extra_paths: Set[str] = None) -> subprocess.Popen:
pwdin, final_cmd = None, []
if root_password is not None:
@@ -241,7 +243,7 @@ def new_root_subprocess(cmd: List[str], root_password: str, cwd: str = '.',
final_cmd.extend(cmd)
- return subprocess.Popen(final_cmd, stdin=pwdin, stdout=PIPE, stderr=PIPE, cwd=cwd, env=gen_env(global_interpreter, lang))
+ return subprocess.Popen(final_cmd, stdin=pwdin, stdout=PIPE, stderr=PIPE, cwd=cwd, env=gen_env(global_interpreter, lang, extra_paths))
def notify_user(msg: str, app_name: str, icon_path: str):
diff --git a/bauh/gems/flatpak/__init__.py b/bauh/gems/flatpak/__init__.py
index cc5933d2..69e08aae 100644
--- a/bauh/gems/flatpak/__init__.py
+++ b/bauh/gems/flatpak/__init__.py
@@ -1,4 +1,5 @@
import os
+from pathlib import Path
from bauh.api.constants import CONFIG_PATH
@@ -7,3 +8,4 @@ SUGGESTIONS_FILE = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master
CONFIG_FILE = '{}/flatpak.yml'.format(CONFIG_PATH)
CONFIG_DIR = '{}/flatpak'.format(CONFIG_PATH)
UPDATES_IGNORED_FILE = '{}/updates_ignored.txt'.format(CONFIG_DIR)
+EXPORTS_PATH = '{}/.local/share/flatpak/exports/share'.format(str(Path.home()))
diff --git a/bauh/gems/flatpak/controller.py b/bauh/gems/flatpak/controller.py
index 76e2febe..0f79781e 100644
--- a/bauh/gems/flatpak/controller.py
+++ b/bauh/gems/flatpak/controller.py
@@ -18,7 +18,7 @@ from bauh.commons import user, internet
from bauh.commons.config import save_config
from bauh.commons.html import strip_html, bold
from bauh.commons.system import SystemProcess, ProcessHandler
-from bauh.gems.flatpak import flatpak, SUGGESTIONS_FILE, CONFIG_FILE, UPDATES_IGNORED_FILE, CONFIG_DIR
+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.constants import FLATHUB_API_URL
from bauh.gems.flatpak.model import FlatpakApplication
@@ -166,6 +166,10 @@ class FlatpakManager(SoftwareManager):
return SearchResult(models, None, len(models))
def downgrade(self, pkg: FlatpakApplication, root_password: str, watcher: ProcessWatcher) -> bool:
+
+ if not self._make_exports_dir(watcher):
+ return False
+
handler = ProcessHandler(watcher)
pkg.commit = flatpak.get_commit(pkg.id, pkg.branch, pkg.installation)
@@ -198,6 +202,10 @@ class FlatpakManager(SoftwareManager):
def upgrade(self, requirements: UpgradeRequirements, root_password: str, watcher: ProcessWatcher) -> bool:
flatpak_version = flatpak.get_version()
+
+ if not self._make_exports_dir(watcher):
+ return False
+
for req in requirements.to_upgrade:
watcher.change_status("{} {} ({})...".format(self.i18n['manage_window.status.upgrading'], req.pkg.name, req.pkg.version))
related, deps = False, False
@@ -227,6 +235,10 @@ class FlatpakManager(SoftwareManager):
return True
def uninstall(self, pkg: FlatpakApplication, root_password: str, watcher: ProcessWatcher, disk_loader: DiskCacheLoader) -> TransactionResult:
+
+ if not self._make_exports_dir(watcher):
+ return TransactionResult.fail()
+
uninstalled = ProcessHandler(watcher).handle(SystemProcess(subproc=flatpak.uninstall(pkg.ref, pkg.installation)))
if uninstalled:
@@ -298,6 +310,18 @@ class FlatpakManager(SoftwareManager):
return PackageHistory(pkg=pkg, history=commits, pkg_status_idx=status_idx)
+ def _make_exports_dir(self, watcher: ProcessWatcher) -> bool:
+ if not os.path.exists(EXPORTS_PATH):
+ self.logger.info("Creating dir '{}'".format(EXPORTS_PATH))
+ watcher.print('Creating dir {}'.format(EXPORTS_PATH))
+ try:
+ os.mkdir(EXPORTS_PATH)
+ except:
+ watcher.print('Error while creating the directory {}'.format(EXPORTS_PATH))
+ return False
+
+ return True
+
def install(self, pkg: FlatpakApplication, root_password: str, disk_loader: DiskCacheLoader, watcher: ProcessWatcher) -> TransactionResult:
config = read_config()
@@ -348,6 +372,9 @@ class FlatpakManager(SoftwareManager):
installed = flatpak.list_installed(flatpak_version)
installed_by_level = {'{}:{}:{}'.format(p['id'], p['name'], p['branch']) for p in installed if p['installation'] == pkg.installation} if installed else None
+ if not self._make_exports_dir(handler.watcher):
+ return TransactionResult(success=False, installed=[], removed=[])
+
res = handler.handle(SystemProcess(subproc=flatpak.install(str(pkg.id), pkg.origin, pkg.installation), wrong_error_phrase='Warning'))
if res:
diff --git a/bauh/gems/flatpak/flatpak.py b/bauh/gems/flatpak/flatpak.py
index 56eda91d..e16fa310 100755
--- a/bauh/gems/flatpak/flatpak.py
+++ b/bauh/gems/flatpak/flatpak.py
@@ -7,6 +7,7 @@ from typing import List, Dict, Set, Iterable
from bauh.api.exception import NoInternetException
from bauh.commons.system import new_subprocess, run_cmd, new_root_subprocess, SimpleProcess, ProcessHandler
from bauh.commons.util import size_to_byte
+from bauh.gems.flatpak import EXPORTS_PATH
RE_SEVERAL_SPACES = re.compile(r'\s+')
@@ -164,7 +165,7 @@ def update(app_ref: str, installation: str, related: bool = False, deps: bool =
if not deps:
cmd.append('--no-deps')
- return new_subprocess(cmd)
+ return new_subprocess(cmd=cmd, extra_paths={EXPORTS_PATH})
def uninstall(app_ref: str, installation: str):
@@ -173,7 +174,8 @@ def uninstall(app_ref: str, installation: str):
:param app_ref:
:return:
"""
- return new_subprocess(['flatpak', 'uninstall', app_ref, '-y', '--{}'.format(installation)])
+ 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]:
@@ -231,9 +233,9 @@ def downgrade(app_ref: str, commit: str, installation: str, root_password: str)
cmd = ['flatpak', 'update', '--no-related', '--no-deps', '--commit={}'.format(commit), app_ref, '-y', '--{}'.format(installation)]
if installation == 'system':
- return new_root_subprocess(cmd, root_password)
+ return new_root_subprocess(cmd=cmd, root_password=root_password, extra_paths={EXPORTS_PATH})
else:
- return new_subprocess(cmd)
+ return new_subprocess(cmd=cmd, extra_paths={EXPORTS_PATH})
def get_app_commits(app_ref: str, origin: str, installation: str, handler: ProcessHandler) -> List[str]:
@@ -354,7 +356,8 @@ def search(version: str, word: str, installation: str, app_id: bool = False) ->
def install(app_id: str, origin: str, installation: str):
- return new_subprocess(['flatpak', 'install', origin, app_id, '-y', '--{}'.format(installation)])
+ return new_subprocess(cmd=['flatpak', 'install', origin, app_id, '-y', '--{}'.format(installation)],
+ extra_paths={EXPORTS_PATH})
def set_default_remotes(installation: str, root_password: str = None) -> SimpleProcess:
From 444dca56418fdccdd1fab935d7bf1536534c16e5 Mon Sep 17 00:00:00 2001
From: Vinicius Moreira
Date: Tue, 11 Aug 2020 11:21:05 -0300
Subject: [PATCH 2/2] [flatpak] fix -> downgrading crashing with version 1.8.X
| history: the top commit is returned as '(null)'
---
CHANGELOG.md | 3 +++
bauh/gems/flatpak/controller.py | 14 +++++++++++++-
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2c77f449..87bfb355 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- not displaying all packages that must be uninstalled
- displaying "required size" for packages that must be uninstalled
- some conflict resolution scenarios when upgrading several packages
+- Flatpak
+ - downgrading crashing with version 1.8.X
+ - history: the top commit is returned as "(null)"
- UI
- crashing when nothing can be upgraded
diff --git a/bauh/gems/flatpak/controller.py b/bauh/gems/flatpak/controller.py
index 0f79781e..cd0e41a5 100644
--- a/bauh/gems/flatpak/controller.py
+++ b/bauh/gems/flatpak/controller.py
@@ -180,7 +180,13 @@ class FlatpakManager(SoftwareManager):
if commits is None:
return False
- commit_idx = commits.index(pkg.commit)
+ try:
+ commit_idx = commits.index(pkg.commit)
+ except ValueError:
+ if commits[0] == '(null)':
+ commit_idx = 0
+ else:
+ return False
# downgrade is not possible if the app current commit in the first one:
if commit_idx == len(commits) - 1:
@@ -301,13 +307,19 @@ class FlatpakManager(SoftwareManager):
def get_history(self, pkg: FlatpakApplication) -> PackageHistory:
pkg.commit = flatpak.get_commit(pkg.id, pkg.branch, pkg.installation)
commits = flatpak.get_app_commits_data(pkg.ref, pkg.origin, pkg.installation)
+
status_idx = 0
+ commit_found = False
for idx, data in enumerate(commits):
if data['commit'] == pkg.commit:
status_idx = idx
+ commit_found = True
break
+ if not commit_found and pkg.commit and commits[0]['commit'] == '(null)':
+ commits[0]['commit'] = pkg.commit
+
return PackageHistory(pkg=pkg, history=commits, pkg_status_idx=status_idx)
def _make_exports_dir(self, watcher: ProcessWatcher) -> bool: