mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-06 22:54:16 +02:00
[appimage] fix -> crashing when trying to upgrade and the internet connection is off
This commit is contained in:
@@ -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/).
|
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
|
## [0.9.14] 2021-02-03
|
||||||
### Improvements
|
### Improvements
|
||||||
- AppImage
|
- AppImage
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
__version__ = '0.9.14'
|
__version__ = '0.9.15'
|
||||||
__app_name__ = 'bauh'
|
__app_name__ = 'bauh'
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|||||||
@@ -68,12 +68,17 @@ class HttpClient:
|
|||||||
res = self.get(url, params=params, headers=headers, allow_redirects=allow_redirects, session=session)
|
res = self.get(url, params=params, headers=headers, allow_redirects=allow_redirects, session=session)
|
||||||
return yaml.safe_load(res.text) if res else None
|
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}
|
params = {'url': url, 'allow_redirects': True, 'stream': True}
|
||||||
if session:
|
|
||||||
res = self.session.get(**params)
|
try:
|
||||||
else:
|
if session:
|
||||||
res = requests.get(**params)
|
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:
|
if res.status_code == 200:
|
||||||
size = res.headers.get('Content-Length')
|
size = res.headers.get('Content-Length')
|
||||||
@@ -84,7 +89,7 @@ class HttpClient:
|
|||||||
except:
|
except:
|
||||||
pass
|
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)
|
size = self.get_content_length_in_bytes(url, session)
|
||||||
|
|
||||||
if size:
|
if size:
|
||||||
@@ -98,4 +103,3 @@ class HttpClient:
|
|||||||
res = self.session.get(**params)
|
res = self.session.get(**params)
|
||||||
|
|
||||||
return res.status_code in (200, 403)
|
return res.status_code in (200, 403)
|
||||||
return False
|
|
||||||
|
|||||||
Reference in New Issue
Block a user