mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 01:14: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:
@@ -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()))
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user