fix: application is not initializing when there is no internet connection

This commit is contained in:
Vinicius Moreira
2019-10-22 10:18:35 -03:00
parent a33ede646a
commit 696ce1c79e
4 changed files with 54 additions and 33 deletions

View File

@@ -9,7 +9,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- 3 password attempts for root authentication - 3 password attempts for root authentication
- AUR: - AUR:
- showing a "user-friendly" popup when there are integrity issues with the source-files of a building package - showing a "user-friendly" popup when there are integrity issues with the source-files of a building package
### Fixes ### Fixes
- application not initializing when there is no internet connection
- AUR: - AUR:
- update-checking for some scenarios - update-checking for some scenarios
- not respecting **ignorepkg** settings in **pacman.conf** - not respecting **ignorepkg** settings in **pacman.conf**

View File

@@ -8,6 +8,8 @@ from multiprocessing import Process
from pathlib import Path from pathlib import Path
from threading import Thread from threading import Thread
import requests
from bauh.api.http import HttpClient from bauh.api.http import HttpClient
from bauh.gems.appimage import LOCAL_PATH, db from bauh.gems.appimage import LOCAL_PATH, db
@@ -68,7 +70,11 @@ class DatabaseUpdater(Thread if bool(int(os.getenv('BAUH_DEBUG', 0))) else Proce
def run(self): def run(self):
if self.enabled: if self.enabled:
while True: while True:
self._download_databases() try:
self._download_databases()
except requests.exceptions.ConnectionError:
self.logger.warning('The internet connection seems to be off.')
self.logger.info('Sleeping') self.logger.info('Sleeping')
time.sleep(self.sleep) time.sleep(self.sleep)
else: else:

View File

@@ -8,6 +8,8 @@ from multiprocessing import Process
from threading import Thread from threading import Thread
from typing import Dict, List from typing import Dict, List
import requests
from bauh.api.abstract.context import ApplicationContext from bauh.api.abstract.context import ApplicationContext
from bauh.api.abstract.controller import SoftwareManager from bauh.api.abstract.controller import SoftwareManager
from bauh.api.constants import HOME_PATH from bauh.api.constants import HOME_PATH
@@ -45,7 +47,7 @@ class AURIndexUpdater(Thread):
self.logger.info('Pre-indexed {} AUR package names in memory'.format(len(self.man.names_index))) self.logger.info('Pre-indexed {} AUR package names in memory'.format(len(self.man.names_index)))
else: else:
self.logger.warning('No data returned from: {}'.format(URL_INDEX)) self.logger.warning('No data returned from: {}'.format(URL_INDEX))
except ConnectionError: except requests.exceptions.ConnectionError:
self.logger.warning('No internet connection: could not pre-index packages') self.logger.warning('No internet connection: could not pre-index packages')
time.sleep(60 * 20) # updates every 20 minutes time.sleep(60 * 20) # updates every 20 minutes
@@ -148,21 +150,26 @@ class CategoriesDownloader:
def get_categories(self) -> Dict[str, List[str]]: def get_categories(self) -> Dict[str, List[str]]:
self.logger.info('Downloading AUR category definitions from {}'.format(self.URL_CATEGORIES_FILE)) self.logger.info('Downloading AUR category definitions from {}'.format(self.URL_CATEGORIES_FILE))
res = self.http_client.get(self.URL_CATEGORIES_FILE) try:
res = self.http_client.get(self.URL_CATEGORIES_FILE)
if res: if res:
try: try:
categories_map = {} categories_map = {}
for l in res.text.split('\n'): for l in res.text.split('\n'):
if l: if l:
data = l.split('=') data = l.split('=')
categories_map[data[0]] = [c.strip() for c in data[1].split(',') if c] categories_map[data[0]] = [c.strip() for c in data[1].split(',') if c]
self.logger.info('Loaded categories for {} AUR packages'.format(len(categories_map))) self.logger.info('Loaded categories for {} AUR packages'.format(len(categories_map)))
return categories_map return categories_map
except: except:
self.logger.error("Could not parse AUR categories definitions") self.logger.error("Could not parse AUR categories definitions")
traceback.print_exc() traceback.print_exc()
return {}
else:
self.logger.info('Could not download {}'.format(self.URL_CATEGORIES_FILE))
return {} return {}
else: except requests.exceptions.ConnectionError:
self.logger.info('Could not download {}'.format(self.URL_CATEGORIES_FILE)) self.logger.warning('The internet connection seems to be off.')
return {}

View File

@@ -4,6 +4,8 @@ import traceback
from threading import Thread from threading import Thread
from typing import Dict, List from typing import Dict, List
import requests
from bauh.api.abstract.cache import MemoryCache from bauh.api.abstract.cache import MemoryCache
from bauh.api.abstract.context import ApplicationContext from bauh.api.abstract.context import ApplicationContext
from bauh.api.abstract.controller import SoftwareManager from bauh.api.abstract.controller import SoftwareManager
@@ -85,21 +87,25 @@ class CategoriesDownloader:
def get_categories(self) -> Dict[str, List[str]]: def get_categories(self) -> Dict[str, List[str]]:
self.logger.info('Downloading Snap category definitions from {}'.format(self.URL_CATEGORIES_FILE)) self.logger.info('Downloading Snap category definitions from {}'.format(self.URL_CATEGORIES_FILE))
res = self.http_client.get(self.URL_CATEGORIES_FILE) try:
res = self.http_client.get(self.URL_CATEGORIES_FILE)
if res: if res:
try: try:
categories_map = {} categories_map = {}
for l in res.text.split('\n'): for l in res.text.split('\n'):
if l: if l:
data = l.split('=') data = l.split('=')
categories_map[data[0]] = [c.strip() for c in data[1].split(',') if c] categories_map[data[0]] = [c.strip() for c in data[1].split(',') if c]
self.logger.info('Loaded categories for {} Snap applications'.format(len(categories_map))) self.logger.info('Loaded categories for {} Snap applications'.format(len(categories_map)))
return categories_map return categories_map
except: except:
self.logger.error("Could not parse categories definitions") self.logger.error("Could not parse categories definitions")
traceback.print_exc() traceback.print_exc()
return {} return {}
else: else:
self.logger.info('Could not download {}'.format(self.URL_CATEGORIES_FILE)) self.logger.info('Could not download {}'.format(self.URL_CATEGORIES_FILE))
except requests.exceptions.ConnectionError:
self.logger.warning('The internet connection seems to be off.')
return {}