????

Your IP : 3.23.61.5


Current Path : /lib/python3.6/site-packages/glances/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/glances/__pycache__/outdated.cpython-36.pyc

3

Eo�c��@s�dZddlmZmZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZm
Z
mZmZddlmZddlmZdd	lmZydd
lmZdZWn6ek
r�Zzejdje��d
ZWYddZ[XnXdZGdd�de�ZdS)zManage Glances update.�)�datetime�	timedeltaN)�CertificateError)�__version__)�	nativestr�urlopen�	HTTPError�URLError)�user_cache_dir)�
safe_makedirs)�logger)�VersionTzKUnable to import 'packaging' module ({}). Glances cannot check for updates.Fz)https://pypi.python.org/pypi/Glances/jsonc@s`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�Outdatedz�
    This class aims at providing methods to warn the user when a new Glances
    version is available on the PyPI repository (https://pypi.python.org/pypi/Glances/).
    cCsp||_||_t�|_tjj|jd�|_tdt	j
�d�|_|j|�t
sNd|j_tjdj|jj��|j�dS)zInit the Outdated classzglances-version.dbz0.0)�installed_version�latest_version�refresh_dateTz$Check Glances version up-to-date: {}N)�args�configr
�	cache_dir�os�path�join�
cache_filerr�now�data�load_config�PACKAGING_IMPORT�disable_check_updater�debug�format�get_pypi_version)�selfrr�r"�/usr/lib/python3.6/outdated.py�__init__+s
zOutdated.__init__cCsJd}t|d�r2|j|�r2|j|d�j�dk|j_ntjdj|��dSdS)zHLoad outdated parameter in the global section of the configuration file.�global�has_sectionZcheck_updateZfalsez0Cannot find section {} in the configuration fileFT)	�hasattrr&Z	get_value�lowerrrrrr)r!rZglobal_sectionr"r"r#r=szOutdated.load_configcCs
|jdS)Nr)r)r!r"r"r#rIszOutdated.installed_versioncCs
|jdS)Nr)r)r!r"r"r#rLszOutdated.latest_versioncCs
|jdS)Nr)r)r!r"r"r#rOszOutdated.refresh_datecCsP|jjrdS|j�}|ikr4tj|jd�}|j�n|d|jd<tj	d�dS)z�Wrapper to get the latest PyPI version (async)

        The data are stored in a cached file
        Only update online once a week
        N)�targetrz#Get Glances version from cache file)
rr�_load_cache�	threadingZThread�_update_pypi_version�startrrr)r!�cached_dataZthreadr"r"r#r Rs
zOutdated.get_pypi_versioncCs>|jjrdStjdj|j�|j���t|j��t|j��kS)z)Return True if a new version is availableFz2Check Glances version (installed: {} / latest: {}))rrrrrrrr
)r!r"r"r#�is_outdatedhs
zOutdated.is_outdatedcCs�tdd�}i}y&t|jd��}tj|�}WdQRXWn6tk
rj}ztjdj|j|��WYdd}~Xn4Xtjd�|d|j	�ks�t
j�|d|kr�i}|S)	z&Load cache file and return cached data�)Zdays�rbNz,Cannot read version from cache file: {} ({})zRead version from cache filerr)r�openr�pickle�load�	Exceptionrrrrrr)r!Zmax_refresh_dater.�f�er"r"r#r*ss
&
zOutdated._load_cachecCspt|j�y*t|jd��}tj|j|�WdQRXWn6tk
rj}ztj	dj
|j|��WYdd}~XnXdS)zSave data to the cache file.�wbNz*Cannot write version to cache file {} ({}))rrr2rr3�dumprr5r�errorr)r!r6r7r"r"r#�_save_cache�s
zOutdated._save_cachecCs�tjdjt��tj�|jd<yttdd�j�}Wn8t	t
tfk
rj}ztjdj|��WYdd}~Xn(Xtj
t|��dd|jd	<tjd
�|j�|jS)zBGet the latest PyPI version (as a string) via the RESTful JSON APIz9Get latest Glances version from the PyPI RESTful API ({})r�)Ztimeoutz9Cannot get Glances version from the PyPI RESTful API ({})N�info�versionrz&Save Glances version to the cache file)rrr�PYPI_API_URLrrrr�readrr	r�json�loadsrr;)r!�resr7r"r"r#r,�s"
zOutdated._update_pypi_versionN)�__name__�
__module__�__qualname__�__doc__r$rrrrr r/r*r;r,r"r"r"r#r$sr) rGrrr+rAr3rZsslrZglancesrZglances.compatrrrr	Zglances.configr
Zglances.globalsrZglances.loggerrZpackaging.versionr
rr5r7r:rr?�objectrr"r"r"r#�<module>
s&