refactoring to use the new ApplicationContext

This commit is contained in:
Vinicius Moreira
2019-08-30 18:57:24 -03:00
parent bd17594723
commit a6422c6edc
3 changed files with 10 additions and 8 deletions

View File

@@ -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)

View File

@@ -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:

View File

@@ -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))