refactoring based on the new api concepts

This commit is contained in:
Vinicius Moreira
2019-08-29 13:37:51 -03:00
parent be85d1cce5
commit 438f40f8a4
7 changed files with 38 additions and 38 deletions

View File

@@ -8,7 +8,7 @@ from bauh_api.util.http import HttpClient
from bauh import __version__, __app_name__, app_args from bauh import __version__, __app_name__, app_args
from bauh.core import resource, extensions from bauh.core import resource, extensions
from bauh.core.controller import GenericApplicationManager from bauh.core.controller import GenericSoftwareManager
from bauh.util import util from bauh.util import util
from bauh.util.memory import CacheCleaner from bauh.util.memory import CacheCleaner
from bauh.view.qt.systray import TrayIcon from bauh.view.qt.systray import TrayIcon
@@ -31,7 +31,7 @@ caches.append(icon_cache)
disk_loader_factory = DiskCacheLoaderFactory(disk_cache=args.disk_cache, cache_map=cache_map) disk_loader_factory = DiskCacheLoaderFactory(disk_cache=args.disk_cache, cache_map=cache_map)
manager = GenericApplicationManager(managers, disk_loader_factory=disk_loader_factory, app_args=args, locale_keys=locale_keys) manager = GenericSoftwareManager(managers, disk_loader_factory=disk_loader_factory, app_args=args, locale_keys=locale_keys)
manager.prepare() manager.prepare()
app = QApplication(sys.argv) app = QApplication(sys.argv)

View File

@@ -2,7 +2,7 @@ from argparse import Namespace
from threading import Thread from threading import Thread
from typing import List, Set from typing import List, Set
from bauh_api.abstract.controller import ApplicationManager, SearchResult from bauh_api.abstract.controller import SoftwareManager, SearchResult
from bauh_api.abstract.handler import ProcessWatcher from bauh_api.abstract.handler import ProcessWatcher
from bauh_api.abstract.model import SoftwarePackage, PackageUpdate, PackageHistory from bauh_api.abstract.model import SoftwarePackage, PackageUpdate, PackageHistory
from bauh_api.util.disk import DiskCacheLoader from bauh_api.util.disk import DiskCacheLoader
@@ -13,10 +13,10 @@ from bauh import ROOT_DIR
SUGGESTIONS_LIMIT = 6 SUGGESTIONS_LIMIT = 6
class GenericApplicationManager(ApplicationManager): class GenericSoftwareManager(SoftwareManager):
def __init__(self, managers: List[ApplicationManager], disk_loader_factory: DiskCacheLoaderFactory, app_args: Namespace, locale_keys: dict): def __init__(self, managers: List[SoftwareManager], disk_loader_factory: DiskCacheLoaderFactory, app_args: Namespace, locale_keys: dict):
super(GenericApplicationManager, self).__init__(app_args=app_args, app_cache=None, locale_keys=locale_keys, app_root_dir=ROOT_DIR, http_client=None) super(GenericSoftwareManager, self).__init__(app_args=app_args, app_cache=None, locale_keys=locale_keys, app_root_dir=ROOT_DIR, http_client=None)
self.managers = managers self.managers = managers
self.map = {t: m for m in self.managers for t in m.get_managed_types()} self.map = {t: m for m in self.managers for t in m.get_managed_types()}
self.disk_loader_factory = disk_loader_factory self.disk_loader_factory = disk_loader_factory
@@ -44,7 +44,7 @@ class GenericApplicationManager(ApplicationManager):
return res return res
def _is_enabled(self, man: ApplicationManager): def _is_enabled(self, man: SoftwareManager):
if self._enabled_map is not None: if self._enabled_map is not None:
enabled = self._enabled_map.get(man.get_managed_types()) enabled = self._enabled_map.get(man.get_managed_types())
@@ -57,7 +57,7 @@ class GenericApplicationManager(ApplicationManager):
else: else:
return man.is_enabled() return man.is_enabled()
def _search(self, word: str, man: ApplicationManager, disk_loader, res: SearchResult): def _search(self, word: str, man: SoftwareManager, disk_loader, res: SearchResult):
if self._is_enabled(man): if self._is_enabled(man):
apps_found = man.search(words=word, disk_loader=disk_loader) apps_found = man.search(words=word, disk_loader=disk_loader)
res.installed.extend(apps_found.installed) res.installed.extend(apps_found.installed)
@@ -169,7 +169,7 @@ class GenericApplicationManager(ApplicationManager):
def is_enabled(self): def is_enabled(self):
return True return True
def _get_manager_for(self, app: SoftwarePackage) -> ApplicationManager: def _get_manager_for(self, app: SoftwarePackage) -> SoftwareManager:
man = self.map[app.__class__] man = self.map[app.__class__]
return man if man and self._is_enabled(man) else None return man if man and self._is_enabled(man) else None
@@ -235,7 +235,7 @@ class GenericApplicationManager(ApplicationManager):
return warnings return warnings
def _fill_suggestions(self, suggestions: list, man: ApplicationManager, limit: int): def _fill_suggestions(self, suggestions: list, man: SoftwareManager, limit: int):
if self._is_enabled(man): if self._is_enabled(man):
man_sugs = man.list_suggestions(limit) man_sugs = man.list_suggestions(limit)

View File

@@ -4,7 +4,7 @@ import pkgutil
from argparse import Namespace from argparse import Namespace
from typing import List, Dict from typing import List, Dict
from bauh_api.abstract.controller import ApplicationManager from bauh_api.abstract.controller import SoftwareManager
from bauh_api.util.cache import Cache from bauh_api.util.cache import Cache
from bauh_api.util.http import HttpClient from bauh_api.util.http import HttpClient
@@ -17,7 +17,7 @@ ext_pattern = '{}_'.format(__app_name__)
def find_manager(member): def find_manager(member):
if not isinstance(member, str): if not isinstance(member, str):
if inspect.isclass(member) and inspect.getmro(member)[1].__name__ == 'ApplicationManager': if inspect.isclass(member) and inspect.getmro(member)[1].__name__ == 'SoftwareManager':
return member return member
elif inspect.ismodule(member) and member.__name__ not in ignore_modules: elif inspect.ismodule(member) and member.__name__ not in ignore_modules:
for name, mod in inspect.getmembers(member): for name, mod in inspect.getmembers(member):
@@ -26,7 +26,7 @@ def find_manager(member):
return manager_found return manager_found
def load_managers(caches: List[Cache], cache_map: Dict[type, Cache], locale_keys: Dict[str, str], app_args: Namespace, http_client: HttpClient) -> List[ApplicationManager]: def load_managers(caches: List[Cache], cache_map: Dict[type, Cache], locale_keys: Dict[str, str], app_args: Namespace, http_client: HttpClient) -> List[SoftwareManager]:
managers = [] managers = []
for m in pkgutil.iter_modules(): for m in pkgutil.iter_modules():

View File

@@ -10,10 +10,10 @@ from bauh_api.util.cache import Cache
class HistoryDialog(QDialog): class HistoryDialog(QDialog):
def __init__(self, app_history: PackageHistory, icon_cache: Cache, locale_keys: dict): def __init__(self, history: PackageHistory, icon_cache: Cache, locale_keys: dict):
super(HistoryDialog, self).__init__() super(HistoryDialog, self).__init__()
self.setWindowTitle('{} - {} '.format(locale_keys['popup.history.title'], app_history.app.base_data.name)) self.setWindowTitle('{} - {} '.format(locale_keys['popup.history.title'], history.pkg.base_data.name))
layout = QVBoxLayout() layout = QVBoxLayout()
self.setLayout(layout) self.setLayout(layout)
@@ -24,13 +24,13 @@ class HistoryDialog(QDialog):
table_history.verticalHeader().setVisible(False) table_history.verticalHeader().setVisible(False)
table_history.setAlternatingRowColors(True) table_history.setAlternatingRowColors(True)
table_history.setColumnCount(len(app_history.history[0])) table_history.setColumnCount(len(history.history[0]))
table_history.setRowCount(len(app_history.history)) table_history.setRowCount(len(history.history))
table_history.setHorizontalHeaderLabels([locale_keys.get(app_history.app.get_type() + '.history.' + key, key).capitalize() for key in sorted(app_history.history[0].keys())]) table_history.setHorizontalHeaderLabels([locale_keys.get(history.pkg.get_type() + '.history.' + key, key).capitalize() for key in sorted(history.history[0].keys())])
for row, commit in enumerate(app_history.history): for row, commit in enumerate(history.history):
current_status = app_history.app_status_idx == row current_status = history.pkg_status_idx == row
for col, key in enumerate(sorted(commit.keys())): for col, key in enumerate(sorted(commit.keys())):
item = QTableWidgetItem() item = QTableWidgetItem()
@@ -54,7 +54,7 @@ class HistoryDialog(QDialog):
new_width = reduce(operator.add, [table_history.columnWidth(i) for i in range(table_history.columnCount())]) new_width = reduce(operator.add, [table_history.columnWidth(i) for i in range(table_history.columnCount())])
self.resize(new_width, table_history.height()) self.resize(new_width, table_history.height())
icon_data = icon_cache.get(app_history.app.base_data.icon_url) icon_data = icon_cache.get(history.pkg.base_data.icon_url)
if icon_data and icon_data.get('icon'): if icon_data and icon_data.get('icon'):
self.setWindowIcon(icon_data.get('icon')) self.setWindowIcon(icon_data.get('icon'))

View File

@@ -9,7 +9,7 @@ from bauh_api.abstract.model import PackageUpdate
from bauh import __app_name__ from bauh import __app_name__
from bauh.core import resource from bauh.core import resource
from bauh_api.abstract.controller import ApplicationManager from bauh_api.abstract.controller import SoftwareManager
from bauh.util import util from bauh.util import util
from bauh.view.qt.about import AboutDialog from bauh.view.qt.about import AboutDialog
from bauh.view.qt.window import ManageWindow from bauh.view.qt.window import ManageWindow
@@ -19,7 +19,7 @@ class UpdateCheck(QThread):
signal = pyqtSignal(list) signal = pyqtSignal(list)
def __init__(self, manager: ApplicationManager, check_interval: int, parent=None): def __init__(self, manager: SoftwareManager, check_interval: int, parent=None):
super(UpdateCheck, self).__init__(parent) super(UpdateCheck, self).__init__(parent)
self.check_interval = check_interval self.check_interval = check_interval
self.manager = manager self.manager = manager
@@ -34,7 +34,7 @@ class UpdateCheck(QThread):
class TrayIcon(QSystemTrayIcon): class TrayIcon(QSystemTrayIcon):
def __init__(self, locale_keys: dict, manager: ApplicationManager, manage_window: ManageWindow, check_interval: int = 60, update_notification: bool = True): def __init__(self, locale_keys: dict, manager: SoftwareManager, manage_window: ManageWindow, check_interval: int = 60, update_notification: bool = True):
super(TrayIcon, self).__init__() super(TrayIcon, self).__init__()
self.locale_keys = locale_keys self.locale_keys = locale_keys
self.manager = manager self.manager = manager

View File

@@ -5,7 +5,7 @@ from typing import List
import requests import requests
from PyQt5.QtCore import QThread, pyqtSignal from PyQt5.QtCore import QThread, pyqtSignal
from bauh_api.abstract.controller import ApplicationManager from bauh_api.abstract.controller import SoftwareManager
from bauh_api.abstract.handler import ProcessWatcher from bauh_api.abstract.handler import ProcessWatcher
from bauh_api.abstract.model import PackageStatus from bauh_api.abstract.model import PackageStatus
from bauh_api.abstract.view import InputViewComponent, MessageType from bauh_api.abstract.view import InputViewComponent, MessageType
@@ -62,7 +62,7 @@ class AsyncAction(QThread, ProcessWatcher):
class UpdateSelectedApps(AsyncAction): class UpdateSelectedApps(AsyncAction):
def __init__(self, manager: ApplicationManager, locale_keys: dict, apps_to_update: List[PackageView] = None): def __init__(self, manager: SoftwareManager, locale_keys: dict, apps_to_update: List[PackageView] = None):
super(UpdateSelectedApps, self).__init__() super(UpdateSelectedApps, self).__init__()
self.apps_to_update = apps_to_update self.apps_to_update = apps_to_update
self.manager = manager self.manager = manager
@@ -92,7 +92,7 @@ class UpdateSelectedApps(AsyncAction):
class RefreshApps(AsyncAction): class RefreshApps(AsyncAction):
def __init__(self, manager: ApplicationManager, app: PackageView = None): def __init__(self, manager: SoftwareManager, app: PackageView = None):
super(RefreshApps, self).__init__() super(RefreshApps, self).__init__()
self.manager = manager self.manager = manager
self.app = app # app that should be on list top self.app = app # app that should be on list top
@@ -118,7 +118,7 @@ class RefreshApps(AsyncAction):
class UninstallApp(AsyncAction): class UninstallApp(AsyncAction):
def __init__(self, manager: ApplicationManager, icon_cache: Cache, app: PackageView = None): def __init__(self, manager: SoftwareManager, icon_cache: Cache, app: PackageView = None):
super(UninstallApp, self).__init__() super(UninstallApp, self).__init__()
self.app = app self.app = app
self.manager = manager self.manager = manager
@@ -140,7 +140,7 @@ class UninstallApp(AsyncAction):
class DowngradeApp(AsyncAction): class DowngradeApp(AsyncAction):
def __init__(self, manager: ApplicationManager, locale_keys: dict, app: PackageView = None): def __init__(self, manager: SoftwareManager, locale_keys: dict, app: PackageView = None):
super(DowngradeApp, self).__init__() super(DowngradeApp, self).__init__()
self.manager = manager self.manager = manager
self.app = app self.app = app
@@ -163,7 +163,7 @@ class DowngradeApp(AsyncAction):
class GetAppInfo(AsyncAction): class GetAppInfo(AsyncAction):
def __init__(self, manager: ApplicationManager, app: PackageView = None): def __init__(self, manager: SoftwareManager, app: PackageView = None):
super(GetAppInfo, self).__init__() super(GetAppInfo, self).__init__()
self.app = app self.app = app
self.manager = manager self.manager = manager
@@ -178,7 +178,7 @@ class GetAppInfo(AsyncAction):
class GetAppHistory(AsyncAction): class GetAppHistory(AsyncAction):
def __init__(self, manager: ApplicationManager, locale_keys: dict, app: PackageView = None): def __init__(self, manager: SoftwareManager, locale_keys: dict, app: PackageView = None):
super(GetAppHistory, self).__init__() super(GetAppHistory, self).__init__()
self.app = app self.app = app
self.manager = manager self.manager = manager
@@ -196,7 +196,7 @@ class GetAppHistory(AsyncAction):
class SearchApps(AsyncAction): class SearchApps(AsyncAction):
def __init__(self, manager: ApplicationManager): def __init__(self, manager: SoftwareManager):
super(SearchApps, self).__init__() super(SearchApps, self).__init__()
self.word = None self.word = None
self.manager = manager self.manager = manager
@@ -214,7 +214,7 @@ class SearchApps(AsyncAction):
class InstallApp(AsyncAction): class InstallApp(AsyncAction):
def __init__(self, manager: ApplicationManager, disk_cache: bool, icon_cache: Cache, locale_keys: dict, app: PackageView = None): def __init__(self, manager: SoftwareManager, disk_cache: bool, icon_cache: Cache, locale_keys: dict, app: PackageView = None):
super(InstallApp, self).__init__() super(InstallApp, self).__init__()
self.app = app self.app = app
self.manager = manager self.manager = manager
@@ -314,7 +314,7 @@ class VerifyModels(QThread):
class RefreshApp(AsyncAction): class RefreshApp(AsyncAction):
def __init__(self, manager: ApplicationManager, app: PackageView = None): def __init__(self, manager: SoftwareManager, app: PackageView = None):
super(RefreshApp, self).__init__() super(RefreshApp, self).__init__()
self.app = app self.app = app
self.manager = manager self.manager = manager
@@ -337,7 +337,7 @@ class RefreshApp(AsyncAction):
class FindSuggestions(AsyncAction): class FindSuggestions(AsyncAction):
def __init__(self, man: ApplicationManager): def __init__(self, man: SoftwareManager):
super(FindSuggestions, self).__init__() super(FindSuggestions, self).__init__()
self.man = man self.man = man
@@ -350,7 +350,7 @@ class ListWarnings(QThread):
signal_warnings = pyqtSignal(list) signal_warnings = pyqtSignal(list)
def __init__(self, man: ApplicationManager, locale_keys: dict): def __init__(self, man: SoftwareManager, locale_keys: dict):
super(QThread, self).__init__() super(QThread, self).__init__()
self.locale_keys = locale_keys self.locale_keys = locale_keys
self.man = man self.man = man

View File

@@ -6,7 +6,7 @@ from PyQt5.QtCore import QEvent, Qt, QSize, pyqtSignal
from PyQt5.QtGui import QIcon, QWindowStateChangeEvent, QPixmap from PyQt5.QtGui import QIcon, QWindowStateChangeEvent, QPixmap
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QApplication, QCheckBox, QHeaderView, QToolButton, QToolBar, \ from PyQt5.QtWidgets import QWidget, QVBoxLayout, QApplication, QCheckBox, QHeaderView, QToolButton, QToolBar, \
QLabel, QPlainTextEdit, QLineEdit, QProgressBar, QHBoxLayout, QPushButton, QComboBox QLabel, QPlainTextEdit, QLineEdit, QProgressBar, QHBoxLayout, QPushButton, QComboBox
from bauh_api.abstract.controller import ApplicationManager from bauh_api.abstract.controller import SoftwareManager
from bauh_api.abstract.model import SoftwarePackage from bauh_api.abstract.model import SoftwarePackage
from bauh_api.abstract.view import MessageType from bauh_api.abstract.view import MessageType
from bauh_api.util.cache import Cache from bauh_api.util.cache import Cache
@@ -37,7 +37,7 @@ class ManageWindow(QWidget):
def _toolbar_button_style(self, bg: str): def _toolbar_button_style(self, bg: str):
return 'QPushButton { color: white; font-weight: bold; background: ' + bg + '}' return 'QPushButton { color: white; font-weight: bold; background: ' + bg + '}'
def __init__(self, locale_keys: dict, icon_cache: Cache, manager: ApplicationManager, disk_cache: bool, download_icons: bool, screen_size, suggestions: bool, tray_icon=None): def __init__(self, locale_keys: dict, icon_cache: Cache, manager: SoftwareManager, disk_cache: bool, download_icons: bool, screen_size, suggestions: bool, tray_icon=None):
super(ManageWindow, self).__init__() super(ManageWindow, self).__init__()
self.locale_keys = locale_keys self.locale_keys = locale_keys
self.manager = manager self.manager = manager