From a6422c6edc7f474a71b86d7334c7d70708a5993f Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Fri, 30 Aug 2019 18:57:24 -0300 Subject: [PATCH] refactoring to use the new ApplicationContext --- bauh/app.py | 7 ++++--- bauh/core/controller.py | 7 ++++--- bauh/core/extensions.py | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/bauh/app.py b/bauh/app.py index 2456da61..487312db 100755 --- a/bauh/app.py +++ b/bauh/app.py @@ -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) diff --git a/bauh/core/controller.py b/bauh/core/controller.py index afffc9cb..abdd728a 100755 --- a/bauh/core/controller.py +++ b/bauh/core/controller.py @@ -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: diff --git a/bauh/core/extensions.py b/bauh/core/extensions.py index 0450f52a..d7b9c648 100644 --- a/bauh/core/extensions.py +++ b/bauh/core/extensions.py @@ -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))