def _load_catalogs(self, refresh=False): expiration = datetime.timedelta(hours=4) self._update_status_bar('Loading, catalogs...', idle=True) self.catalog_plugins = plugins.ClientCatalogManager( self.application.user_data_path) catalog_cache = self.catalog_plugins.get_cache() now = datetime.datetime.utcnow() for catalog_url in self.config['catalogs']: catalog_cache_dict = catalog_cache.get_catalog_by_url(catalog_url) if not refresh and catalog_cache_dict and catalog_cache_dict[ 'created'] + expiration > now: try: catalog = Catalog(catalog_cache_dict['value']) except (KeyError, TypeError) as error: self.logger.warning( "{0} error when trying to add catalog dict to manager". format(error.__class__.__name)) else: self.catalog_plugins.add_catalog( catalog, catalog_url=catalog_cache_dict['url'], cache=False) continue self.logger.debug("downloading catalog: {}".format(catalog_url)) self._update_status_bar( "Loading, downloading catalog: {}".format(catalog_url)) catalog = self._load_catalog_from_url(catalog_url) if not catalog: continue self.catalog_plugins.add_catalog(catalog, catalog_url=catalog_url, cache=True) self._load_plugins()
def _load_catalogs(self, refresh=False): expiration = datetime.timedelta(hours=4) self._update_status_bar('Loading, catalogs...', idle=True) self.catalog_plugins = plugins.ClientCatalogManager( self.application.user_data_path) catalog_cache = self.catalog_plugins.get_cache() now = datetime.datetime.utcnow() for catalog_url in self.config['catalogs']: catalog_cache_dict = catalog_cache.get_catalog_by_url(catalog_url) if not refresh and catalog_cache_dict and catalog_cache_dict[ 'created'] + expiration > now: try: catalog = Catalog(catalog_cache_dict['value']) except (KeyError, TypeError) as error: self.logger.warning( "{0} error when trying to add catalog dict to manager". format(error.__class__.__name)) else: self.catalog_plugins.add_catalog( catalog, catalog_url=catalog_cache_dict['url'], cache=False) continue self.logger.debug("downloading catalog: {}".format(catalog_url)) self._update_status_bar( "Loading, downloading catalog: {}".format(catalog_url)) try: catalog = Catalog.from_url(catalog_url) except requests.exceptions.ConnectionError: self.logger.warning( "connection error trying to download catalog url: {}". format(catalog)) self.idle_show_dialog_error( 'Catalog Loading Error', "Failed to download catalog, check your internet connection." ) except Exception: self.logger.warning("failed to add catalog by url", exc_info=True) self.idle_show_dialog_error('Catalog Loading Error', "Failed to add catalog") else: self.catalog_plugins.add_catalog(catalog, catalog_url=catalog_url, cache=True) self._load_plugins()
def _load_catalog_from_cache_tsafe(self, catalog_cache_dict): catalog = None try: catalog = Catalog(catalog_cache_dict['value']) except (KeyError, TypeError) as error: self.logger.warning( "{0} error when trying to add catalog dict to manager".format( error.__class__.__name)) else: self.catalog_plugins.add_catalog( catalog, catalog_url=catalog_cache_dict['url'], cache=False) self._add_catalog_to_tree_tsafe(catalog) return catalog
def _load_catalog_from_url_tsafe(self, catalog_url): catalog = None try: catalog = Catalog.from_url(catalog_url) except requests.exceptions.ConnectionError: self.logger.warning("connection error trying to download catalog url: {}".format(catalog_url)) self._show_dialog_error_tsafe('Catalog Loading Error', 'Failed to download catalog, check your internet connection.') except Exception: self.logger.warning('failed to add catalog by url: ' + catalog_url, exc_info=True) self._show_dialog_error_tsafe('Catalog Loading Error', 'Failed to add catalog') else: self.catalog_plugins.add_catalog(catalog, catalog_url=catalog_url, cache=True) self._add_catalog_to_tree_tsafe(catalog) return catalog
def _load_catalog_from_url(self, catalog_url): catalog = None try: catalog = Catalog.from_url(catalog_url) except requests.exceptions.ConnectionError: self.logger.warning( "connection error trying to download catalog url: {}".format( catalog_url)) self.idle_show_dialog_error( 'Catalog Loading Error', "Failed to download catalog, check your internet connection.") except Exception: self.logger.warning("failed to add catalog by url", exc_info=True) self.idle_show_dialog_error('Catalog Loading Error', "Failed to add catalog") return catalog
def _load_catalog_from_url_tsafe(self, catalog_url): catalog = None try: catalog = Catalog.from_url(catalog_url) except requests.exceptions.ConnectionError: self.logger.warning( "connection error trying to download catalog url: {}".format( catalog_url)) self._show_dialog_error_tsafe( 'Catalog Loading Error', 'Failed to download catalog, check your internet connection.') except Exception: self.logger.warning('failed to add catalog by url: ' + catalog_url, exc_info=True) self._show_dialog_error_tsafe('Catalog Loading Error', 'Failed to add catalog') else: self.catalog_plugins.add_catalog(catalog, catalog_url=catalog_url, cache=True) self._add_catalog_to_tree_tsafe(catalog) return catalog