From 9cd89292bef0d0233dfc267eee8d1bc5067dcea2 Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Thu, 2 Jan 2020 16:55:54 -0300 Subject: [PATCH 1/4] [fix][appimage] not passing the Home path as a String --- CHANGELOG.md | 1 + bauh/gems/appimage/controller.py | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb805732..ea6391eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - not verifying if an icon path is a file - Web: - not handling HTTP connection issues +- not passing the Home path as a String ( does not work in Python 3.5 ) ## [0.8.0] 2019-12-24 ### Features diff --git a/bauh/gems/appimage/controller.py b/bauh/gems/appimage/controller.py index fd9ace98..538d3051 100644 --- a/bauh/gems/appimage/controller.py +++ b/bauh/gems/appimage/controller.py @@ -20,15 +20,14 @@ from bauh.api.abstract.handler import ProcessWatcher from bauh.api.abstract.model import SoftwarePackage, PackageHistory, PackageUpdate, PackageSuggestion, \ SuggestionPriority 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, LOCAL_PATH, SUGGESTIONS_FILE from bauh.gems.appimage.config import read_config from bauh.gems.appimage.model import AppImage -from bauh.gems.appimage.query import FIND_APPS_BY_NAME, FIND_APPS_BY_NAME_ONLY_NAME from bauh.gems.appimage.worker import DatabaseUpdater +HOME_PATH = str(Path.home()) DB_APPS_PATH = '{}/{}'.format(HOME_PATH, '.local/share/bauh/appimage/apps.db') DB_RELEASES_PATH = '{}/{}'.format(HOME_PATH, '.local/share/bauh/appimage/releases.db') From 74ddfc03efed3bac3daea24b51439d9707a652a1 Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Thu, 2 Jan 2020 17:13:57 -0300 Subject: [PATCH 2/4] [refactoring] removing the HOME_PATH constant in favor of Path.home() --- bauh/api/constants.py | 7 +++---- bauh/gems/appimage/__init__.py | 5 ++--- bauh/gems/arch/__init__.py | 5 +++-- bauh/gems/web/__init__.py | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/bauh/api/constants.py b/bauh/api/constants.py index a14e0b8d..61c96fe1 100644 --- a/bauh/api/constants.py +++ b/bauh/api/constants.py @@ -1,6 +1,5 @@ from pathlib import Path -HOME_PATH = Path.home() -CACHE_PATH = '{}/.cache/bauh'.format(HOME_PATH) -CONFIG_PATH = '{}/.config/bauh'.format(HOME_PATH) -DESKTOP_ENTRIES_DIR = '{}/.local/share/applications'.format(HOME_PATH) +CACHE_PATH = '{}/.cache/bauh'.format(Path.home()) +CONFIG_PATH = '{}/.config/bauh'.format(Path.home()) +DESKTOP_ENTRIES_DIR = '{}/.local/share/applications'.format(Path.home()) diff --git a/bauh/gems/appimage/__init__.py b/bauh/gems/appimage/__init__.py index 7ac802a6..341db84d 100644 --- a/bauh/gems/appimage/__init__.py +++ b/bauh/gems/appimage/__init__.py @@ -1,8 +1,7 @@ import os - -from bauh.api.constants import HOME_PATH +from pathlib import Path ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) -LOCAL_PATH = '{}/.local/share/bauh/appimage'.format(HOME_PATH) +LOCAL_PATH = '{}/.local/share/bauh/appimage'.format(Path.home()) 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/arch/__init__.py b/bauh/gems/arch/__init__.py index 65bf849e..5c3c8bee 100644 --- a/bauh/gems/arch/__init__.py +++ b/bauh/gems/arch/__init__.py @@ -1,6 +1,7 @@ import os +from pathlib import Path -from bauh.api.constants import CACHE_PATH, HOME_PATH, CONFIG_PATH +from bauh.api.constants import CACHE_PATH, CONFIG_PATH ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) BUILD_DIR = '/tmp/bauh/aur' @@ -8,7 +9,7 @@ ARCH_CACHE_PATH = CACHE_PATH + '/arch' CATEGORIES_CACHE_DIR = ARCH_CACHE_PATH + '/categories' CATEGORIES_FILE_PATH = CATEGORIES_CACHE_DIR + '/aur.txt' URL_CATEGORIES_FILE = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/aur/categories.txt' -CONFIG_DIR = '{}/.config/bauh/arch'.format(HOME_PATH) +CONFIG_DIR = '{}/.config/bauh/arch'.format(Path.home()) CUSTOM_MAKEPKG_FILE = '{}/makepkg.conf'.format(CONFIG_DIR) AUR_INDEX_FILE = '{}/aur.txt'.format(BUILD_DIR) CONFIG_FILE = '{}/arch.yml'.format(CONFIG_PATH) diff --git a/bauh/gems/web/__init__.py b/bauh/gems/web/__init__.py index 68af6a87..7d9f9321 100644 --- a/bauh/gems/web/__init__.py +++ b/bauh/gems/web/__init__.py @@ -1,7 +1,7 @@ import os from pathlib import Path -from bauh.api.constants import HOME_PATH, DESKTOP_ENTRIES_DIR, CONFIG_PATH +from bauh.api.constants import DESKTOP_ENTRIES_DIR, CONFIG_PATH ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) WEB_PATH = '{}/.local/share/bauh/web'.format(Path.home()) @@ -13,7 +13,7 @@ NODE_BIN_PATH = '{}/bin/node'.format(NODE_DIR_PATH) NPM_BIN_PATH = '{}/bin/npm'.format(NODE_DIR_PATH) NODE_MODULES_PATH = '{}/node_modules'.format(ENV_PATH) NATIVEFIER_BIN_PATH = '{}/.bin/nativefier'.format(NODE_MODULES_PATH) -ELECTRON_PATH = '{}/.cache/electron'.format(HOME_PATH) +ELECTRON_PATH = '{}/.cache/electron'.format(Path.home()) ELECTRON_DOWNLOAD_URL = 'https://github.com/electron/electron/releases/download/v{version}/electron-v{version}-linux-{arch}.zip' ELECTRON_SHA256_URL = 'https://github.com/electron/electron/releases/download/v{version}/SHASUMS256.txt' URL_ENVIRONMENT_SETTINGS = 'https://raw.githubusercontent.com/vinifmor/bauh-files/master/web/environment.yml' From 0acb5b7047f5687a93c8e124c8e3a13cd57746b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Moreira?= Date: Wed, 8 Jan 2020 15:48:14 -0300 Subject: [PATCH 3/4] [improvement][web] not using HTTP sessions anymore to perform the searches --- CHANGELOG.md | 4 ++++ bauh/api/http.py | 36 ++++++++++++++++++++++-------------- bauh/gems/web/controller.py | 14 +++++++------- bauh/gems/web/worker.py | 2 +- 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea6391eb..fecbd3a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [0.8.1] +### Improvements +- Web: + - not using HTTP sessions anymore to perform the searches. It seems to avoid URLs not being found after an internet drop event. + ### Fixes - not verifying if an icon path is a file - Web: diff --git a/bauh/api/http.py b/bauh/api/http.py index 31e90c90..2a1c91be 100644 --- a/bauh/api/http.py +++ b/bauh/api/http.py @@ -17,7 +17,7 @@ class HttpClient: self.sleep = sleep self.logger = logger - def get(self, url: str, params: dict = None, headers: dict = None, allow_redirects: bool = True, ignore_ssl: bool = False, single_call: bool = False) -> requests.Request: + def get(self, url: str, params: dict = None, headers: dict = None, allow_redirects: bool = True, ignore_ssl: bool = False, single_call: bool = False, session: bool = True) -> requests.Response: cur_attempts = 1 while cur_attempts <= self.max_attempts: @@ -35,7 +35,10 @@ class HttpClient: if ignore_ssl: args['verify'] = False - res = self.session.get(url, **args) + if session: + res = self.session.get(url, **args) + else: + res = requests.get(url, **args) if res.status_code == 200: return res @@ -56,20 +59,20 @@ class HttpClient: self.logger.warning("Could not retrieve data from '{}'".format(url)) - def get_json(self, url: str, params: dict = None, headers: dict = None, allow_redirects: bool = True): - res = self.get(url, params=params, headers=headers, allow_redirects=allow_redirects) + def get_json(self, url: str, params: dict = None, headers: dict = None, allow_redirects: bool = True, session: bool = True): + res = self.get(url, params=params, headers=headers, allow_redirects=allow_redirects, session=session) return res.json() if res else None - def get_yaml(self, url: str, params: dict = None, headers: dict = None, allow_redirects: bool = True): - res = self.get(url, params=params, headers=headers, allow_redirects=allow_redirects) + def get_yaml(self, url: str, params: dict = None, headers: dict = None, allow_redirects: bool = True, session: bool = True): + res = self.get(url, params=params, headers=headers, allow_redirects=allow_redirects, session=session) return yaml.safe_load(res.text) if res else None - def get_content_length(self, url: str) -> str: - """ - :param url: - :return: - """ - res = self.session.get(url, allow_redirects=True, stream=True) + def get_content_length(self, url: str, session: bool = True) -> str: + params = {'url': url, 'allow_redirects': True, 'stream': True} + if session: + res = self.session.get(**params) + else: + res = requests.get(**params) if res.status_code == 200: size = res.headers.get('Content-Length') @@ -77,6 +80,11 @@ class HttpClient: if size is not None: return system.get_human_size_str(size) - def exists(self, url: str) -> bool: - res = self.session.head(url=url, allow_redirects=True, verify=False, timeout=5) + def exists(self, url: str, session: bool = True) -> bool: + params = {'url': url, 'allow_redirects': True, 'verify': False, 'timeout': 5} + if session: + res = self.session.head(**params) + else: + res = self.session.get(**params) + return res.status_code in (200, 403) diff --git a/bauh/gems/web/controller.py b/bauh/gems/web/controller.py index e45f9df7..0e1d9c14 100644 --- a/bauh/gems/web/controller.py +++ b/bauh/gems/web/controller.py @@ -137,10 +137,10 @@ class WebApplicationManager(SoftwareManager): return description def _get_fix_for(self, url_no_protocol: str) -> str: - try: - fix_url = URL_FIX_PATTERN.format(url=url_no_protocol) - res = self.http_client.get(fix_url) + fix_url = URL_FIX_PATTERN.format(url=url_no_protocol) + try: + res = self.http_client.get(fix_url, session=False) if res: return res.text except Exception as e: @@ -156,7 +156,7 @@ class WebApplicationManager(SoftwareManager): headers = {'Accept-language': self._get_lang_header(), 'User-Agent': UA_CHROME} try: - url_res = self.http_client.get(url, headers=headers, ignore_ssl=True, single_call=True) + url_res = self.http_client.get(url, headers=headers, ignore_ssl=True, single_call=True, session=False) if url_res: return BeautifulSoup(url_res.text, 'lxml', parse_only=SoupStrainer('head')) @@ -529,11 +529,11 @@ class WebApplicationManager(SoftwareManager): def _download_suggestion_icon(self, pkg: WebApplication, app_dir: str) -> Tuple[str, bytes]: try: - if self.http_client.exists(pkg.icon_url): + if self.http_client.exists(pkg.icon_url, session=False): icon_path = '{}/{}'.format(app_dir, pkg.icon_url.split('/')[-1]) try: - res = self.http_client.get(pkg.icon_url) + res = self.http_client.get(pkg.icon_url, session=False) if not res: self.logger.info('Could not download the icon {}'.format(pkg.icon_url)) else: @@ -756,7 +756,7 @@ class WebApplicationManager(SoftwareManager): if not app.description: app.description = self._get_app_description(app.url, soup) - find_url = not app.icon_url or (app.icon_url and not self.http_client.exists(app.icon_url)) + find_url = not app.icon_url or (app.icon_url and not self.http_client.exists(app.icon_url, session=False)) if find_url: app.icon_url = self._get_app_icon_url(app.url, soup) diff --git a/bauh/gems/web/worker.py b/bauh/gems/web/worker.py index c6b68d6e..48182222 100644 --- a/bauh/gems/web/worker.py +++ b/bauh/gems/web/worker.py @@ -19,7 +19,7 @@ class SuggestionsDownloader: def download(self) -> dict: self.logger.info("Reading suggestions from {}".format(URL_SUGGESTIONS)) try: - suggestions = self.http_client.get_yaml(URL_SUGGESTIONS) + suggestions = self.http_client.get_yaml(URL_SUGGESTIONS, session=False) if suggestions: self.logger.info("{} suggestions successfully read".format(len(suggestions))) From 8b77c87dab7ef222961118e616f5607233166b4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Moreira?= Date: Thu, 9 Jan 2020 12:20:34 -0300 Subject: [PATCH 4/4] [fix] missing categories i18n --- CHANGELOG.md | 1 + bauh/view/resources/locale/de | 3 ++- bauh/view/resources/locale/en | 3 ++- bauh/view/resources/locale/it | 3 ++- bauh/view/util/translation.py | 5 ++++- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fecbd3a3..449942f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - not using HTTP sessions anymore to perform the searches. It seems to avoid URLs not being found after an internet drop event. ### Fixes +- missing categories i18n [48](https://github.com/vinifmor/bauh/issues/48) - not verifying if an icon path is a file - Web: - not handling HTTP connection issues diff --git a/bauh/view/resources/locale/de b/bauh/view/resources/locale/de index f4387ad2..d931929d 100644 --- a/bauh/view/resources/locale/de +++ b/bauh/view/resources/locale/de @@ -171,4 +171,5 @@ files=Dateien all_files=Alle Dateien file_chooser.title=Dateiauswahl message.file.not_exist=Datei existiert nicht -message.file.not_exist.body=Die Datei {} scheint nicht zu existieren \ No newline at end of file +message.file.not_exist.body=Die Datei {} scheint nicht zu existieren +development=Entwicklung \ No newline at end of file diff --git a/bauh/view/resources/locale/en b/bauh/view/resources/locale/en index baf28c65..079441d4 100644 --- a/bauh/view/resources/locale/en +++ b/bauh/view/resources/locale/en @@ -175,4 +175,5 @@ files=files all_files=all files file_chooser.title=File selector message.file.not_exist=File does not exist -message.file.not_exist.body=The file {} seems not to exist \ No newline at end of file +message.file.not_exist.body=The file {} seems not to exist +development=development \ No newline at end of file diff --git a/bauh/view/resources/locale/it b/bauh/view/resources/locale/it index f715f261..d9d9fed0 100644 --- a/bauh/view/resources/locale/it +++ b/bauh/view/resources/locale/it @@ -172,4 +172,5 @@ files=files all_files=tutti i files file_chooser.title=Selettore file message.file.not_exist=File non esiste -message.file.not_exist.body=Il file {} sembra non esistere \ No newline at end of file +message.file.not_exist.body=Il file {} sembra non esistere +development=sviluppo \ No newline at end of file diff --git a/bauh/view/util/translation.py b/bauh/view/util/translation.py index a76204a2..40c22685 100644 --- a/bauh/view/util/translation.py +++ b/bauh/view/util/translation.py @@ -19,7 +19,10 @@ class I18n(dict): return self.current.__getitem__(item) except KeyError: if self.default: - return self.default.__getitem__(item) + try: + return self.default.__getitem__(item) + except KeyError: + return item else: return item