mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 00:04:15 +02:00
[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:
@@ -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">
|
<img src="https://raw.githubusercontent.com/vinifmor/bauh/staging/pictures/releases/0.9.7/arch_install_reason.png">
|
||||||
</p>
|
</p>
|
||||||
- upgrade: only removing packages after downloading the required ones (when multi-threaded download is enabled)
|
- 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
|
### Fixes
|
||||||
- Arch
|
- Arch
|
||||||
|
|||||||
@@ -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,
|
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 = {
|
args = {
|
||||||
"stdout": PIPE,
|
"stdout": PIPE,
|
||||||
"stderr": PIPE,
|
"stderr": PIPE,
|
||||||
"cwd": cwd,
|
"cwd": cwd,
|
||||||
"shell": shell,
|
"shell": shell,
|
||||||
"env": gen_env(global_interpreter, lang)
|
"env": gen_env(global_interpreter, lang, extra_paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
if input:
|
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 = '.',
|
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, []
|
pwdin, final_cmd = None, []
|
||||||
|
|
||||||
if root_password is not 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)
|
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):
|
def notify_user(msg: str, app_name: str, icon_path: str):
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from bauh.api.constants import CONFIG_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_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()))
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ from bauh.commons import user, internet
|
|||||||
from bauh.commons.config import save_config
|
from bauh.commons.config import save_config
|
||||||
from bauh.commons.html import strip_html, bold
|
from bauh.commons.html import strip_html, bold
|
||||||
from bauh.commons.system import SystemProcess, ProcessHandler
|
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.config import read_config
|
||||||
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
|
||||||
@@ -166,6 +166,10 @@ class FlatpakManager(SoftwareManager):
|
|||||||
return SearchResult(models, None, len(models))
|
return SearchResult(models, None, len(models))
|
||||||
|
|
||||||
def downgrade(self, pkg: FlatpakApplication, root_password: str, watcher: ProcessWatcher) -> bool:
|
def downgrade(self, pkg: FlatpakApplication, root_password: str, watcher: ProcessWatcher) -> bool:
|
||||||
|
|
||||||
|
if not self._make_exports_dir(watcher):
|
||||||
|
return False
|
||||||
|
|
||||||
handler = ProcessHandler(watcher)
|
handler = ProcessHandler(watcher)
|
||||||
pkg.commit = flatpak.get_commit(pkg.id, pkg.branch, pkg.installation)
|
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:
|
def upgrade(self, requirements: UpgradeRequirements, root_password: str, watcher: ProcessWatcher) -> bool:
|
||||||
flatpak_version = flatpak.get_version()
|
flatpak_version = flatpak.get_version()
|
||||||
|
|
||||||
|
if not self._make_exports_dir(watcher):
|
||||||
|
return False
|
||||||
|
|
||||||
for req in requirements.to_upgrade:
|
for req in requirements.to_upgrade:
|
||||||
watcher.change_status("{} {} ({})...".format(self.i18n['manage_window.status.upgrading'], req.pkg.name, req.pkg.version))
|
watcher.change_status("{} {} ({})...".format(self.i18n['manage_window.status.upgrading'], req.pkg.name, req.pkg.version))
|
||||||
related, deps = False, False
|
related, deps = False, False
|
||||||
@@ -227,6 +235,10 @@ class FlatpakManager(SoftwareManager):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def uninstall(self, pkg: FlatpakApplication, root_password: str, watcher: ProcessWatcher, disk_loader: DiskCacheLoader) -> TransactionResult:
|
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)))
|
uninstalled = ProcessHandler(watcher).handle(SystemProcess(subproc=flatpak.uninstall(pkg.ref, pkg.installation)))
|
||||||
|
|
||||||
if uninstalled:
|
if uninstalled:
|
||||||
@@ -298,6 +310,18 @@ class FlatpakManager(SoftwareManager):
|
|||||||
|
|
||||||
return PackageHistory(pkg=pkg, history=commits, pkg_status_idx=status_idx)
|
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:
|
def install(self, pkg: FlatpakApplication, root_password: str, disk_loader: DiskCacheLoader, watcher: ProcessWatcher) -> TransactionResult:
|
||||||
config = read_config()
|
config = read_config()
|
||||||
|
|
||||||
@@ -348,6 +372,9 @@ class FlatpakManager(SoftwareManager):
|
|||||||
installed = flatpak.list_installed(flatpak_version)
|
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
|
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'))
|
res = handler.handle(SystemProcess(subproc=flatpak.install(str(pkg.id), pkg.origin, pkg.installation), wrong_error_phrase='Warning'))
|
||||||
|
|
||||||
if res:
|
if res:
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from typing import List, Dict, Set, Iterable
|
|||||||
from bauh.api.exception import NoInternetException
|
from bauh.api.exception import NoInternetException
|
||||||
from bauh.commons.system import new_subprocess, run_cmd, new_root_subprocess, SimpleProcess, ProcessHandler
|
from bauh.commons.system import new_subprocess, run_cmd, new_root_subprocess, 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
|
||||||
|
|
||||||
RE_SEVERAL_SPACES = re.compile(r'\s+')
|
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:
|
if not deps:
|
||||||
cmd.append('--no-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):
|
def uninstall(app_ref: str, installation: str):
|
||||||
@@ -173,7 +174,8 @@ def uninstall(app_ref: str, installation: str):
|
|||||||
:param app_ref:
|
:param app_ref:
|
||||||
:return:
|
: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]:
|
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)]
|
cmd = ['flatpak', 'update', '--no-related', '--no-deps', '--commit={}'.format(commit), app_ref, '-y', '--{}'.format(installation)]
|
||||||
|
|
||||||
if installation == 'system':
|
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:
|
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]:
|
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):
|
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:
|
def set_default_remotes(installation: str, root_password: str = None) -> SimpleProcess:
|
||||||
|
|||||||
Reference in New Issue
Block a user