[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

This commit is contained in:
Vinicius Moreira
2020-08-11 11:08:09 -03:00
parent b68a21894e
commit 57c88f9589
5 changed files with 46 additions and 10 deletions

View File

@@ -12,6 +12,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
<img src="https://raw.githubusercontent.com/vinifmor/bauh/staging/pictures/releases/0.9.7/arch_install_reason.png">
</p>
- 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

View File

@@ -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):

View File

@@ -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()))

View File

@@ -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:

View File

@@ -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: