def _update_pypi_version(self): """Get the latest PyPI version (as a string) via the RESTful JSON API""" logger.debug( "Get latest Glances version from the PyPI RESTful API ({})".format( PYPI_API_URL)) # Update the current time self.data[u'refresh_date'] = datetime.now() try: res = urlopen(PYPI_API_URL, timeout=3).read() except (HTTPError, URLError, CertificateError) as e: logger.debug( "Cannot get Glances version from the PyPI RESTful API ({})". format(e)) else: self.data[u'latest_version'] = json.loads( nativestr(res))['info']['version'] logger.debug("Save Glances version to the cache file") # Save result to the cache file # Note: also saved if the Glances PyPI version cannot be grabbed self._save_cache() return self.data
def _get_ip_public(self, queue_target, url, json=False, key=None): """Request the url service and put the result in the queue_target.""" try: response = urlopen(url, timeout=self.timeout).read().decode('utf-8') except Exception as e: logger.debug("IP plugin - Cannot open URL {} ({})".format(url, e)) queue_target.put(None) else: # Request depend on service try: if not json: queue_target.put(response) else: queue_target.put(loads(response)[key]) except ValueError: queue_target.put(None)
def _get_ip_public(self, queue_target, url, json=False, key=None): """Request the url service and put the result in the queue_target""" try: response = urlopen(url, timeout=self.timeout).read().decode('utf-8') except Exception as e: logger.debug("IP plugin - Cannot open URL {} ({})".format(url, e)) queue_target.put(None) else: # Request depend on service try: if not json: queue_target.put(response) else: queue_target.put(loads(response)[key]) except ValueError: queue_target.put(None)
def _update_pypi_version(self): """Get the latest PyPI version (as a string) via the RESTful JSON API""" logger.debug("Get latest Glances version from the PyPI RESTful API ({})".format(PYPI_API_URL)) # Update the current time self.data[u'refresh_date'] = datetime.now() try: res = urlopen(PYPI_API_URL, timeout=3).read() except (HTTPError, URLError) as e: logger.debug("Cannot get Glances version from the PyPI RESTful API ({})".format(e)) else: self.data[u'latest_version'] = json.loads(nativestr(res))['info']['version'] logger.debug("Save Glances version to the cache file") # Save result to the cache file # Note: also saved if the Glances PyPI version cannot be grabbed self._save_cache() return self.data