mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 23:14:16 +02:00
Flatpak not required
This commit is contained in:
@@ -12,7 +12,6 @@ from fpakman.util import util
|
|||||||
from fpakman.core.controller import FlatpakManager, GenericApplicationManager
|
from fpakman.core.controller import FlatpakManager, GenericApplicationManager
|
||||||
from fpakman.util.cache import Cache
|
from fpakman.util.cache import Cache
|
||||||
from fpakman.util.memory import CacheCleaner
|
from fpakman.util.memory import CacheCleaner
|
||||||
from fpakman.view.qt import common
|
|
||||||
from fpakman.view.qt.systray import TrayIcon
|
from fpakman.view.qt.systray import TrayIcon
|
||||||
|
|
||||||
app_name = 'fpakman'
|
app_name = 'fpakman'
|
||||||
@@ -54,8 +53,6 @@ if args.update_notification == 0:
|
|||||||
|
|
||||||
locale_keys = util.get_locale_keys(args.locale)
|
locale_keys = util.get_locale_keys(args.locale)
|
||||||
|
|
||||||
common.check_flatpak_installed(locale_keys)
|
|
||||||
|
|
||||||
caches = []
|
caches = []
|
||||||
flatpak_api_cache = Cache(expiration_time=args.cache_exp)
|
flatpak_api_cache = Cache(expiration_time=args.cache_exp)
|
||||||
caches.append(flatpak_api_cache)
|
caches.append(flatpak_api_cache)
|
||||||
|
|||||||
@@ -57,6 +57,10 @@ class ApplicationManager(ABC):
|
|||||||
def install_and_stream(self, app: Application):
|
def install_and_stream(self, app: Application):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def is_enabled(self) -> bool:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class FlatpakManager(ApplicationManager):
|
class FlatpakManager(ApplicationManager):
|
||||||
|
|
||||||
@@ -190,6 +194,9 @@ class FlatpakManager(ApplicationManager):
|
|||||||
def install_and_stream(self, app: FlatpakApplication):
|
def install_and_stream(self, app: FlatpakApplication):
|
||||||
return flatpak.install_and_stream(app.base_data.id, app.origin)
|
return flatpak.install_and_stream(app.base_data.id, app.origin)
|
||||||
|
|
||||||
|
def is_enabled(self):
|
||||||
|
return flatpak.is_installed()
|
||||||
|
|
||||||
|
|
||||||
class GenericApplicationManager(ApplicationManager):
|
class GenericApplicationManager(ApplicationManager):
|
||||||
|
|
||||||
@@ -200,14 +207,16 @@ class GenericApplicationManager(ApplicationManager):
|
|||||||
def search(self, word: str) -> List[Application]:
|
def search(self, word: str) -> List[Application]:
|
||||||
apps = []
|
apps = []
|
||||||
for man in self.managers:
|
for man in self.managers:
|
||||||
apps.extend(man.search(word))
|
if man.is_enabled():
|
||||||
|
apps.extend(man.search(word))
|
||||||
|
|
||||||
return apps
|
return apps
|
||||||
|
|
||||||
def read_installed(self) -> List[Application]:
|
def read_installed(self) -> List[Application]:
|
||||||
installed = []
|
installed = []
|
||||||
for man in self.managers:
|
for man in self.managers:
|
||||||
installed.extend(man.read_installed())
|
if man.is_enabled():
|
||||||
|
installed.extend(man.read_installed())
|
||||||
|
|
||||||
return installed
|
return installed
|
||||||
|
|
||||||
@@ -215,30 +224,55 @@ class GenericApplicationManager(ApplicationManager):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def downgrade_app(self, app: Application, root_password: str):
|
def downgrade_app(self, app: Application, root_password: str):
|
||||||
manager = self.map.get(app.__class__)
|
man = self._get_manager_for(app)
|
||||||
|
|
||||||
if manager.can_downgrade():
|
if man and man.can_downgrade():
|
||||||
return manager.downgrade_app(app, root_password)
|
return man.downgrade_app(app, root_password)
|
||||||
else:
|
else:
|
||||||
raise Exception("downgrade is not possible for {}".format(app.__class__.__name__))
|
raise Exception("downgrade is not possible for {}".format(app.__class__.__name__))
|
||||||
|
|
||||||
def clean_cache_for(self, app: Application):
|
def clean_cache_for(self, app: Application):
|
||||||
self.map[app.__class__].clean_cache_for(app)
|
man = self._get_manager_for(app)
|
||||||
|
|
||||||
|
if man:
|
||||||
|
return man.clean_cache_for(app)
|
||||||
|
|
||||||
def update_and_stream(self, app: Application):
|
def update_and_stream(self, app: Application):
|
||||||
return self.map[app.__class__].update_and_stream(app)
|
man = self._get_manager_for(app)
|
||||||
|
|
||||||
|
if man:
|
||||||
|
return man.update_and_stream(app)
|
||||||
|
|
||||||
def uninstall_and_stream(self, app: Application):
|
def uninstall_and_stream(self, app: Application):
|
||||||
return self.map[app.__class__].uninstall_and_stream(app)
|
man = self._get_manager_for(app)
|
||||||
|
|
||||||
|
if man:
|
||||||
|
return man.uninstall_and_stream(app)
|
||||||
|
|
||||||
def install_and_stream(self, app: Application):
|
def install_and_stream(self, app: Application):
|
||||||
return self.map[app.__class__].install_and_stream(app)
|
man = self._get_manager_for(app)
|
||||||
|
|
||||||
|
if man:
|
||||||
|
return man.install_and_stream(app)
|
||||||
|
|
||||||
def get_info(self, app: Application):
|
def get_info(self, app: Application):
|
||||||
return self.map[app.__class__].get_info(app)
|
man = self._get_manager_for(app)
|
||||||
|
|
||||||
|
if man:
|
||||||
|
return man.get_info(app)
|
||||||
|
|
||||||
def get_history(self, app: Application):
|
def get_history(self, app: Application):
|
||||||
return self.map[app.__class__].get_history(app)
|
man = self._get_manager_for(app)
|
||||||
|
|
||||||
|
if man:
|
||||||
|
return man.get_history(app)
|
||||||
|
|
||||||
def get_app_type(self):
|
def get_app_type(self):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def is_enabled(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def _get_manager_for(self, app: Application):
|
||||||
|
man = self.map[app.__class__]
|
||||||
|
return man if man and man.is_enabled() else None
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ def is_installed():
|
|||||||
|
|
||||||
|
|
||||||
def get_version():
|
def get_version():
|
||||||
res = system.run_cmd('{} --version'.format(BASE_CMD))
|
res = system.run_cmd('{} --version'.format(BASE_CMD), print_error=False)
|
||||||
return res.split(' ')[1].strip() if res else None
|
return res.split(' ')[1].strip() if res else None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,17 @@ from typing import List
|
|||||||
from fpakman.core import resource
|
from fpakman.core import resource
|
||||||
|
|
||||||
|
|
||||||
def run_cmd(cmd: str, expected_code: int = 0, ignore_return_code: bool = False) -> str:
|
def run_cmd(cmd: str, expected_code: int = 0, ignore_return_code: bool = False, print_error: bool = True) -> str:
|
||||||
res = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, env={'LANG': 'en'})
|
args = {
|
||||||
|
"shell": True,
|
||||||
|
"stdout": subprocess.PIPE,
|
||||||
|
"env": {'LANG': 'en'}
|
||||||
|
}
|
||||||
|
|
||||||
|
if not print_error:
|
||||||
|
args["stderr"] = subprocess.DEVNULL
|
||||||
|
|
||||||
|
res = subprocess.run(cmd, **args)
|
||||||
return res.stdout.decode() if ignore_return_code or res.returncode == expected_code else None
|
return res.stdout.decode() if ignore_return_code or res.returncode == expected_code else None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -25,8 +25,6 @@ manage_window.status.installing=Installing
|
|||||||
manage_window.bt.refresh.tooltip=Reload the data about installed applications
|
manage_window.bt.refresh.tooltip=Reload the data about installed applications
|
||||||
manage_window.bt.upgrade.tooltip=Upgrade all selected applications
|
manage_window.bt.upgrade.tooltip=Upgrade all selected applications
|
||||||
manage_window.checkbox.show_details=Show details
|
manage_window.checkbox.show_details=Show details
|
||||||
popup.flatpak_not_installed.title=Error
|
|
||||||
popup.flatpak_not_installed.msg=flatpak seems not to be installed. Exiting
|
|
||||||
popup.root.title=Requires root privileges
|
popup.root.title=Requires root privileges
|
||||||
popup.root.password=Password
|
popup.root.password=Password
|
||||||
popup.root.bad_password.title=Error
|
popup.root.bad_password.title=Error
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ manage_window.status.installing=Instalando
|
|||||||
manage_window.bt.refresh.tooltip=Recarga los datos sobre los aplicativos instalados
|
manage_window.bt.refresh.tooltip=Recarga los datos sobre los aplicativos instalados
|
||||||
manage_window.bt.upgrade.tooltip=Actualiza todos los aplicativos seleccionados
|
manage_window.bt.upgrade.tooltip=Actualiza todos los aplicativos seleccionados
|
||||||
manage_window.checkbox.show_details=Mostrar detalles
|
manage_window.checkbox.show_details=Mostrar detalles
|
||||||
popup.flatpak_not_installed.title=Error
|
|
||||||
popup.flatpak_not_installed.msg=flatpak no parece estar instalado. Saliendo
|
|
||||||
popup.root.title=Requiere privilegios de root
|
popup.root.title=Requiere privilegios de root
|
||||||
popup.root.password=Contraseña
|
popup.root.password=Contraseña
|
||||||
popup.root.bad_password.title=Error
|
popup.root.bad_password.title=Error
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ manage_window.status.installing=Instalando
|
|||||||
manage_window.bt.refresh.tooltip=Recarrega os dados sobre os aplicativos instalados
|
manage_window.bt.refresh.tooltip=Recarrega os dados sobre os aplicativos instalados
|
||||||
manage_window.bt.upgrade.tooltip=Atualiza todos os aplicativos selecionados
|
manage_window.bt.upgrade.tooltip=Atualiza todos os aplicativos selecionados
|
||||||
manage_window.checkbox.show_details=Mostrar detalhes
|
manage_window.checkbox.show_details=Mostrar detalhes
|
||||||
popup.flatpak_not_installed.title=Erro
|
|
||||||
popup.flatpak_not_installed.msg=flatpak não parece estar instalado. Saindo
|
|
||||||
popup.root.title=Requer privilégios de root
|
popup.root.title=Requer privilégios de root
|
||||||
popup.root.password=Senha
|
popup.root.password=Senha
|
||||||
popup.root.bad_password.title=Erro
|
popup.root.bad_password.title=Erro
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
from fpakman.core import flatpak
|
|
||||||
from fpakman.view.qt import dialog
|
|
||||||
|
|
||||||
|
|
||||||
def check_flatpak_installed(locale_keys: dict):
|
|
||||||
|
|
||||||
if not flatpak.is_installed():
|
|
||||||
dialog.show_error(title=locale_keys['popup.flatpak_not_installed.title'],
|
|
||||||
body=locale_keys['popup.flatpak_not_installed.msg'] + '...')
|
|
||||||
exit(1)
|
|
||||||
@@ -12,7 +12,6 @@ from fpakman.core import resource
|
|||||||
from fpakman.core.controller import ApplicationManager
|
from fpakman.core.controller import ApplicationManager
|
||||||
from fpakman.core.model import Application
|
from fpakman.core.model import Application
|
||||||
from fpakman.util.cache import Cache
|
from fpakman.util.cache import Cache
|
||||||
from fpakman.view.qt import common
|
|
||||||
from fpakman.view.qt.apps_table import AppsTable
|
from fpakman.view.qt.apps_table import AppsTable
|
||||||
from fpakman.view.qt.history import HistoryDialog
|
from fpakman.view.qt.history import HistoryDialog
|
||||||
from fpakman.view.qt.info import InfoDialog
|
from fpakman.view.qt.info import InfoDialog
|
||||||
@@ -39,7 +38,6 @@ class ManageWindow(QWidget):
|
|||||||
self.icon_cache = icon_cache
|
self.icon_cache = icon_cache
|
||||||
|
|
||||||
self.icon_flathub = QIcon(resource.get_path('img/logo.svg'))
|
self.icon_flathub = QIcon(resource.get_path('img/logo.svg'))
|
||||||
self._check_flatpak_installed()
|
|
||||||
self.resize(ManageWindow.__BASE_HEIGHT__, ManageWindow.__BASE_HEIGHT__)
|
self.resize(ManageWindow.__BASE_HEIGHT__, ManageWindow.__BASE_HEIGHT__)
|
||||||
self.setWindowTitle(locale_keys['manage_window.title'])
|
self.setWindowTitle(locale_keys['manage_window.title'])
|
||||||
self.setWindowIcon(self.icon_flathub)
|
self.setWindowIcon(self.icon_flathub)
|
||||||
@@ -200,9 +198,6 @@ class ManageWindow(QWidget):
|
|||||||
self.hide()
|
self.hide()
|
||||||
self._handle_console_option(False)
|
self._handle_console_option(False)
|
||||||
|
|
||||||
def _check_flatpak_installed(self):
|
|
||||||
common.check_flatpak_installed(self.locale_keys)
|
|
||||||
|
|
||||||
def _acquire_lock(self):
|
def _acquire_lock(self):
|
||||||
|
|
||||||
self.thread_lock.acquire()
|
self.thread_lock.acquire()
|
||||||
@@ -241,20 +236,16 @@ class ManageWindow(QWidget):
|
|||||||
def refresh(self):
|
def refresh(self):
|
||||||
|
|
||||||
if self._acquire_lock():
|
if self._acquire_lock():
|
||||||
self._check_flatpak_installed()
|
|
||||||
self._begin_action(self.locale_keys['manage_window.status.refreshing'])
|
self._begin_action(self.locale_keys['manage_window.status.refreshing'])
|
||||||
|
|
||||||
self.thread_refresh.start()
|
self.thread_refresh.start()
|
||||||
|
|
||||||
def _finish_refresh(self, apps: List[Application]):
|
def _finish_refresh(self, apps: List[Application]):
|
||||||
|
|
||||||
self.update_apps(apps)
|
self.update_apps(apps)
|
||||||
self.finish_action()
|
self.finish_action()
|
||||||
self._release_lock()
|
self._release_lock()
|
||||||
|
|
||||||
def uninstall_app(self, app: ApplicationView):
|
def uninstall_app(self, app: ApplicationView):
|
||||||
self._check_flatpak_installed()
|
|
||||||
|
|
||||||
if self._acquire_lock():
|
if self._acquire_lock():
|
||||||
self._handle_console_option(True)
|
self._handle_console_option(True)
|
||||||
self._begin_action(self.locale_keys['manage_window.status.uninstalling'])
|
self._begin_action(self.locale_keys['manage_window.status.uninstalling'])
|
||||||
@@ -326,8 +317,6 @@ class ManageWindow(QWidget):
|
|||||||
self.move(geo.topLeft())
|
self.move(geo.topLeft())
|
||||||
|
|
||||||
def update_apps(self, apps: List[Application]):
|
def update_apps(self, apps: List[Application]):
|
||||||
self._check_flatpak_installed()
|
|
||||||
|
|
||||||
self.apps = []
|
self.apps = []
|
||||||
|
|
||||||
napps = 0 # number of apps (not libraries)
|
napps = 0 # number of apps (not libraries)
|
||||||
@@ -408,9 +397,6 @@ class ManageWindow(QWidget):
|
|||||||
self.label_status.setText('')
|
self.label_status.setText('')
|
||||||
|
|
||||||
def downgrade_app(self, app: dict):
|
def downgrade_app(self, app: dict):
|
||||||
|
|
||||||
self._check_flatpak_installed()
|
|
||||||
|
|
||||||
if self._acquire_lock():
|
if self._acquire_lock():
|
||||||
|
|
||||||
pwd = None
|
pwd = None
|
||||||
@@ -471,15 +457,11 @@ class ManageWindow(QWidget):
|
|||||||
self.thread_search.start()
|
self.thread_search.start()
|
||||||
|
|
||||||
def _finish_search(self, apps_found: List[Application]):
|
def _finish_search(self, apps_found: List[Application]):
|
||||||
|
|
||||||
self._release_lock()
|
self._release_lock()
|
||||||
self.finish_action()
|
self.finish_action()
|
||||||
self.update_apps(apps_found)
|
self.update_apps(apps_found)
|
||||||
|
|
||||||
def install_app(self, app: dict):
|
def install_app(self, app: dict):
|
||||||
|
|
||||||
self._check_flatpak_installed()
|
|
||||||
|
|
||||||
if self._acquire_lock():
|
if self._acquire_lock():
|
||||||
self._handle_console_option(True)
|
self._handle_console_option(True)
|
||||||
self._begin_action(self.locale_keys['manage_window.status.installing'])
|
self._begin_action(self.locale_keys['manage_window.status.installing'])
|
||||||
|
|||||||
Reference in New Issue
Block a user