[snap] suggestions retrieved from bauh-files

This commit is contained in:
Vinícius Moreira
2019-12-20 17:45:32 -03:00
parent 18d8a99e58
commit 7cbd745af1
7 changed files with 42 additions and 35 deletions

View File

@@ -6,3 +6,4 @@ ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
SNAP_CACHE_PATH = CACHE_PATH + '/snap'
CATEGORIES_FILE_PATH = SNAP_CACHE_PATH + '/categories.txt'
URL_CATEGORIES_FILE = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/snap/categories.txt'
SUGGESTIONS_FILE = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/snap/suggestions.txt'

View File

@@ -13,7 +13,7 @@ from bauh.api.abstract.view import SingleSelectComponent, SelectViewType, InputO
from bauh.commons.category import CategoriesDownloader
from bauh.commons.html import bold
from bauh.commons.system import SystemProcess, ProcessHandler, new_root_subprocess
from bauh.gems.snap import snap, suggestions, URL_CATEGORIES_FILE, SNAP_CACHE_PATH, CATEGORIES_FILE_PATH
from bauh.gems.snap import snap, URL_CATEGORIES_FILE, SNAP_CACHE_PATH, CATEGORIES_FILE_PATH, SUGGESTIONS_FILE
from bauh.gems.snap.constants import SNAP_API_URL
from bauh.gems.snap.model import SnapApplication
from bauh.gems.snap.worker import SnapAsyncDataLoader
@@ -239,31 +239,39 @@ class SnapManager(SoftwareManager):
res = []
if snap.is_snapd_running():
sugs = [(i, p) for i, p in suggestions.ALL.items()]
sugs.sort(key=lambda t: t[1].value, reverse=True)
self.logger.info('Downloading suggestions file {}'.format(SUGGESTIONS_FILE))
file = self.http_client.get(SUGGESTIONS_FILE)
threads = []
self.categories_downloader.join()
if not file or not file.text:
self.logger.warning("No suggestion found in {}".format(SUGGESTIONS_FILE))
return res
else:
self.logger.info('Mapping suggestions')
self.categories_downloader.join()
for sug in sugs:
suggestions, threads = [], []
if limit <= 0 or len(res) < limit:
cached_sug = self.suggestions_cache.get(sug[0])
for l in file.text.split('\n'):
if l:
lsplit = l.strip().split('=')
if cached_sug:
res.append(cached_sug)
else:
t = Thread(target=self._fill_suggestion, args=(sug[0], sug[1], res))
t.start()
threads.append(t)
time.sleep(0.001) # to avoid being blocked
else:
break
if limit <= 0 or len(suggestions) < limit:
cached_sug = self.suggestions_cache.get(lsplit[1])
for t in threads:
t.join()
if cached_sug:
res.append(cached_sug)
else:
t = Thread(target=self._fill_suggestion, args=(lsplit[1], SuggestionPriority(int(lsplit[0])), res))
t.start()
threads.append(t)
time.sleep(0.001) # to avoid being blocked
else:
break
res.sort(key=lambda s: s.priority.value, reverse=True)
for t in threads:
t.join()
res.sort(key=lambda s: s.priority.value, reverse=True)
return res
def is_default_enabled(self) -> bool:

View File

@@ -0,0 +1,10 @@
3=skype
2=drawing
2=obs-studio
2=eclispe
1=krita
1=audacity
0=supertuxkart
0=retroarch
0=chromium
0=matroska-tools

View File

@@ -1,13 +0,0 @@
from bauh.api.abstract.model import SuggestionPriority
ALL = {
'whatsdesk': SuggestionPriority.TOP,
'slack': SuggestionPriority.HIGH,
'discord': SuggestionPriority.HIGH,
'yakyak': SuggestionPriority.MEDIUM,
'instagraph': SuggestionPriority.MEDIUM,
'gimp': SuggestionPriority.MEDIUM,
'pycharm-professional': SuggestionPriority.LOW,
'eclipse': SuggestionPriority.LOW,
'supertuxkart': SuggestionPriority.LOW
}

View File

@@ -23,7 +23,7 @@ URL_SUGGESTIONS = "https://raw.githubusercontent.com/vinifmor/bauh-files/master/
UA_CHROME = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'
TEMP_PATH = '/tmp/bauh/web'
SEARCH_INDEX_FILE = '{}/index.yml'.format(TEMP_PATH)
SUGGESTIONS_CACHE_FILE = '{}/suggestions.yml'.format(TEMP_PATH)
SUGGESTIONS_CACHE_FILE = '{}/suggestions.txt'.format(TEMP_PATH)
CONFIG_FILE = '{}/web.yml'.format(CONFIG_PATH)
NATIVEFIER_URL = 'https://github.com/jiahaog/nativefier/archive/v7.7.0.tar.gz'

View File

@@ -336,7 +336,7 @@ class GenericSoftwareManager(SoftwareManager):
self.logger.info(man.__class__.__name__ + ' took {0:.2f} seconds'.format(mtf - mti))
if man_sugs:
if len(man_sugs) > limit:
if 0 < limit < len(man_sugs):
man_sugs = man_sugs[0:limit]
suggestions.extend(man_sugs)