o Hcf @sdZddlZddlmZddlmZddlmZm Z m Z ddl m Z m Z ddlmZddlmZd Zd Zd efd d Zd eefddZd eefddZdS)z" Client version related functions N)inf)Optional)get_apt_cache_timeget_pkg_candidate_versionversion_compare)CANDIDATE_CACHE_PATH UAC_RUN_PATH)ProcessExecutionError)subpz32.3.1z 32.3.1~22.04returncCsptdstStjtjt}tjtj|dr6gd}z t|\}}| WSt y5Yt Swt S)aOReturn 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.git)gitdescribez --abbrev=8z--match=[0-9]*z--long) PACKAGED_VERSION startswithospathdirname__file__existsjoinr stripr __VERSION__)topdircmdout_r2/usr/lib/python3/dist-packages/uaclient/version.py get_versions    rcCstpt}tjtrttj|krUd}z.td}|rBtj t ddt td}| |Wd|WS1s:wY|WSWnt yT|durR|YSYnwzt td}|WdWS1smwYWdSt y~YdSw)Nzubuntu-pro-clientT)exist_okwr)rrrrrrstatst_mtimermakedirsropenwrite Exceptionreadr)last_apt_cache_updatecandidate_versionfrrrget_last_known_candidate/s<        $ r,cCs"t}|rt|tdkr|SdS)Nr)r,rr) candidaterrrcheck_for_new_versionLsr.)__doc__os.pathrmathrtypingr uaclient.aptrrruaclient.defaultsrruaclient.exceptionsr uaclient.systemr rrstrrr,r.rrrrs