using SearchResult

This commit is contained in:
Vinicius Moreira
2019-08-27 15:27:45 -03:00
parent 040cdc9505
commit 4cc65256ff
2 changed files with 10 additions and 10 deletions

View File

@@ -2,7 +2,7 @@ from argparse import Namespace
from threading import Thread from threading import Thread
from typing import List, Dict, Set from typing import List, Dict, Set
from bauh_api.abstract.controller import ApplicationManager from bauh_api.abstract.controller import ApplicationManager, SearchResult
from bauh_api.abstract.handler import ProcessWatcher from bauh_api.abstract.handler import ProcessWatcher
from bauh_api.abstract.model import Application, ApplicationUpdate, ApplicationHistory from bauh_api.abstract.model import Application, ApplicationUpdate, ApplicationHistory
from bauh_api.util.disk import DiskCacheLoader from bauh_api.util.disk import DiskCacheLoader
@@ -57,16 +57,16 @@ class GenericApplicationManager(ApplicationManager):
else: else:
return man.is_enabled() return man.is_enabled()
def _search(self, word: str, man: ApplicationManager, disk_loader, res: dict): def _search(self, word: str, man: ApplicationManager, disk_loader, res: SearchResult):
if self._is_enabled(man): if self._is_enabled(man):
apps_found = man.search(words=word, disk_loader=disk_loader) apps_found = man.search(words=word, disk_loader=disk_loader)
res['installed'].extend(apps_found['installed']) res.installed.extend(apps_found.installed)
res['new'].extend(apps_found['new']) res.new.extend(apps_found.new)
def search(self, word: str, disk_loader: DiskCacheLoader = None) -> Dict[str, List[Application]]: def search(self, word: str, disk_loader: DiskCacheLoader = None) -> SearchResult:
self._wait_to_be_ready() self._wait_to_be_ready()
res = {'installed': [], 'new': []} res = SearchResult([], [])
norm_word = word.strip().lower() norm_word = word.strip().lower()
disk_loader = self.disk_loader_factory.new() disk_loader = self.disk_loader_factory.new()
@@ -86,8 +86,8 @@ class GenericApplicationManager(ApplicationManager):
disk_loader.stop = True disk_loader.stop = True
disk_loader.join() disk_loader.join()
for key in res: res.installed = self._sort(res.installed, norm_word)
res[key] = self._sort(res[key], norm_word) res.new = self._sort(res.new, norm_word)
return res return res

View File

@@ -189,8 +189,8 @@ class SearchApps(AsyncAction):
if self.word: if self.word:
res = self.manager.search(self.word) res = self.manager.search(self.word)
apps_found.extend(res['installed']) apps_found.extend(res.installed)
apps_found.extend(res['new']) apps_found.extend(res.new)
self.notify_finished(apps_found) self.notify_finished(apps_found)
self.word = None self.word = None