From 113402cebd17a8553a85a24326c6a8da8c986a66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Moreira?= Date: Fri, 27 Dec 2019 10:15:41 -0300 Subject: [PATCH 1/2] [fix] not verifying if an icon path is a file --- CHANGELOG.md | 4 ++++ bauh/__init__.py | 2 +- bauh/view/qt/apps_table.py | 5 +++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7066814d..54e73cc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,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] +### Fixes +- not verifying if an icon path is a file + ## [0.8.0] 2019-12-24 ### Features - Native Web applications support: diff --git a/bauh/__init__.py b/bauh/__init__.py index 7289277f..e6a21914 100644 --- a/bauh/__init__.py +++ b/bauh/__init__.py @@ -1,4 +1,4 @@ -__version__ = '0.8.0' +__version__ = '0.8.1' __app_name__ = 'bauh' import os diff --git a/bauh/view/qt/apps_table.py b/bauh/view/qt/apps_table.py index 2a68cda1..0e207784 100644 --- a/bauh/view/qt/apps_table.py +++ b/bauh/view/qt/apps_table.py @@ -341,8 +341,9 @@ class AppsTable(QTableWidget): item.setText(name) - if self.disk_cache and pkg.model.supports_disk_cache() and pkg.model.get_disk_icon_path() and os.path.exists(pkg.model.get_disk_icon_path()): - with open(pkg.model.get_disk_icon_path(), 'rb') as f: + icon_path = pkg.model.get_disk_icon_path() + if self.disk_cache and pkg.model.supports_disk_cache() and icon_path and os.path.isfile(icon_path): + with open(icon_path, 'rb') as f: icon_bytes = f.read() pixmap = QPixmap() pixmap.loadFromData(icon_bytes) From 1636d600ee511aeb51477beecfcc5a3766dba5cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Moreira?= Date: Fri, 27 Dec 2019 13:14:16 -0300 Subject: [PATCH 2/2] [fix][web] not handling HTTP connection issues --- CHANGELOG.md | 2 ++ bauh/gems/web/controller.py | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54e73cc7..eb805732 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [0.8.1] ### Fixes - not verifying if an icon path is a file +- Web: + - not handling HTTP connection issues ## [0.8.0] 2019-12-24 ### Features diff --git a/bauh/gems/web/controller.py b/bauh/gems/web/controller.py index 0a922658..e45f9df7 100644 --- a/bauh/gems/web/controller.py +++ b/bauh/gems/web/controller.py @@ -11,6 +11,7 @@ from typing import List, Type, Set, Tuple import yaml from colorama import Fore +from requests import exceptions from bauh.api.abstract.context import ApplicationContext from bauh.api.abstract.controller import SoftwareManager, SearchResult @@ -136,10 +137,14 @@ class WebApplicationManager(SoftwareManager): return description def _get_fix_for(self, url_no_protocol: str) -> str: - res = self.http_client.get(URL_FIX_PATTERN.format(url=url_no_protocol)) + try: + fix_url = URL_FIX_PATTERN.format(url=url_no_protocol) + res = self.http_client.get(fix_url) - if res: - return res.text + if res: + return res.text + except Exception as e: + self.logger.warning("Error when trying to retrieve a fix for {}: {}".format(fix_url, e.__class__.__name__)) def _strip_url_protocol(self, url: str) -> str: return RE_PROTOCOL_STRIP.split(url)[1].strip().lower() @@ -149,10 +154,14 @@ class WebApplicationManager(SoftwareManager): def _map_url(self, url: str) -> "BeautifulSoup": headers = {'Accept-language': self._get_lang_header(), 'User-Agent': UA_CHROME} - url_res = self.http_client.get(url, headers=headers, ignore_ssl=True, single_call=True) - if url_res: - return BeautifulSoup(url_res.text, 'lxml', parse_only=SoupStrainer('head')) + try: + url_res = self.http_client.get(url, headers=headers, ignore_ssl=True, single_call=True) + + if url_res: + return BeautifulSoup(url_res.text, 'lxml', parse_only=SoupStrainer('head')) + except exceptions.ConnectionError as e: + self.logger.warning("Could not get {}: {}".format(url, e.__class__.__name__)) def search(self, words: str, disk_loader: DiskCacheLoader, limit: int = -1, is_url: bool = False) -> SearchResult: local_config = {}