
Me
                 @   s   d  Z  d d l Z d d l m Z d d l m Z d d l m Z m	 Z	 m
 Z
 d d l m Z m Z d d l m Z d d l m Z d	 Z d
 Z e d d d    Z e e d d d    Z e e d d d    Z d S)z"
Client version related functions
    N)inf)Optional)get_apt_cache_timeget_pkg_candidate_versionversion_compare)CANDIDATE_CACHE_PATHUAC_RUN_PATH)ProcessExecutionError)subpZ30z30~16.04)returnc              C   s   t  j d  s t  St j j t j j t   }  t j j t j j |  d   r d d d d d g } y  t |  \ } } | j	   SWn t
 k
 r Yn Xt S)aO  Return the packaged version as a string

    Prefer the binary PACKAGED_VESION set by debian/rules to DEB_VERSION.
    If unavailable, check for a .git development environments:
      a. If run in our upstream repo `git describe` will gives a leading
         XX.Y so return the --long version to allow daily build recipes
         to count commit offset from upstream's XX.Y signed tag.
      b. If run in a git-ubuntu pkg repo, upstream tags aren't visible,
         believe __VERSION__ is correct - there is and MUST always be a
         test to make sure it matches debian/changelog
    z@@PACKAGED_VERSIONz.gitZgitZdescribez
--abbrev=8z--match=[0-9]*z--long)PACKAGED_VERSION
startswithospathdirname__file__existsjoinr
   stripr	   __VERSION__)Ztopdircmdout_ r   2/usr/lib/python3/dist-packages/uaclient/version.pyget_version   s    !r   c              C   s   t    p t }  t j j t  s: t j t  j |  k  r yS t d  } | r t j	 t
 d d t t d   } | j |  Wd  QRX| SWn" t k
 r | d  k	 r | SYn Xy- t t d   } | j   j   SWd  QRXWn t k
 r Yn Xd  S)Nzubuntu-advantage-toolsexist_okTwr)r   r   r   r   r   r   statst_mtimer   makedirsr   openwrite	Exceptionreadr   )Zlast_apt_cache_updateZcandidate_versionfr   r   r   get_last_known_candidate.   s(    		r'   c              C   s/   t    }  |  r+ t |  t    d k r+ |  Sd  S)Nr   )r'   r   r   )	candidater   r   r   check_for_new_versionL   s    	r)   )__doc__os.pathr   Zmathr   Ztypingr   Zuaclient.aptr   r   r   Zuaclient.defaultsr   r   Zuaclient.exceptionsr	   Zuaclient.systemr
   r   r   strr   r'   r)   r   r   r   r   <module>   s   