From b4d3a48112ff30cf3fd104212f0b24efe3aa9c1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Moreira?= Date: Tue, 17 Dec 2019 13:11:38 -0300 Subject: [PATCH] [wgem] handling i18n suggestion description | fix indexed search --- bauh/app.py | 2 +- bauh/gems/web/controller.py | 33 +++++++++++++++++++++++++-------- bauh/view/util/translation.py | 4 +++- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/bauh/app.py b/bauh/app.py index 3ff4c75f..5f180c4a 100755 --- a/bauh/app.py +++ b/bauh/app.py @@ -34,7 +34,7 @@ def main(): i18n_key, current_i18n = translation.get_locale_keys(args.locale) default_i18n = translation.get_locale_keys(DEFAULT_I18N_KEY)[1] if i18n_key != DEFAULT_I18N_KEY else {} - i18n = I18n(current_i18n, default_i18n) + i18n = I18n(i18n_key, current_i18n, DEFAULT_I18N_KEY, default_i18n) cache_cleaner = CacheCleaner() cache_factory = DefaultMemoryCacheFactory(expiration_time=args.cache_exp, cleaner=cache_cleaner) diff --git a/bauh/gems/web/controller.py b/bauh/gems/web/controller.py index 096d6aad..f47a215f 100644 --- a/bauh/gems/web/controller.py +++ b/bauh/gems/web/controller.py @@ -190,13 +190,18 @@ class WebApplicationManager(SoftwareManager): split_words = lower_words.split(' ') singleword = ''.join(lower_words) - index_match_keys = set() - for word in (*split_words, singleword): - indexed = index.get(word) - if indexed: - index_match_keys.update(indexed) + query_list = [*split_words, singleword] - if index_match_keys: + index_match_keys = set() + for key in index: + for query in query_list: + if query in key: + index_match_keys.update(index[key]) + + if not index_match_keys: + self.logger.info("Query '{}' was not found in the suggestion's index".format(words)) + res.installed.extend(installed_matches) + else: if not os.path.exists(SUGGESTIONS_CACHE_FILE): # if the suggestions cache was not found, it will not be possible to retrieve the matched apps # so only the installed matches will be returned @@ -224,7 +229,7 @@ class WebApplicationManager(SoftwareManager): # checking if any of the installed matches is one of the matched suggestions for sug in matched_suggestions: - found = (installed for installed in installed_matches if i.url == sug.get('url')) + found = [i for i in installed_matches if i.url == sug.get('url')] if found: res.installed.extend(found) @@ -376,7 +381,7 @@ class WebApplicationManager(SoftwareManager): op_igcert = InputOption(id_='ignore_certs', label=self.i18n['web.install.option.ignore_certificate.label'], value="--ignore-certificate", tooltip=self.i18n['web.install.option.ignore_certificate.tip']) adv_opts = [op_single, op_allow_urls, op_max, op_fs, op_nframe, op_ncache, op_insecure, op_igcert] - def_adv_opts = {op_single} + def_adv_opts = {op_single, op_allow_urls} if app.preset_options: for opt in adv_opts: @@ -623,6 +628,18 @@ class WebApplicationManager(SoftwareManager): icon_url=suggestion.get('icon_url'), categories=[suggestion['category']] if suggestion.get('category') else None, preset_options=suggestion.get('options')) + + description = suggestion.get('description') + + if isinstance(description, dict): + app.description = description.get(self.i18n.current_key, description.get(self.i18n.default_key)) + elif isinstance(description, str): + app.description = description + + if self.env_settings and self.env_settings.get('electron'): + app.version = self.env_settings['electron']['version'] + app.latest_version = app.version + app.status = PackageStatus.LOADING_DATA Thread(target=self._fill_suggestion, args=(app,)).start() diff --git a/bauh/view/util/translation.py b/bauh/view/util/translation.py index 2e8795bf..a9c7febf 100644 --- a/bauh/view/util/translation.py +++ b/bauh/view/util/translation.py @@ -7,9 +7,11 @@ from bauh.view.util import resource class I18n(dict): - def __init__(self, current_locale: dict, default_locale: dict): + def __init__(self, current_key: str, current_locale: dict, default_key: str, default_locale: dict): super(I18n, self).__init__() + self.current_key = current_key self.current = current_locale + self.default_key = default_key self.default = default_locale def __getitem__(self, item):