From 873ff801fa00bf1f62c50c18986db36039f074ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Moreira?= Date: Fri, 20 Dec 2019 19:31:37 -0300 Subject: [PATCH] [appimage] begin: moving suggestions to cloud --- bauh/gems/appimage/__init__.py | 1 + bauh/gems/appimage/controller.py | 31 ++++++++++++++++++------------- bauh/gems/appimage/suggestions.py | 12 ------------ 3 files changed, 19 insertions(+), 25 deletions(-) delete mode 100644 bauh/gems/appimage/suggestions.py diff --git a/bauh/gems/appimage/__init__.py b/bauh/gems/appimage/__init__.py index 570f72ad..7ac802a6 100644 --- a/bauh/gems/appimage/__init__.py +++ b/bauh/gems/appimage/__init__.py @@ -5,3 +5,4 @@ from bauh.api.constants import HOME_PATH ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) LOCAL_PATH = '{}/.local/share/bauh/appimage'.format(HOME_PATH) INSTALLATION_PATH = LOCAL_PATH + '/installed/' +SUGGESTIONS_FILE = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/appimage/suggestions.txt' \ No newline at end of file diff --git a/bauh/gems/appimage/controller.py b/bauh/gems/appimage/controller.py index 9544bb53..9f6df44b 100644 --- a/bauh/gems/appimage/controller.py +++ b/bauh/gems/appimage/controller.py @@ -22,7 +22,7 @@ from bauh.api.abstract.view import MessageType from bauh.api.constants import HOME_PATH from bauh.commons.html import bold from bauh.commons.system import SystemProcess, new_subprocess, ProcessHandler, run_cmd, SimpleProcess -from bauh.gems.appimage import query, INSTALLATION_PATH, suggestions, LOCAL_PATH +from bauh.gems.appimage import query, INSTALLATION_PATH, LOCAL_PATH, SUGGESTIONS_FILE from bauh.gems.appimage.config import read_config from bauh.gems.appimage.model import AppImage from bauh.gems.appimage.worker import DatabaseUpdater @@ -421,21 +421,26 @@ class AppImageManager(SoftwareManager): connection = self._get_db_connection(DB_APPS_PATH) if connection: - try: - sugs = [(i, p) for i, p in suggestions.ALL.items()] - sugs.sort(key=lambda t: t[1].value, reverse=True) + file = self.http_client.get(SUGGESTIONS_FILE) - if limit > 0: - sugs = sugs[0:limit] + if not file or not file.text: + self.logger.warning("No suggestion found in {}".format(SUGGESTIONS_FILE)) + return res + else: + try: + for line in file.text.split('\n'): + if line: # TODO stopped here + if limit > 0: + sugs = sugs[0:limit] - cursor = connection.cursor() - cursor.execute(query.FIND_APPS_BY_NAME_FULL.format(','.join(["'{}'".format(s[0]) for s in sugs]))) + cursor = connection.cursor() + cursor.execute(query.FIND_APPS_BY_NAME_FULL.format(','.join(["'{}'".format(s[0]) for s in sugs]))) - for t in cursor.fetchall(): - app = AppImage(*t) - res.append(PackageSuggestion(app, suggestions.ALL.get(app.name.lower()))) - finally: - self._close_connection(DB_APPS_PATH, connection) + for t in cursor.fetchall(): + app = AppImage(*t) + res.append(PackageSuggestion(app, suggestions.ALL.get(app.name.lower()))) + finally: + self._close_connection(DB_APPS_PATH, connection) return res diff --git a/bauh/gems/appimage/suggestions.py b/bauh/gems/appimage/suggestions.py deleted file mode 100644 index dc4a4f85..00000000 --- a/bauh/gems/appimage/suggestions.py +++ /dev/null @@ -1,12 +0,0 @@ -from bauh.api.abstract.model import SuggestionPriority - -ALL = { - 'onlyoffice': SuggestionPriority.MEDIUM, - 'gamehub': SuggestionPriority.MEDIUM, - 'rpcs3': SuggestionPriority.MEDIUM, - 'etcher': SuggestionPriority.MEDIUM, - 'postman': SuggestionPriority.LOW, - 'nosqlbooster': SuggestionPriority.LOW, - 'emcas': SuggestionPriority.LOW, - 'azpainter': SuggestionPriority.LOW -} \ No newline at end of file