mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 00:04:15 +02:00
refactoring to use the new ApplicationContext
This commit is contained in:
@@ -24,15 +24,16 @@ icon_cache = cache_factory.new(args.icon_exp)
|
||||
|
||||
context = ApplicationContext(i18n=i18n,
|
||||
http_client=HttpClient(),
|
||||
args=args,
|
||||
disk_cache=args.disk_cache,
|
||||
download_icons=args.download_icons,
|
||||
app_root_dir=ROOT_DIR,
|
||||
cache_factory=cache_factory,
|
||||
disk_loader_factory=DefaultDiskCacheLoaderFactory(disk_cache_enabled=args.disk_cache))
|
||||
|
||||
managers = extensions.load_managers(context=context)
|
||||
managers = extensions.load_managers(context=context, locale=args.locale)
|
||||
|
||||
|
||||
manager = GenericSoftwareManager(managers, context=context)
|
||||
manager = GenericSoftwareManager(managers, context=context, app_args=args)
|
||||
manager.prepare()
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from argparse import Namespace
|
||||
from threading import Thread
|
||||
from typing import List, Set, Type
|
||||
|
||||
@@ -11,11 +12,11 @@ SUGGESTIONS_LIMIT = 6
|
||||
|
||||
class GenericSoftwareManager(SoftwareManager):
|
||||
|
||||
def __init__(self, managers: List[SoftwareManager], context: ApplicationContext):
|
||||
def __init__(self, managers: List[SoftwareManager], context: ApplicationContext, app_args: Namespace):
|
||||
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._enabled_map = {} if context.args.check_packaging_once else None
|
||||
self._enabled_map = {} if app_args.check_packaging_once else None
|
||||
self.thread_prepare = None
|
||||
self.i18n = context.i18n
|
||||
self.disk_loader_factory = context.disk_loader_factory
|
||||
@@ -187,7 +188,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.context.args.disk_cache and app.supports_disk_cache():
|
||||
if self.context.disk_cache and app.supports_disk_cache():
|
||||
man = self._get_manager_for(app)
|
||||
|
||||
if man:
|
||||
|
||||
@@ -23,7 +23,7 @@ def find_manager(member):
|
||||
return manager_found
|
||||
|
||||
|
||||
def load_managers(context: ApplicationContext) -> List[SoftwareManager]:
|
||||
def load_managers(locale: str, context: ApplicationContext) -> List[SoftwareManager]:
|
||||
managers = []
|
||||
|
||||
for m in pkgutil.iter_modules():
|
||||
@@ -37,7 +37,7 @@ def load_managers(context: ApplicationContext) -> List[SoftwareManager]:
|
||||
locale_path = '{}/resources/locale'.format(module.__path__[0])
|
||||
|
||||
if os.path.exists(locale_path):
|
||||
context.i18n.update(util.get_locale_keys(context.args.locale, locale_path))
|
||||
context.i18n.update(util.get_locale_keys(locale, locale_path))
|
||||
|
||||
managers.append(manager_class(context=context))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user