3 ]O@sddlmZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl mZmZddlmZddlmZmZddlmZmZdd lmZd ZejeZGd d d eZGd ddeZ ddZ!ddZ"dS))absolute_importN)lockfile)version) total_secondsWINDOWS)PyPI)USER_CACHE_DIRrunning_under_virtualenv) ensure_dirget_installed_version)check_path_ownerz%Y-%m-%dT%H:%M:%SZc@seZdZddZddZdS)VirtualenvSelfCheckStatecCs\tjjtjd|_y&t|j}tj||_ WdQRXWnt t fk rVi|_ YnXdS)Nzpip-selfcheck.json) ospathjoinsysprefixstatefile_pathopenjsonloadstateIOError ValueError)self statefiler1/tmp/pip-build-8jg9gmni/pip/pip/utils/outdated.py__init__s  z!VirtualenvSelfCheckState.__init__c Cs:t|jd$}tj|jt|d|dddWdQRXdS)Nw) last_check pypi_versionT,:) sort_keys separators)r"r#)rrrdumpstrftimeSELFCHECK_DATE_FMT)rr! current_timerrrrsave$szVirtualenvSelfCheckState.saveN)__name__ __module__ __qualname__rr*rrrrr s r c@seZdZddZddZdS)GlobalSelfCheckStatecCsbtjjtd|_y,t|j}tj|tj |_ WdQRXWn t t t fk r\i|_ YnXdS)Nzselfcheck.json)rrrrrrrrrrrrrKeyError)rrrrrr3s   zGlobalSelfCheckState.__init__cCsttjj|jsdSttjj|jtj|jztjj|jrft |j}t j |}WdQRXni}|j t |d|tj<t |jd}t j||dddWdQRXWdQRXdS)N)r r!rTr"r#)r$r%)r"r#)r rrdirnamerr rLockFileexistsrrrr'r(rrr&)rr!r)rrrrrr*=s  zGlobalSelfCheckState.saveN)r+r,r-rr*rrrrr.2s r.cCstr tStSdS)N)r r r.rrrrload_selfcheck_statefileXsr3c Cs:td}|dkrdStj|}d}yt}tjj}d|jkrvd|jkrvtjj|jdt}t ||dkrv|jd}|dkr|j t j dd id }|j d d tt|jd tjdDd}|j||tj|}||ko|j|jkrtrd} nd} tjd||| Wn$tk r4tjdddYnXdS)zCheck for an update for pip. Limit the frequency of checks to once per week. State is stored either in the active virtualenv or in the user's USER_CACHE_DIR keyed off the prefix of the pip script path. pipNr r!<Acceptzapplication/json)headerscSsg|]}tj|js|qSr)packaging_versionparse is_prerelease).0vrrr sz%pip_version_check..releases)keyz python -m pipzYou are using pip version %s, however version %s is available. You should consider upgrading via the '%s install --upgrade pip' command.z5There was an error checking the latest version of pipT)exc_infoi`'i: )r r:r;r3datetimeutcnowrstrptimer(rgetr pip_json_urlraise_for_statussortedlistrr* base_versionrloggerwarning Exceptiondebug) sessioninstalled_version pip_versionr!rr)r respremote_versionpip_cmdrrrpip_version_check_sJ       rY)# __future__rrFrloggingos.pathrr pip._vendorrZpip._vendor.packagingrr: pip.compatrr pip.modelsr pip.locationsrr pip.utilsr r pip.utils.filesystemr r( getLoggerr+rOobjectr r.r3rYrrrrs$      &