mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-09 10:54:16 +02:00
refactoring memory and disk cache abstractions
This commit is contained in:
@@ -2,24 +2,23 @@ from threading import Thread
|
||||
from typing import List, Set, Type
|
||||
|
||||
from bauh_api.abstract.controller import SoftwareManager, SearchResult, ApplicationContext
|
||||
from bauh_api.abstract.disk import DiskCacheLoader
|
||||
from bauh_api.abstract.handler import ProcessWatcher
|
||||
from bauh_api.abstract.model import SoftwarePackage, PackageUpdate, PackageHistory
|
||||
from bauh_api.util.disk import DiskCacheLoader
|
||||
from bauh_api.util.disk import DiskCacheLoaderFactory
|
||||
|
||||
SUGGESTIONS_LIMIT = 6
|
||||
|
||||
|
||||
class GenericSoftwareManager(SoftwareManager):
|
||||
|
||||
def __init__(self, managers: List[SoftwareManager], context: ApplicationContext, disk_loader_factory: DiskCacheLoaderFactory):
|
||||
super(GenericSoftwareManager, self).__init__(context=context, app_cache=None)
|
||||
def __init__(self, managers: List[SoftwareManager], context: ApplicationContext):
|
||||
super(GenericSoftwareManager, self).__init__(context=context)
|
||||
self.managers = managers
|
||||
self.map = {t: m for m in self.managers for t in m.get_managed_types()}
|
||||
self.disk_loader_factory = disk_loader_factory
|
||||
self._enabled_map = {} if context.args.check_packaging_once else None
|
||||
self.thread_prepare = None
|
||||
self.i18n = context.i18n
|
||||
self.disk_loader_factory = context.disk_loader_factory
|
||||
|
||||
def _sort(self, apps: List[SoftwarePackage], word: str) -> List[SoftwarePackage]:
|
||||
|
||||
@@ -188,7 +187,7 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
return man if man and self._is_enabled(man) else None
|
||||
|
||||
def cache_to_disk(self, app: SoftwarePackage, icon_bytes: bytes, only_icon: bool):
|
||||
if self.disk_loader_factory.disk_cache and app.supports_disk_cache():
|
||||
if self.context.args.disk_cache and app.supports_disk_cache():
|
||||
man = self._get_manager_for(app)
|
||||
|
||||
if man:
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import inspect
|
||||
import os
|
||||
import pkgutil
|
||||
from typing import List, Dict
|
||||
from typing import List
|
||||
|
||||
from bauh_api.abstract.controller import SoftwareManager, ApplicationContext
|
||||
from bauh_api.util.cache import Cache
|
||||
|
||||
from bauh import __app_name__
|
||||
from bauh.util import util
|
||||
@@ -24,7 +23,7 @@ def find_manager(member):
|
||||
return manager_found
|
||||
|
||||
|
||||
def load_managers(caches: List[Cache], cache_map: Dict[type, Cache], context: ApplicationContext) -> List[SoftwareManager]:
|
||||
def load_managers(context: ApplicationContext) -> List[SoftwareManager]:
|
||||
managers = []
|
||||
|
||||
for m in pkgutil.iter_modules():
|
||||
@@ -40,13 +39,6 @@ def load_managers(caches: List[Cache], cache_map: Dict[type, Cache], context: Ap
|
||||
if os.path.exists(locale_path):
|
||||
context.i18n.update(util.get_locale_keys(context.args.locale, locale_path))
|
||||
|
||||
app_cache = Cache(expiration_time=context.args.cache_exp)
|
||||
man = manager_class(context=context, app_cache=app_cache)
|
||||
|
||||
for t in man.get_managed_types():
|
||||
cache_map[t] = app_cache
|
||||
|
||||
caches.append(app_cache)
|
||||
managers.append(man)
|
||||
managers.append(manager_class(context=context))
|
||||
|
||||
return managers
|
||||
|
||||
Reference in New Issue
Block a user