[appimage] fix -> crashing when trying to upgrade and the internet connection is off

This commit is contained in:
Vinicius Moreira
2021-02-12 14:46:21 -03:00
parent 9af8dd4f1f
commit 8c0c4d4546
3 changed files with 18 additions and 8 deletions

View File

@@ -4,6 +4,12 @@ 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.9.15] 2021
### Fixes
- AppImage
- crashing when trying to upgrade and the internet connection is off
## [0.9.14] 2021-02-03
### Improvements
- AppImage

View File

@@ -1,4 +1,4 @@
__version__ = '0.9.14'
__version__ = '0.9.15'
__app_name__ = 'bauh'
import os

View File

@@ -68,12 +68,17 @@ class HttpClient:
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_in_bytes(self, url: str, session: bool = True) -> int:
def get_content_length_in_bytes(self, url: str, session: bool = True) -> Optional[int]:
params = {'url': url, 'allow_redirects': True, 'stream': True}
if session:
res = self.session.get(**params)
else:
res = requests.get(**params)
try:
if session:
res = self.session.get(**params)
else:
res = requests.get(**params)
except requests.exceptions.ConnectionError:
self.logger.info("Internet seems to be off. Could not reach '{}'".format(url))
return
if res.status_code == 200:
size = res.headers.get('Content-Length')
@@ -84,7 +89,7 @@ class HttpClient:
except:
pass
def get_content_length(self, url: str, session: bool = True) -> str:
def get_content_length(self, url: str, session: bool = True) -> Optional[str]:
size = self.get_content_length_in_bytes(url, session)
if size:
@@ -98,4 +103,3 @@ class HttpClient:
res = self.session.get(**params)
return res.status_code in (200, 403)
return False